def join_server(bot): messages.print_message("Connecting to " + bot.server_name + "...", messages.MessageType.GENERAL, True) bot.irc.connect((bot.server_name, bot.server_port)) bot.irc.send( utils.encode("USER " + bot.bot_username + " Ping Pong " + bot.bot_realname + "\n")) bot.irc.send(utils.encode("NICK " + bot.bot_nick + "\n"))
def greet(self, args): message = "✿ Greetings, love! ✿" if self.channel is not None: self.bot.irc.send( utils.encode("PRIVMSG " + self.channel + " :" + message + "\n")) else: self.bot.irc.send( utils.encode("PRIVMSG " + self.sender + " :" + message + "\n"))
def join(self, channel): try: messages.print_message("Joining " + channel + "...") self.bot.irc.send(utils.encode("JOIN " + channel + "\n")) while True: message = self.bot.irc.recv(self.bot.buffer).decode("UTF-8") message = message.strip('\n\r') if message: messages.print_message(message, messages.MessageType.NOTICE) if message.find("End of /NAMES list.") != null: return True if message.find(":Illegal") != null: raise Exception("Could not join: " + channel + " - Illegal channel name.") if message.find("PING :") != null: commands.pong(self.bot, message) if message.find(":Cannot") != null: raise Exception("Could not join: " + channel + " - No invitation was given.") else: break return True except Exception as error: raise Exception(error)
def start(self, *args): if len(args) == 0: messages.send_message( self.bot, self.sender + ", ''!leave' takes a required parameter -- <channel>", self.sender) else: params = args[0][0] channel = params[1] if len(params) > 0: if self.sender == self.bot.bot_master: try: messages.send_message( self.bot, "Attempting to leave: " + channel, self.sender) self.bot.irc.send( utils.encode("PART " + channel + "\n")) messages.send_message(self.bot, "Left " + channel, self.sender) except Exception as error: messages.send_message(self.bot, "Unable to leave: " + channel, self.sender) else: messages.send_message( self.bot, self.sender + ", I only listen to my master.", self.sender) else: messages.send_message( self.bot, self.sender + ", ''!leave' takes a required parameter -- <channel>", self.sender)
def join_channel(bot, channel): message = null messages.print_message("Joining " + channel + "...", messages.MessageType.GENERAL, True) bot.irc.send(utils.encode("JOIN " + channel + "\n")) while message.find("End of /NAMES list.") == null: message = bot.irc.recv(bot.buffer).decode("UTF-8") message = message.strip('\n\r') if message.find("PING :") != null: if logging.Logger.verbosity_level >= logging.Verbosity.DEBUG: messages.print_message(message, messages.MessageType.NOTICE, True) pong(message) else: messages.print_message(message, messages.MessageType.NOTICE, True)
def process_message(bot, message): # Log what the server sent us. data = message.strip() if data: # Check if we should play ping-pong. if message.find("PING :") != null: if logging.Logger.verbosity_level >= logging.Verbosity.DEBUG: print_message(data, MessageType.GENERAL, True) commands.pong(bot, message) return if message.find("QUOTE") != null: if logging.Logger.verbosity_level >= logging.Verbosity.DEBUG: print_message(data, MessageType.GENERAL, True) pong = message.split(" ")[len(message.split(" ")) - 1] pong = "PING :" + pong commands.pong(bot, pong) return print_message(data, MessageType.GENERAL, True) # Check if we should identify to the network. if bot.bot_registered: if message.find("Password accepted - you are now recognized") != null: print_message("We have connected to the IRC server and successfully logged in.") else: if message.find("NOTICE") != null: if message.find("This nickname is registered") != null: # print("[!] Sending identify command") bot.irc.send(utils.encode("PRIVMSG NickServ :identify " + bot.bot_password + "\n")) # Handle all other messages from the server if message.find("PRIVMSG") != null: # Split the name of the sender and its message. channel = None if message.find("#") != null: channel = message.split(' ')[2] sender = message.split('!', 1)[0][1:] contents = message.split('PRIVMSG', 1)[1].split(':', 1)[1] if sender == bot.bot_master or sender in bot.friends: if commands.iscommand(contents): bundle = commands.CommandBundle(bot, contents, sender, channel) commands.process_command(bundle) else: bot.irc.close() bot.connected = False print_message("The socket has been closed.", MessageType.WARNING)
def run(self, *args): params = args[0][0][0] if len(params) == 0: messages.send_message( self.bot, self.sender + ", '!kick' takes a required parameter -- <username> ", self.sender) else: if len(params) > 1: try: username = params[1] self.bot.irc.send( utils.encode("KICK " + self.channel + " " + username + "\n")) except: messages.send_message( self.bot, self.sender + ", I can't kick anybody.", self.sender) else: messages.send_message( self.bot, self.sender + ", '!kick' takes a required parameter - <username>", self.sender)
def start(self, *args): message = "Test module ∞ ⚭ ☨⚛︎ 🍪🍩🎂🍦🍕🍔🍟🥞🥓🥥🍓🍒🍑🍎🥝🌶🥒🥚🍏🍋🍉🍇🍅🥦🥨🍜🌮🍯🥂" self.bot.irc.send( utils.encode("PRIVMSG " + self.sender + " :" + message + "\n"))
def send_message(bot, message, target): bot.irc.send(utils.encode("PRIVMSG " + target + " :" + message + "\n"))
def start(self, *args): message = "🏓" self.bot.irc.send( utils.encode("PRIVMSG " + self.sender + " :" + message + "\n"))
def wave_action(bot, target): bot.socket.send( utils.encode("PRIVMSG " + target + " :\x01ACTION " + "waves at chat\n"))
def pong(bot, ping): reply = ping.split(':')[1] bot.irc.send(utils.encode("PONG :" + reply + "\n")) if logging.Logger.verbosity_level >= logging.Verbosity.DEBUG: messages.print_message("PONG :" + reply, messages.MessageType.GENERAL, True)