Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ch
- import time
- class bot(ch.RoomManager):
- timeleft = 0
- starttime = 0
- mode = 'n'
- nominations = []
- votes = []
- 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.
- print("[{0}] {1}: {2}".format(room.name, user.name.title(), message.body))
- try:
- cmd, args = message.body.split(" ", 1)
- except:
- cmd, args = message.body, ""
- if cmd[0] == "!":
- prfx = True
- cmd = cmd[1:]
- else:
- prfx = False
- 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.
- if cmd.lower() == "nominate" and prfx:
- nominations.extend(args)
- 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.
- if cmd.lower() == "vote" and prfx:
- votes.extend(args)
- loop = 1
- while loop == 1 : #This is the loop that simply checks the time and updates timeleft
- timeleft = starttime - int(time.clock())
- if timeleft <=0 and mode == 'n': #switches to "vote" mode if timeleft in "nominate" mode reaches 0
- timeleft = 50
- starttime = 50
- mode = 'v'
- if timeleft <=0 and mode == 'v': #vice versa
- timeleft = 200
- starttime = 200
- mode = 'n'
- rooms = ["testgroup444"]
- username = "user"
- password = "pass"
- 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