def log_in(self, connection, event): """ Logs incoming events.""" try: nick = self.string_escape(event.source().split('!')[0]) host = self.string_escape(event.source().split('!')[1]) except: nick = self.string_escape(event.source()) host = '' try: channel = self.string_escape(event.target().split('!')[0]) except: channel = self.string_escape(event.target()) if self.color_string_unescape(channel) == self.bot.nick: channel = nick server = self.bot.irc.server_nick(connection) event_type = event.eventtype() event_source = event.source() event_arguments = [] #print('lol', event.arguments()) for argument in event.arguments(): event_arguments.append(self.string_escape(argument)) #print('klol', event_arguments) event_target = event.target() target = 'global' sep_blue = self.Fore['BLUE']+'-'+self.Fore['RESET'] sep_green = self.Fore['GREEN']+'-'+self.Fore['RESET'] ident_server = sep_blue+'!'+sep_blue+' ' output = '' output += self.Style['DIM'] output += strftime("%H:%M:%S", localtime()) output += self.Style['RESET_ALL'] output += ' '+sep_green+server+sep_green+' ' indent = strings.printable_len(output) if event_type in ['all_raw_messages', 'ping', 'ctcp', ]: return elif event_type in ['action', ]: output += sep_blue output += channel output += sep_blue output += self.Style['BRIGHT']+' * ' output += nick+' '+self.Style['RESET_ALL'] indent = strings.printable_len(output) output += event_arguments[0] elif event_type in ['privnotice', '439', ]: output += self.Fore['GREEN'] output += nick output += self.Fore['RESET']+' ' for message in event_arguments: output += message+' ' elif event_type in ['welcome', 'yourhost', 'created', 'myinfo', 'featurelist', 'luserclient', 'luserop', 'luserchannels', 'luserme', 'n_local', 'n_global', 'luserconns', 'luserunknown', 'motdstart', 'motd', 'endofmotd', ]: output += ident_server indent = strings.printable_len(output) for message in event_arguments: output += message+' ' elif event_type in ['umode', ]: output += ident_server indent = strings.printable_len(output) output += 'Mode change ' output += self.Style['DIM']+'['+self.Style['RESET_ALL'] output += event_arguments[0] output += self.Style['DIM']+']'+self.Style['RESET_ALL'] output += ' for user ' output += self.Style['BRIGHT'] output += event_target elif event_type in ['mode', ]: output += ident_server indent = strings.printable_len(output) output += 'mode/' output += self.Style['DIM']+self.Fore['CYAN'] output += event_target output += self.Fore['RESET'] output += ' [' output += self.Style['RESET_ALL'] for arg in event_arguments: output += arg output += ' ' output = output[:-1] output += self.Style['DIM'] output += '] ' output += self.Style['RESET_ALL'] output += 'by user ' output += self.Style['BRIGHT'] output += nick elif event_type in ['nicknameinuse', ]: output += ident_server indent = strings.printable_len(output) try: output += event_arguments[1] output += ' ' output += self.Style['DIM']+'['+self.Style['RESET_ALL'] output += self.Style['BRIGHT']+event_arguments[0] output += self.Style['DIM']+']'+self.Style['RESET_ALL'] except: output += event_arguments elif event_type in ['invite', ]: output += ident_server indent = strings.printable_len(output) output += self.Style['BRIGHT'] output += nick output += self.Style['RESET_ALL'] output += ' invites you to ' output += self.Style['BRIGHT'] output += event_arguments[0] output += self.Style['RESET_ALL'] target = event_arguments[0] elif event_type in ['join', ]: output += ident_server indent = strings.printable_len(output) output += self.Style['BRIGHT']+self.Fore['CYAN'] output += nick output += self.Fore['RESET']+self.Style['RESET_ALL'] output += ' ' output += self.Style['DIM']+'[' output += self.Fore['CYAN'] output += self.string_escape(event.source().split('!')[1]) output += self.Fore['RESET'] output += ']'+self.Style['RESET_ALL'] output += ' has joined ' output += self.Style['BRIGHT'] output += event_target output += self.Style['RESET_ALL'] target = event_target elif event_type in ['quit', ]: output += ident_server indent = strings.printable_len(output) output += self.Fore['CYAN'] output += nick output += self.Fore['RESET'] output += ' ' output += self.Style['DIM']+'['+self.Style['RESET_ALL'] output += self.string_escape(event.source().split('!')[1]) output += self.Style['DIM']+']'+self.Style['RESET_ALL'] output += ' has quit ' output += self.Style['DIM']+'['+self.Style['RESET_ALL'] output += event_arguments[0] output += self.Style['DIM']+']'+self.Style['RESET_ALL'] elif event_type in ['currenttopic', ]: output += ident_server indent = strings.printable_len(output) output += 'Topic for ' output += self.Style['DIM']+self.Fore['CYAN'] output += event_arguments[0] output += self.Fore['RESET']+self.Style['RESET_ALL'] output += ': ' output += event_arguments[1] target = event_arguments[0] elif event_type in ['topic', ]: output += ident_server indent = strings.printable_len(output) output += self.Style['BRIGHT'] output += nick output += self.Style['RESET_ALL'] output += ' changed the topic of ' output += self.Style['BRIGHT'] output += event_target output += self.Style['RESET_ALL'] output += ' to: ' output += event_arguments[0] target = event_target elif event_type in ['topicinfo', ]: output += ident_server indent = strings.printable_len(output) output += 'Topic set by ' output += self.Style['BRIGHT'] output += event_arguments[1].split('!')[0] output += self.Style['RESET_ALL'] output += self.Style['DIM'] output += ' [' output += self.Style['RESET_ALL'] output += event_arguments[1].split('!')[1] output += self.Style['DIM'] output += '] ' output += self.Style['RESET_ALL'] output += 'on' output += self.Style['DIM'] output += ' [' output += self.Style['RESET_ALL'] output += strftime("%a %b %d, %H:%M:%S %Y", gmtime(int(event_arguments[2]))) output += self.Style['DIM'] output += '] ' output += self.Style['RESET_ALL'] target = event_target elif event_type in ['paert', ]: output += ident_server indent = strings.printable_len(output) output += self.Fore['CYAN'] output += nick output += self.Fore['RESET'] output += ' ' output += self.Style['DIM']+'['+self.Style['RESET_ALL'] output += host output += self.Style['DIM']+']'+self.Style['RESET_ALL'] output += ' has left ' output += self.Style['BRIGHT'] output += channel output += self.Style['RESET_ALL'] elif event_type in ['pubmsg', ]: output += sep_blue output += channel output += sep_blue output += self.Style['DIM']+' <'+self.Style['RESET_ALL'] output += self.nick_symbol(nick) output += self.nick_color(nick) output += nick output += self.Fore['RESET'] output += self.Style['DIM']+'> '+self.Style['RESET_ALL'] indent = strings.printable_len(output) output += event_arguments[0] target = channel elif event_type in ['privmsg', ]: output += sep_blue output += nick output += sep_blue output += self.Style['DIM']+' <'+self.Style['RESET_ALL'] output += self.nick_color(nick) output += nick output += self.Fore['RESET'] output += self.Style['DIM']+'> '+self.Style['RESET_ALL'] indent = strings.printable_len(output) output += event_arguments[0] target = nick elif event_type in ['nick', ]: output += ident_server indent = strings.printable_len(output) output += self.Fore['CYAN'] output += nick output += self.Fore['RESET'] output += ' is now known as ' output += self.Style['BRIGHT']+self.Fore['CYAN'] output += channel output += self.Fore['RESET']+self.Style['RESET_ALL'] else: output += "log_in: %s, source: %s, target: %s, arguments: %s" % (event_type, event_source, event_target, event_arguments) target = 'unidentified' self.log(output, indent, target)
def log_in(self, connection, event): """ Logs incoming events.""" try: nick = self.string_escape(event.source().split("!")[0]) host = self.string_escape(event.source().split("!")[1]) except: nick = self.string_escape(event.source()) host = "" try: channel = self.string_escape(event.target().split("!")[0]) except: channel = self.string_escape(event.target()) if self.color_string_unescape(channel) == self.bot.nick: channel = nick server = self.bot.irc.server_nick(connection) event_type = event.eventtype() event_source = event.source() event_arguments = [] # print('lol', event.arguments()) for argument in event.arguments(): event_arguments.append(self.string_escape(argument)) # print('klol', event_arguments) event_target = event.target() target = "global" sep_blue = self.Fore["BLUE"] + "-" + self.Fore["RESET"] sep_green = self.Fore["GREEN"] + "-" + self.Fore["RESET"] ident_server = sep_blue + "!" + sep_blue + " " output = "" output += self.Style["DIM"] output += strftime("%H:%M:%S", localtime()) output += self.Style["RESET_ALL"] output += " " + sep_green + server + sep_green + " " indent = strings.printable_len(output) if event_type in ["all_raw_messages", "ping", "ctcp"]: return elif event_type in ["action"]: output += sep_blue output += channel output += sep_blue output += self.Style["BRIGHT"] + " * " output += nick + " " + self.Style["RESET_ALL"] indent = strings.printable_len(output) output += event_arguments[0] elif event_type in ["privnotice", "439"]: output += self.Fore["GREEN"] output += nick output += self.Fore["RESET"] + " " for message in event_arguments: output += message + " " elif event_type in [ "welcome", "yourhost", "created", "myinfo", "featurelist", "luserclient", "luserop", "luserchannels", "luserme", "n_local", "n_global", "luserconns", "luserunknown", "motdstart", "motd", "endofmotd", ]: output += ident_server indent = strings.printable_len(output) for message in event_arguments: output += message + " " elif event_type in ["umode"]: output += ident_server indent = strings.printable_len(output) output += "Mode change " output += self.Style["DIM"] + "[" + self.Style["RESET_ALL"] output += event_arguments[0] output += self.Style["DIM"] + "]" + self.Style["RESET_ALL"] output += " for user " output += self.Style["BRIGHT"] output += event_target elif event_type in ["mode"]: output += ident_server indent = strings.printable_len(output) output += "mode/" output += self.Style["DIM"] + self.Fore["CYAN"] output += event_target output += self.Fore["RESET"] output += " [" output += self.Style["RESET_ALL"] for arg in event_arguments: output += arg output += " " output = output[:-1] output += self.Style["DIM"] output += "] " output += self.Style["RESET_ALL"] output += "by user " output += self.Style["BRIGHT"] output += nick elif event_type in ["nicknameinuse"]: output += ident_server indent = strings.printable_len(output) try: output += event_arguments[1] output += " " output += self.Style["DIM"] + "[" + self.Style["RESET_ALL"] output += self.Style["BRIGHT"] + event_arguments[0] output += self.Style["DIM"] + "]" + self.Style["RESET_ALL"] except: output += event_arguments elif event_type in ["invite"]: output += ident_server indent = strings.printable_len(output) output += self.Style["BRIGHT"] output += nick output += self.Style["RESET_ALL"] output += " invites you to " output += self.Style["BRIGHT"] output += event_arguments[0] output += self.Style["RESET_ALL"] target = event_arguments[0] elif event_type in ["join"]: output += ident_server indent = strings.printable_len(output) output += self.Style["BRIGHT"] + self.Fore["CYAN"] output += nick output += self.Fore["RESET"] + self.Style["RESET_ALL"] output += " " output += self.Style["DIM"] + "[" output += self.Fore["CYAN"] output += self.string_escape(event.source().split("!")[1]) output += self.Fore["RESET"] output += "]" + self.Style["RESET_ALL"] output += " has joined " output += self.Style["BRIGHT"] output += event_target output += self.Style["RESET_ALL"] target = event_target elif event_type in ["quit"]: output += ident_server indent = strings.printable_len(output) output += self.Fore["CYAN"] output += nick output += self.Fore["RESET"] output += " " output += self.Style["DIM"] + "[" + self.Style["RESET_ALL"] output += self.string_escape(event.source().split("!")[1]) output += self.Style["DIM"] + "]" + self.Style["RESET_ALL"] output += " has quit " output += self.Style["DIM"] + "[" + self.Style["RESET_ALL"] output += event_arguments[0] output += self.Style["DIM"] + "]" + self.Style["RESET_ALL"] elif event_type in ["currenttopic"]: output += ident_server indent = strings.printable_len(output) output += "Topic for " output += self.Style["DIM"] + self.Fore["CYAN"] output += event_arguments[0] output += self.Fore["RESET"] + self.Style["RESET_ALL"] output += ": " output += event_arguments[1] target = event_arguments[0] elif event_type in ["topic"]: output += ident_server indent = strings.printable_len(output) output += self.Style["BRIGHT"] output += nick output += self.Style["RESET_ALL"] output += " changed the topic of " output += self.Style["BRIGHT"] output += event_target output += self.Style["RESET_ALL"] output += " to: " output += event_arguments[0] target = event_target elif event_type in ["topicinfo"]: output += ident_server indent = strings.printable_len(output) output += "Topic set by " output += self.Style["BRIGHT"] output += event_arguments[1].split("!")[0] output += self.Style["RESET_ALL"] output += self.Style["DIM"] output += " [" output += self.Style["RESET_ALL"] output += event_arguments[1].split("!")[1] output += self.Style["DIM"] output += "] " output += self.Style["RESET_ALL"] output += "on" output += self.Style["DIM"] output += " [" output += self.Style["RESET_ALL"] output += strftime("%a %b %d, %H:%M:%S %Y", gmtime(int(event_arguments[2]))) output += self.Style["DIM"] output += "] " output += self.Style["RESET_ALL"] target = event_target elif event_type in ["paert"]: output += ident_server indent = strings.printable_len(output) output += self.Fore["CYAN"] output += nick output += self.Fore["RESET"] output += " " output += self.Style["DIM"] + "[" + self.Style["RESET_ALL"] output += host output += self.Style["DIM"] + "]" + self.Style["RESET_ALL"] output += " has left " output += self.Style["BRIGHT"] output += channel output += self.Style["RESET_ALL"] elif event_type in ["pubmsg"]: output += sep_blue output += channel output += sep_blue output += self.Style["DIM"] + " <" + self.Style["RESET_ALL"] output += self.nick_symbol(nick) output += self.nick_color(nick) output += nick output += self.Fore["RESET"] output += self.Style["DIM"] + "> " + self.Style["RESET_ALL"] indent = strings.printable_len(output) output += event_arguments[0] target = channel elif event_type in ["privmsg"]: output += sep_blue output += nick output += sep_blue output += self.Style["DIM"] + " <" + self.Style["RESET_ALL"] output += self.nick_color(nick) output += nick output += self.Fore["RESET"] output += self.Style["DIM"] + "> " + self.Style["RESET_ALL"] indent = strings.printable_len(output) output += event_arguments[0] target = nick elif event_type in ["nick"]: output += ident_server indent = strings.printable_len(output) output += self.Fore["CYAN"] output += nick output += self.Fore["RESET"] output += " is now known as " output += self.Style["BRIGHT"] + self.Fore["CYAN"] output += channel output += self.Fore["RESET"] + self.Style["RESET_ALL"] else: output += "log_in: %s, source: %s, target: %s, arguments: %s" % ( event_type, event_source, event_target, event_arguments, ) target = "unidentified" self.log(output, indent, target)
def log_out(self, connection, event): """ Logs outgoing events.""" try: nick = self.string_escape(event.source().split('!')[0]) host = self.string_escape(event.source().split('!')[1]) except: nick = self.string_escape(event.source()) host = '' try: channel = self.string_escape(event.target().split('!')[0]) except: channel = self.string_escape(event.target()) if self.color_string_unescape(channel) == self.bot.nick: channel = nick server = self.bot.irc.server_nick(connection) event_type = event.eventtype() event_arguments = [] for argument in event.arguments(): event_arguments.append(self.string_escape(argument)) event_target = self.string_escape(event.target()) target = 'global' sep_blue = self.Fore['BLUE']+'-'+self.Fore['RESET'] sep_green = self.Fore['GREEN']+'-'+self.Fore['RESET'] ident_server = sep_blue+'!'+sep_blue+' ' output = '' output += self.Style['DIM'] output += strftime("%H:%M:%S", localtime()) output += self.Style['RESET_ALL'] output += ' '+sep_green+server+sep_green+' ' indent = strings.printable_len(output) if event_type in ['all_raw_messages', 'ping', ]: pass elif event_type in ['action', ]: output += sep_blue output += channel output += sep_blue output += self.Style['BRIGHT'] output += ' * '+nick output += self.Style['RESET_ALL'] output += ' ' indent = strings.printable_len(output) output += event_arguments[0] target = channel elif event_type in ['privmsg', ]: output += sep_blue output += channel output += sep_blue output += self.Style['DIM']+' <'+self.Style['RESET_ALL'] output += self.nick_symbol(nick) output += self.Style['BRIGHT'] output += nick output += self.Style['RESET_ALL'] output += self.Fore['RESET'] output += self.Style['DIM']+'> '+self.Style['RESET_ALL'] indent = strings.printable_len(output) output += event_arguments[0] target = channel else: output += "log_out: %s, source: %s, target: %s, arguments: %s" % (event.eventtype(), event.source(), event.target(), event.arguments()) target = 'unidentified' self.log(output, indent, target)
def log_out(self, connection, event): """ Logs outgoing events.""" try: nick = self.string_escape(event.source().split("!")[0]) host = self.string_escape(event.source().split("!")[1]) except: nick = self.string_escape(event.source()) host = "" try: channel = self.string_escape(event.target().split("!")[0]) except: channel = self.string_escape(event.target()) if self.color_string_unescape(channel) == self.bot.nick: channel = nick server = self.bot.irc.server_nick(connection) event_type = event.eventtype() event_arguments = [] for argument in event.arguments(): event_arguments.append(self.string_escape(argument)) event_target = self.string_escape(event.target()) target = "global" sep_blue = self.Fore["BLUE"] + "-" + self.Fore["RESET"] sep_green = self.Fore["GREEN"] + "-" + self.Fore["RESET"] ident_server = sep_blue + "!" + sep_blue + " " output = "" output += self.Style["DIM"] output += strftime("%H:%M:%S", localtime()) output += self.Style["RESET_ALL"] output += " " + sep_green + server + sep_green + " " indent = strings.printable_len(output) if event_type in ["all_raw_messages", "ping"]: pass elif event_type in ["action"]: output += sep_blue output += channel output += sep_blue output += self.Style["BRIGHT"] output += " * " + nick output += self.Style["RESET_ALL"] output += " " indent = strings.printable_len(output) output += event_arguments[0] target = channel elif event_type in ["privmsg"]: output += sep_blue output += channel output += sep_blue output += self.Style["DIM"] + " <" + self.Style["RESET_ALL"] output += self.nick_symbol(nick) output += self.Style["BRIGHT"] output += nick output += self.Style["RESET_ALL"] output += self.Fore["RESET"] output += self.Style["DIM"] + "> " + self.Style["RESET_ALL"] indent = strings.printable_len(output) output += event_arguments[0] target = channel else: output += "log_out: %s, source: %s, target: %s, arguments: %s" % ( event.eventtype(), event.source(), event.target(), event.arguments(), ) target = "unidentified" self.log(output, indent, target)