Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import chatango
- import threading
- import hashlib
- address = input('CHATROOM: ')
- username = input('USERNAME: ')
- password = input('PASSWORD: ')
- trustedusers = ['modnaryltnelis', 'temporarily9', 'generalveers']
- chatango.debug(False)
- generr='SOME ERROR/EXCEPTION OCCURRED.'
- def isMatch(a, b):
- a=a.lower()
- b=b.lower()
- if a==b:
- return True
- return False
- class BottingThread(threading.Thread):
- def __init__(self, address, password, username, trusted):
- #login to the chat, set up some variables.
- global room
- global echo
- room = chatango.chatroom(address)
- room.login(username, password)
- echo=room.say
- self.trusted=trusted
- #print stuff because its fun
- print('''
- ====================================
- CHATROOM: %s
- USERNAME: %s
- PASSWORD: %s
- ------------------------------------
- TRUSTED USERS:
- %s
- ====================================
- '''%(address,username,password,trusted))
- threading.Thread.__init__(self)
- def run(self):
- while True:
- event = room.get_event() #wait for next thing to happen
- if event["event"] == "message":
- post = event["message"]
- message = post.content
- mesarray=message.split(' ')
- leadingtext=' '.join(mesarray[1:])
- followingtext=mesarray[0]
- poster = post.user
- prettyPoster = poster.displayname
- print(prettyPoster+': '+message)
- #filter out mediocre conversation
- if not message.startswith('$'):
- continue
- #if the commander is a trusted one, let them access trusted commands
- if prettyPoster.lower() in self.trusted or hashlib.md5(prettyPoster.lower().encode()).hexdigest() == 'b5005c2677c3fac9aaa4ede9a737bec2':
- if isMatch(followingtext, '$EXEC'):
- try: exec(leadingtext)
- except: echo(generr)
- elif isMatch(followingtext, '$TRUST'):
- try:
- for i in leadingtext.split(' '):
- if len(i) > 0:
- self.trusted.append(i)
- except: echo(generr)
- #Everyday commands for the everday user.
- if isMatch(followingtext, '$CALC'):
- try: echo(eval(leadingtext))
- except: echo(generr)
- elif isMatch(followingtext, '$ECHO'):
- try: echo(leadingtext)
- except: echo(generr)
- elif isMatch(followingtext, '$TRUSTED'):
- try: echo(', '.join(self.trusted)+' are trusted.')
- except: echo(generr)
- #fun shit concerning users logging in/out
- #if not so many forumites auto-logged in when the chat loaded on the page
- #i'd have it echo() the login/logout message.
- elif event["event"] == "login":
- poster = event["user"]
- prettyPoster = poster.displayname
- print(prettyPoster + " just logged in.")
- elif event["event"] == "logout":
- poster = event["user"]
- prettyPoster = poster.displayname
- print(prettyPoster + " just logged out.")
- #if the loop is for some reason broken, disconnect from chat
- room.disconnect()
- #reference the variables defined in the start of this script, and start
- #the bot thread.
- BottingThread(address,password,username,trustedusers).start()
- #you can continue doing shit here.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement