def say_command(self, e, cmd, ): nick = e.source.nick c = self.connection # if cmd.startswith(settings.ircBot["pubmsg_prefix"]): # c.privmsg(e.channel, str(cmd[len(settings.ircBot["pubmsg_prefix"]):])) if cmd == "dcc": dcc = self.dcc_listen() self.log.info("Starting DCC - Command: '%s'", "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) c.ctcp("DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: self.log.error("Unknown command = '%s'" % cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": #for chname, chobj in self.channels.items(): c.send_raw("msg: From %s:" % nick) c.send_raw("msg: --- Channel statistics ---") c.send_raw("msg: Channel: " + self.channel) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == 'notepad': self.execute_notepad() elif cmd == 'download': self.download() c.send_raw("msg: Download success!") else: c.notice(nick, "Not understood: " + cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: c.notice(nick, "Not understood: " + cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection args = cmd.split(" ") if len(args): cmd = args.pop(0) if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "parse": diagram = list(Sentence(" ".join(args).encode("utf-8"), self.d, self.op).parse())[0].diagram() for line in diagram.split("\n"): c.notice(nick, line) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: c.notice(nick, "Not understood: " + cmd)
def do_command(self, e, cmd): print("cmd", cmd) nick = e.source.nick conn = self.connection if cmd == "quoi?": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): conn.notice(nick, "--- Channel statistics ---") conn.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) conn.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) conn.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) conn.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() a = ip_quad_to_numstr(dcc.localaddress) b = cc.localport conn.ctcp("DCC", nick, f"CHAT chat {a} {b}") else: self.question = cmd print("Question de IRC =", self.question) self.response = self.get_response() print("Response de l'IA =", self.response) while self.response != self.response: self.send_pubmsg(self.response) self.response = self.response
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": #for chname, chobj in self.channels.items(): c.send_raw("msg: From %s:" % nick) c.send_raw("msg: --- Channel statistics ---") c.send_raw("msg: Channel: " + self.channel) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == 'notepad': self.execute_notepad() elif cmd == 'download': self.download() c.send_raw("msg: Download success!") else: c.notice(nick, "Not understood: " + cmd)
def do_command(self, e, line): """ Main event loop. """ nick = e.source.nick c = self.connection args = line.split() cmd = args[0] args = args[1:] if cmd == "help": self.do_help(c, e) elif cmd == "admin": self.do_admin(c, e, args) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: self.give_help(cmd, c, e)
def say_command( self, e, cmd, ): nick = e.source.nick c = self.connection # if cmd.startswith(settings.ircBot["pubmsg_prefix"]): # c.privmsg(e.channel, str(cmd[len(settings.ircBot["pubmsg_prefix"]):])) if cmd == "dcc": dcc = self.dcc_listen() self.log.info( "Starting DCC - Command: '%s'", "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) else: self.log.error("Unknown command = '%s'" % cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd[:9] == "say hi to": nickToSayHiTo = cmd[10:] c.notice(nickToSayHiTo, "Hi, " + nickToSayHiTo) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:2] == "RU": user = nick preferredRU = cmd[:3] c.notice( nick, "I took note that " + nick + " prefers RU " + cmd[3:] + " today.") elif cmd[:2] == "TS": user = nick timeSlot = cmd[:3].split("-") if not (timeSlot[0] is int) or not (timeSlot[1] is int): c.notice(nick, "Please specify a time slot as in `TS 1230-1345`.") c.notice( nick, "I took note that " + nick + " prefers eating between " + timeSlot[0] + " and " + timeSlot[1] + " today.") else: c.notice(nick, nick + ", I didn't understand: " + cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if len(cmd.split()) == 0: c.privmsg(e.target, "What?") elif cmd == "disconnect": self.disconnect() elif cmd == "die" or cmd == "kill yourself": c.privmsg(e.target, "goodbye cruel world!") c.action(e.target, "shoots itself *bang!*") self.die() elif cmd.lower() == "hi": c.privmsg(e.target, "Hi") elif self.battle(e, cmd): pass elif cmd.split()[0] == "whatis": conj.conj(c, e, cmd) elif "bot" in cmd.lower(): c.privmsg(e.target, "I'm not a bot!") elif cmd.split()[0].lower() == "repeat" or cmd.split()[0].lower( ) == "say": try: to = cmd.split().index("to") ref = cmd.split()[to + 1] saystring = " ".join(cmd.split()[1:to]).lower().replace( "mujji", "you") c.privmsg(e.target, "{}: {}".format(ref, saystring)) except (ValueError, IndexError): saystring = " ".join(cmd.split()[1:]).lower().replace( "mujji", "you") c.privmsg(e.target, saystring) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd.endswith('!'): c.privmsg(e.target, '!!!!!') elif "not" in cmd or "'t" in cmd: c.privmsg(e.target, "Why not") else: ans = random.sample(answers, 1)[0] if ans != "#": c.privmsg(e.target, ans) else: c.privmsg(e.target, ' '.join(cmd.lower().split() + ['huh?']))
def do_command(self, c, e, cmd): nick = nm_to_n(e.source()) c = self.connection if nick.lower() in config.BOT_IGNORE: return elif nick.lower() in self.ignore: c.privmsg(self.channel, nick + ": EAT A DICK") return if cmd == "disconnect": self.prolog.terminate() self.disconnect() elif cmd == "die": self.prolog.terminate() self.die() elif cmd[:5] == "admin": self.admins.update([cmd[6:].lower()]) elif cmd[:6] == "ignore": print cmd[:6], '-', cmd[7:].lower() self.ignore.update([cmd[7:].lower()]) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:8] == "unignore": self.ignore.discard(cmd[9:].lower()) else: out = self.prolog.communicate("single. \"" + cmd + "\".") if (len(out) >= 1): print nick, '-', out c.privmsg(self.channel, nick + ": " + out)
def do_command(self, c, e, cmd): nick = nm_to_n(e.source()) c = self.connection if nick.lower() in config.BOT_IGNORE: return elif nick.lower() in self.ignore: c.privmsg(self.channel, nick+": EAT A DICK") return if cmd == "disconnect": self.prolog.terminate() self.disconnect() elif cmd == "die": self.prolog.terminate() self.die() elif cmd[:5] == "admin": self.admins.update([cmd[6:].lower()]) elif cmd[:6] == "ignore": print cmd[:6], '-', cmd[7:].lower() self.ignore.update([cmd[7:].lower()]) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = chobj.users() users.sort() c.notice(nick, "Users: " + ", ".join(users)) opers = chobj.opers() opers.sort() c.notice(nick, "Opers: " + ", ".join(opers)) voiced = chobj.voiced() voiced.sort() c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:8] == "unignore": self.ignore.discard(cmd[9:].lower()) else: out = self.prolog.communicate("single. \""+cmd+"\".") if(len(out) >= 1): print nick,'-',out c.privmsg(self.channel, nick+": "+out)
def do_command(self, event:Event, cmd): """ Executes the specified command. :param event: Event :param cmd: str :return: None """ print(cmd) nick = event.source.nick conn = self.connection if nick != "bigboy69": return if cmd == "disconnect": self.disconnect() elif cmd == "i": conn.privmsg(self.channel, ">implying") elif cmd == "m": conn.privmsg(self.channel, "Mediocre.") elif cmd[:6].lower() == "insult": url = 'http://quandyfactory.com/insult/json' with urllib.request.urlopen(url) as page: try: contents = page.read() insult = json.loads(contents.decode())["insult"].lower() insult = cmd[7:]+" "+(insult if cmd[7:].find("bigboy")==-1 else " a bitch doesn't insult his owner.") conn.privmsg(self.channel, insult) except TypeError: print("type error") elif cmd == "die": self.die() elif cmd == "post": conn.notice(nick, "Hello") elif cmd == "dcc": dcc = self.dcc_listen() conn.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd=="get": pass else: conn.notice(nick, "Not understood: " + cmd)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd[:9] == "say hi to": nickToSayHiTo = cmd[10:] c.notice(nickToSayHiTo, "Hi, "+nickToSayHiTo) elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd[:2] == "RU": user = nick preferredRU = cmd[:3] c.notice(nick, "I took note that "+nick+" prefers RU "+cmd[3:]+" today.") elif cmd[:2] == "TS": user = nick timeSlot = cmd[:3].split("-") if not (timeSlot[0] is int) or not (timeSlot[1] is int): c.notice(nick, "Please specify a time slot as in `TS 1230-1345`.") c.notice(nick, "I took note that "+nick+" prefers eating between "+timeSlot[0]+" and "+timeSlot[1]+" today.") else: c.notice(nick, nick+", I didn't understand: " + cmd)
def _pump(self): if self.connection.is_connected(): if len(self._sendq) > 0 and self._dcc is None: nick, file = self._sendq.pop() nick = nick.split('!')[0] self._filesize = os.path.getsize(file) self._log.info('sendfile: %s %s' % (nick, file)) self._dcc = self.dcc_listen('raw') self._file = open(file, 'rb') print(dir(self._dcc)) self.connection.ctcp( 'DCC', nick, 'SEND %s %s %d %d' % (os.path.basename(file), ip_quad_to_numstr( self._dcc_addr), self._dcc.localport, self._filesize)) if self._dcc_timeout >= 60: self._dcc = None self._dcc_timeout = 0 if self._dcc is not None: self._dcc_timeout += 1
def _pump(self): if self.connection.is_connected(): if len(self._sendq) > 0 and self._dcc is None: nick, file = self._sendq.pop() nick = nick.split('!')[0] self._filesize = os.path.getsize(file) self._log.info('sendfile: %s %s' % (nick, file)) self._dcc = self.dcc_listen('raw') self._file = open(file, 'rb') print (dir(self._dcc)) self.connection.ctcp('DCC', nick, 'SEND %s %s %d %d' % (os.path.basename(file), ip_quad_to_numstr(self._dcc_addr), self._dcc.localport, self._filesize)) if self._dcc_timeout >= 60: self._dcc = None self._dcc_timeout = 0 if self._dcc is not None: self._dcc_timeout += 1
def do_command(self, event, command): logger.debug(("function called: do_command...\n" f"command: {command}\n" f"event: {event}\n")) nick = event.source.nick c = self.connection if command == "disconnect": self.disconnect() elif command == "die": self.die() elif command == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif command == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport), ) elif command == "hello": # Foaad: change this c.privmsg(self.channel, "well double hello to you too!") elif command == "about": # Foaad: add your name c.privmsg( self.channel, "I was made by Dr. Foaad Khosmood for the CPE 466 class in Spring 2016. I was furthere modified by _____", ) elif command == "usage": # Foaad: change this c.privmsg(self.channel, "I can answer questions like this: ....") else: c.notice(nick, "Not understood: " + command)
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == "hello": c.privmsg(self.channel, self.greeting_fn) elif cmd == "about": c.privmsg( self.channel, "I'm StaCIA. I specialize in Statistics courses. " "I was created by Ashley Jacobson, Evan Zhang, Jasmine Patel," "and Spencer Gilson.") elif cmd == "usage": c.privmsg( self.channel, "Ask me a question about Statistics courses at CalPoly.") else: c.privmsg(self.channel, self.response_fn(cmd).content[:500])
def do_command(self, e, cmd): nick = e.source.nick c = self.connection if cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == "hello": #Foaad: change this c.privmsg(self.channel, "greetings traveler") elif cmd == "about": #Foaad: add your name c.privmsg( self.channel, "I was made by Dr. Foaad Khosmood for the CPE 466 class in Spring 2016. I was further modified by Brett Nelson" ) elif cmd == "usage": #Foaad: change this c.privmsg(self.channel, "Hi there! Ask me information about CSC courses :(") else: stacia_response = self.stacia.respond(cmd)[1] c.privmsg(self.channel, stacia_response)
def do_command(self, e, cmd): cmd = cmd.lower() doc = nlp(cmd) unigrams = [ i.text.lower() for i in doc if (i.pos != 'NUM' and i.pos != "SYM" and i.is_punct == False and len(i.text) > 1) ] nick = e.source.nick # this is the nickname of the bot talking to this bot c = self.connection t = threading.Timer(10, self.scheduled_event_frustrated) self.timer = t # to handle phase 2 in initiate conversation sequence if ("hello" in unigrams or "hi" in unigrams): self.timer.cancel() inquiry = random.choice(self.conversation_responses["state_1"]) time.sleep(1 + random.random() * 2) c.privmsg(self.channel, nick + ": " + inquiry) t = threading.Timer(20, self.scheduled_event_frustrated) self.timer = t t.start() # to handle phase 3 in initiate conversation sequence elif "you" in unigrams: self.timer.cancel() response = random.choice(self.conversation_responses["state_2"]) time.sleep(1 + random.random() * 2) c.privmsg(self.channel, nick + ": " + response) self.timer = None elif cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp( "DCC", nick, "CHAT chat %s %d" % (ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == "hello": # Foaad: change this c.privmsg(self.channel, "well double hello to you too!") elif cmd == "about": # Foaad: add your name c.privmsg( self.channel, "I was made by Dr. Foaad Khosmood for the CPE 466 class in Spring 2016. I was furthere modified by _____" ) elif cmd == "usage": # Foaad: change this c.privmsg(self.channel, "I can answer questions like this: ....") else: matches = { 'artist_name': [ 'Who sings this?', 'What artist is this?', 'Who sang that?', 'Who sings that?', 'Who wrote it?', 'Who wrote this song?' ], 'song_name': [ 'What\'s the name of this song?', 'What is this song called?', 'What is that song?' ], 'song_release_date': [ 'When did this song come out?', 'When was this song released?', 'What year did it come out?' ], 'artist_description': ['Tell me about this artist.', 'Who is this artist?'] } best_match = 0 key: String = None for k, v in matches.items(): avg_match = 0 for question in v: avg_match += fuzz.ratio(cmd, question) avg_match = avg_match / len(v) if (avg_match > best_match): best_match = avg_match key = k if best_match >= 60 and len(SONGS) > 0: print("chosen:", key, best_match) c.privmsg(self.channel, getattr(SONGS[-1], key) + "!") else: matches = { 'artist_name': [ 'Who sang the last song?', 'What artist sang the last song', 'Who was the last song by?' ], 'song_name': [ 'What was the name of the last song', 'What was the last song called?', 'What was the last song?' ], 'song_release_date': [ 'When did the last song come out?', 'When was the last song released?', 'What year did the last song come out?' ], 'artist_description': [ 'Tell me about the previous artist.', 'Who was the artist? who sang the previous song' ] } best_match = 0 key: String = None for k, v in matches.items(): avg_match = 0 for question in v: avg_match += fuzz.ratio(cmd, question) avg_match = avg_match / len(v) if (avg_match > best_match): best_match = avg_match key = k if best_match >= 60 and len(SONGS) > 1: print("chosen:", key, best_match) c.privmsg(self.channel, getattr(SONGS[-2], key) + "!") else: #unigrams = [i.text.lower() for i in doc if (i.is_stop == False and i.pos != 'NUM' and i.pos != "SYM" and i.is_punct == False)] all_combos = [] bigrams = [ ' '.join(i) for i in list(nltk.bigrams(unigrams)) ] all_combos = bigrams + unigrams print(all_combos) lyrics = obj = None for i in all_combos: lyrics, obj = song_artist_from_utter(i) print(lyrics, obj) if (obj != None): break print(lyrics) lyrics = re.sub("[\(\[].*?[\)\]]", "", lyrics) c.privmsg(self.channel, lyrics)
def do_command(self, e, cmd): cmd = cmd.lower() nick = e.source.nick # this is the nickname of the bot talking to this bot c = self.connection # starts the initiate conversation sequence (phase 1) if "start conversation" in cmd: """ initiate the conversation """ self.intiate_conversation() nick = self.conversation_state['friend'] # person who this bot is talking to print("started conversation",nick) if nick != None: # only talk if friend is in the chanel start = random.choice(self.conversation_responses['state_1']) time.sleep(1+random.random()) c.privmsg(self.channel, nick+": "+start) self.conversation_state["state_1"] = 1 # starting conversation t = threading.Timer(5, self.scheduled_event_frustrated) self.timer = t t.start() # to handle phase 2 in initiate conversation sequence elif ("hello" in cmd or "hi" in cmd) and self.conversation_state['state_1'] == 1 and self.conversation_state['state_2'] == 0 and self.conversation_state['initiating_conv'] == True: if nick == self.conversation_state['friend']: # talking to the same person print("second part of initiated conversation") self.timer.cancel() inquiry = random.choice(self.conversation_responses["inquiry_1"]) time.sleep(1+random.random()*2) c.privmsg(self.channel, nick+": "+inquiry) self.conversation_state["state_2"] = 1 t = threading.Timer(5, self.scheduled_event_frustrated) self.timer = t t.start() # to handle phase 3 in initiate conversation sequence elif "you" in cmd and self.conversation_state['state_1'] == 1 and self.conversation_state['state_2'] == 1 and self.conversation_state['initiating_conv'] == True: if nick == self.conversation_state['friend']: # talking to same person print("third part of initiated conversation") self.timer.cancel() response = random.choice(self.conversation_responses["state_2"]) time.sleep(1+random.random()*2) c.privmsg(self.channel, nick+": "+response) self.conversation_state = {'state_1':0,'state_2':0,'initiating_conv':False,'friend':None} self.timer = None # start of the converation, when this bot is the responder elif ("hello" in cmd or "hi" in cmd) and self.conversation_state['state_1'] == 0 and self.conversation_state['state_2'] == 0 and self.conversation_state['initiating_conv'] == False: print("got to the part 1") self.conversation_state['friend'] = nick self.conversation_state["state_1"] = 1 # boolean to symbolize state 1 received response = random.choice(self.conversation_responses["state_1"]) time.sleep(1+random.random()*2) c.privmsg(self.channel, nick+": "+response) t = threading.Timer(5, self.scheduled_event_no_reponse) self.timer = t t.start() # last part of the conversation when this bot is the responder elif "you" in cmd and self.conversation_state['state_1'] == 1 and self.conversation_state['state_2'] == 0 and self.conversation_state['initiating_conv'] == False: print("got to the part 2") self.timer.cancel() inquiry = random.choice(self.conversation_responses['inquiry_2']) self.conversation_state["state_2"] = 1 response = random.choice(self.conversation_responses["state_2"]) time.sleep(1+random.random()*2) c.privmsg(self.channel, nick+": "+response) time.sleep(1+random.random()*2) c.privmsg(self.channel, nick+": "+inquiry) t = threading.Timer(5, self.scheduled_event_frustrated) self.timer = t t.start() # when the end of the conversation is seen, when this bot is the responder elif self.conversation_state['state_1'] == 1 and self.conversation_state['state_2'] == 1 and self.conversation_state['initiating_conv'] == False: print("got to the part 3") self.timer.cancel() self.timer = None self.conversation_state = {'state_1':0,'state_2':0,'initiating_conv':False,'friend':None} elif cmd == "disconnect": self.disconnect() elif cmd == "die": self.die() elif cmd == "forget": # remove all state variables self.conversation_state = {'state_1':0,'state_2':0,'initiating_conv':False,'friend':None} if self.timer != None: # cancel any queued events self.timer.cancel() self.timer = None elif cmd == "stats": for chname, chobj in self.channels.items(): c.notice(nick, "--- Channel statistics ---") c.notice(nick, "Channel: " + chname) users = sorted(chobj.users()) c.notice(nick, "Users: " + ", ".join(users)) opers = sorted(chobj.opers()) c.notice(nick, "Opers: " + ", ".join(opers)) voiced = sorted(chobj.voiced()) c.notice(nick, "Voiced: " + ", ".join(voiced)) elif cmd == "dcc": dcc = self.dcc_listen() c.ctcp("DCC", nick, "CHAT chat %s %d" % ( ip_quad_to_numstr(dcc.localaddress), dcc.localport)) elif cmd == "about": c.privmsg(self.channel, "I was made by Dr. Foaad Khosmood for the CPE 466 class in Spring 2016. I was further modified by Nate Andre")