Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import ch
  2. import time
  3.  
  4. class bot(ch.RoomManager):
  5. timeleft = 0
  6. starttime = 0
  7. mode = 'n'
  8. nominations = []
  9. votes = []
  10.  
  11. def onMessage(self, room, user, message): #This function is called every time an event (anyone posts a message in room) happens. In this case, it is printed and analyzed if it contains a command.
  12. print("[{0}] {1}: {2}".format(room.name, user.name.title(), message.body))
  13. try:
  14. cmd, args = message.body.split(" ", 1)
  15. except:
  16. cmd, args = message.body, ""
  17.  
  18. if cmd[0] == "!":
  19. prfx = True
  20. cmd = cmd[1:]
  21. else:
  22. prfx = False
  23.  
  24. if 100 >= timeleft >= 1 and mode == 'n': #checks if timeleft is less than 100 seconds and bot is in "nominate" mode. If so, args are added to a nominations list.
  25. if cmd.lower() == "nominate" and prfx:
  26. nominations.extend(args)
  27. if 50 >= timeleft >= 1 and mode == 'v': #checks if timeleft is less than 50 seconds and bot is in "vote" mode. If so, args are added to a vote list.
  28. if cmd.lower() == "vote" and prfx:
  29. votes.extend(args)
  30.  
  31. loop = 1
  32. while loop == 1 : #This is the loop that simply checks the time and updates timeleft
  33. timeleft = starttime - int(time.clock())
  34.  
  35. if timeleft <=0 and mode == 'n': #switches to "vote" mode if timeleft in "nominate" mode reaches 0
  36. timeleft = 50
  37. starttime = 50
  38. mode = 'v'
  39. if timeleft <=0 and mode == 'v': #vice versa
  40. timeleft = 200
  41. starttime = 200
  42. mode = 'n'
  43.  
  44.  
  45. rooms = ["testgroup444"]
  46. username = "user"
  47. password = "pass"
  48.  
  49. bot.easy_start(rooms,username,password) #this runs the entire bot continuously, using the credentials give above it. Normally, this should parse the messages posted in the chat room as they come, automatically.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement