Aluf

Omegle bot-PYTHON

Jan 23rd, 2015
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.54 KB | None | 0 0
  1. #Python Omegle bot.
  2. import urllib2 as url
  3. import urllib
  4. import thread as thr
  5.  
  6. idList = list()
  7.  
  8. def disconnect( id ):
  9.     url.urlopen( 'http://omegle.com/disconnect', urllib.urlencode( {'id':id} ) )
  10.  
  11. #for posting things
  12. def sendOmegle( msg, sendId = None, recId = None ):
  13.     '''if id is None, send to all'''
  14.     if recId != None:
  15.         if sendId != None:
  16.             print '*** Not supported yet.'
  17.         else:
  18.             #send msg from bot to one person
  19.             url.urlopen( 'http://omegle.com/send', urllib.urlencode( {'id':recId, 'msg':msg} ) )
  20.             print msg
  21.     else:
  22.         if sendId != None:
  23.             #send msg from one person to all
  24.             sentMsg = sendId + ': ' + msg
  25.             for id in idList:
  26.                 if id != sendId:
  27.                     url.urlopen( 'http://omegle.com/send', urllib.urlencode( {'id':id, 'msg':sentMsg} ) )
  28.             try:
  29.                 print sendId + ': ' + msg.decode( 'utf-8' )
  30.             except:
  31.                 print '*** OH GOD AN EXCEPTION'
  32.                 print sentMsg
  33.         else:
  34.             #send msg from bot to all
  35.             for id in idList:
  36.                 url.urlopen( 'http://omegle.com/send', urllib.urlencode( {'id':id, 'msg':msg} ) )
  37.             print msg
  38.  
  39. def fmtId( string ):
  40.     return string[1:len( string ) - 1]
  41.  
  42. def connect():
  43.     #start omegle
  44.     site = url.urlopen( 'http://omegle.com/start', '' )
  45.  
  46.     #get id
  47.     id = fmtId( site.read() )
  48.  
  49.     idList.append( id )
  50.  
  51.     #connect
  52.     req = url.Request( 'http://omegle.com/events', urllib.urlencode( {'id':id} ) )
  53.  
  54.     print '*** Getting a stranger...'
  55.  
  56.     while True:
  57.         site = url.urlopen( req )
  58.         rec = site.read()
  59.         if 'connected' in rec:
  60.             print '*** You have connected!'
  61.             break
  62.  
  63. def runAll():
  64.     for id in idList:
  65.         thr.start_new_thread( runOne, ( id, ) )
  66.     while len( idList ) != 0:
  67.         pass
  68.     print '*** Everyone left.'
  69.  
  70. def runOne( id ):
  71.     global idList
  72.     while len( idList ) != 0:
  73.         isDisconnected = False
  74.         site = url.urlopen( 'http://omegle.com/events', urllib.urlencode( {'id':id} ) )
  75.         rec = site.read()
  76.         if rec != 'null':
  77.             inputs = eval( rec )
  78.             for inp in inputs:
  79.                 if inp[0] == "strangerDisconnected":
  80.                     idList.remove( id )
  81.                     if len( idList ) > 1:
  82.                         sendOmegle( id + ' disconnected, ' + str( len( idList ) - 1 ) + ' other(s) left.' )
  83.                     else:
  84.                         sendOmegle( 'Everyone but you disconnected, so I\'m out. Have a nice day!' )
  85.                         disconnect( idList[0] )
  86.                         idList = list()
  87.                     isDisconnected = True
  88.                 elif inp[0] == "gotMessage":
  89.                     if inp[1] == 'list':
  90.                         print '***', id, 'has requested a list of IDs.'
  91.                         sendOmegle( 'List of all IDs:', None, id )
  92.                         for dispId in idList:
  93.                             sendOmegle( dispId, None, id )
  94.                     elif inp[1] == 'info':
  95.                         print '***', id, 'has requested info about the bot.'
  96.                         sendOmegle( 'This bot is not affiliated in any way with Omegle. It was just made by a nerd with no life. It\'s in Python!', None, id )
  97.                     else:
  98.                         sendOmegle( inp[1].decode( 'raw_unicode_escape' ).encode( 'utf-8' ), id, None )
  99.         if isDisconnected:
  100.             break
Advertisement
Add Comment
Please, Sign In to add comment