Advertisement
Guest User

Octothorpe

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