def me(self, string, connection, event): server = self.bot.irc.server_nick(connection) (password, target, message) = splitnum(string, split_num=2) pass_hash = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == pass_hash: self.bot.irc.action(server, target, message)
def quit(self, string, connection, event): server = self.bot.irc.server_nick(connection) (password, message) = splitnum(string) password = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == password: self.bot.irc.quit(server, message)
def retrieve_indent(string): """ Extracts indent from the beginning of the given string.""" try: (indent_string, out_string) = splitnum(string, split_char="}") indent = int(indent_string[2:]) except: indent = 0 out_string = string return (indent, out_string)
def retrieve_indent(string): """ Extracts indent from the beginning of the given string.""" try: (indent_string, out_string) = splitnum(string, split_char='}') indent = int(indent_string[2:]) except: indent = 0 out_string = string return (indent, out_string)
def suggest(self, string, connection, event): server = self.bot.irc.server_nick(connection) channel = event.target().split('!')[0] nick = event.source().split('!')[0] if channel == self.bot.nick: channel = nick (command, suggestion) = splitnum(string) command = command.lower() if suggestion == '': output_lines = [ 'SUGEST SYNTAX: ' + self.bot.prefix + 'suggest <command> <suggestion>', "<command> is what about goshu the suggestion affects; for example: if suggesting a different " + self.bot.prefix + "who output for someone, <command> would be who", '<suggestion> is the suggestion you want to pass on' ] for i in range(0, len(output_lines)): if i > 0: output = ' ' * self.bot.indent else: output = '' output += output_lines[i] self.bot.irc.privmsg(server, nick, output) return output = server + ' - ' output += event.source() + ' - ' output += command output += '\n\t' output += suggestion output += '\n' command_escape = '' for character in command: if character in self.valid_characters: command_escape += character else: command_escape += '_' path = 'suggestions/' + command_escape outfile = open(path, 'a') outfile.write(output) outfile.close() self.bot.irc.privmsg(server, nick, 'Thanks for your suggestion')
def ignore(self, string, connection, event): server = self.bot.irc.server_nick(connection) nick = event.source().split('!')[0] (password, nickhost) = splitnum(string) pass_hash = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == pass_hash: ignore_nick = nickhost.split('!')[0] self.bot.irc._nick_ignore_list.append(ignore_nick) try: ignore_host = nickhost.split('!')[1] if ignore_host != '': self.bot.irc._host_ignore_list.append(ignore_host) except: pass self.bot.irc.privmsg(server, nick, nickhost+' has been ignored')
def ignore(self, string, connection, event): server = self.bot.irc.server_nick(connection) nick = event.source().split('!')[0] (password, nickhost) = splitnum(string) pass_hash = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == pass_hash: ignore_nick = nickhost.split('!')[0] self.bot.irc._nick_ignore_list.append(ignore_nick) try: ignore_host = nickhost.split('!')[1] if ignore_host != '': self.bot.irc._host_ignore_list.append(ignore_host) except: pass self.bot.irc.privmsg(server, nick, nickhost + ' has been ignored')
def printable_len(in_string=None): """ Gives how many printable characters long the string is.""" printable = 0 if in_string: running = True while running: if in_string[0] == "/" and in_string[1] == "{": (temp_first, temp_last) = splitnum(in_string, split_char="}") in_string = temp_last elif in_string[0] == "/" and in_string[1] == "/": printable += 1 in_string = in_string[2:] elif in_string[0].isprintable(): printable += 1 in_string = in_string[1:] if len(in_string) < 1: running = False return printable
def printable_len(in_string=None): """ Gives how many printable characters long the string is.""" printable = 0 if in_string: running = True while running: if in_string[0] == '/' and in_string[1] == '{': (temp_first, temp_last) = splitnum(in_string, split_char='}') in_string = temp_last elif in_string[0] == '/' and in_string[1] == '/': printable += 1 in_string = in_string[2:] elif in_string[0].isprintable(): printable += 1 in_string = in_string[1:] if len(in_string) < 1: running = False return printable
def suggest(self, string, connection, event): server = self.bot.irc.server_nick(connection) channel = event.target().split('!')[0] nick = event.source().split('!')[0] if channel == self.bot.nick: channel = nick (command, suggestion) = splitnum(string) command = command.lower() if suggestion == '': output_lines = ['SUGEST SYNTAX: '+self.bot.prefix+'suggest <command> <suggestion>', "<command> is what about goshu the suggestion affects; for example: if suggesting a different "+self.bot.prefix+"who output for someone, <command> would be who", '<suggestion> is the suggestion you want to pass on'] for i in range(0, len(output_lines)): if i > 0: output = ' ' * self.bot.indent else: output = '' output += output_lines[i] self.bot.irc.privmsg(server, nick, output) return output = server + ' - ' output += event.source() + ' - ' output += command output += '\n\t' output += suggestion output += '\n' command_escape = '' for character in command: if character in self.valid_characters: command_escape += character else: command_escape += '_' path = 'suggestions/'+command_escape outfile = open(path, 'a') outfile.write(output) outfile.close() self.bot.irc.privmsg(server, nick, 'Thanks for your suggestion')
def unignore(self, string, connection, event): server = self.bot.irc.server_nick(connection) nick = event.source().split('!')[0] (password, nickhost) = splitnum(string) pass_hash = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == pass_hash: nickhost = nickhost.split('!')[0] for i in range(len(self.bot.irc._nick_ignore_list)): if self.bot.irc._nick_ignore_list[i] == nickhost: del self.bot.irc._nick_ignore_list[i] try: ignore_host = nickhost.split('!')[1] if ignore_host != '': for i in range(len(self.bot.irc._host_ignore_list)): if self.bot.irc._host_ignore_list[i] == ignore_host: del self.bot.irc._host_ignore_list[i] except: pass self.bot.irc.privmsg(server, nick, nickhost+' has been unignored')
def unignore(self, string, connection, event): server = self.bot.irc.server_nick(connection) nick = event.source().split('!')[0] (password, nickhost) = splitnum(string) pass_hash = self.bot.encrypt(password.encode('utf-8')) if self.bot.pass_hash == pass_hash: nickhost = nickhost.split('!')[0] for i in range(len(self.bot.irc._nick_ignore_list)): if self.bot.irc._nick_ignore_list[i] == nickhost: del self.bot.irc._nick_ignore_list[i] try: ignore_host = nickhost.split('!')[1] if ignore_host != '': for i in range(len(self.bot.irc._host_ignore_list)): if self.bot.irc._host_ignore_list[i] == ignore_host: del self.bot.irc._host_ignore_list[i] except: pass self.bot.irc.privmsg(server, nick, nickhost + ' has been unignored')
def split_line(in_string=''): """ Splits line into an alternating string/list format, string for text and list for attributes to be used/parsed.""" split_line = [] while len(in_string) > 0: if in_string[0] == '/': if in_string[1] == '{': #attributes attribute_line, in_string = splitnum(in_string, split_char='}') attributes = attribute_line[2:].split(',') attributes_split = [] for attribute in attributes: if ':' in attribute: attribute = attribute.split(':') attributes_split.append(attribute) split_line.append(attributes_split) split_line.append('') else: split_line[-1] += in_string[0:2] in_string = in_string[2:] else: split_line[-1] += in_string[0] in_string = in_string[1:] return split_line
def wrap(in_string, indent): try: rows, columns = os.popen('stty size', 'r').read().split() except: #not being executed in a terminal return in_string output = '' running = True i = 1 line = 0 while running: if in_string[0] == '/' and in_string[1] == '{': (temp_first, temp_last) = splitnum(in_string, split_char='}') output += temp_first + '}' in_string = temp_last elif in_string[0] == '/': output += '/' + in_string[1] i += 1 in_string = in_string[2:] elif in_string[0] in string.printable: output += in_string[0] i += 1 in_string = in_string[1:] else: output += in_string[0] in_string = in_string[1:] if int(i) > int(columns): output += ' ' * int(indent) i = 1 if line == 0: columns = int(columns) - int(indent) line += 1 if len(in_string) < 1: running = False return output
def wrap(in_string, indent): try: rows, columns = os.popen("stty size", "r").read().split() except: # not being executed in a terminal return in_string output = "" running = True i = 1 line = 0 while running: if in_string[0] == "/" and in_string[1] == "{": (temp_first, temp_last) = splitnum(in_string, split_char="}") output += temp_first + "}" in_string = temp_last elif in_string[0] == "/": output += "/" + in_string[1] i += 1 in_string = in_string[2:] elif in_string[0] in string.printable: output += in_string[0] i += 1 in_string = in_string[1:] else: output += in_string[0] in_string = in_string[1:] if int(i) > int(columns): output += " " * int(indent) i = 1 if line == 0: columns = int(columns) - int(indent) line += 1 if len(in_string) < 1: running = False return output
def split_line(in_string=""): """ Splits line into an alternating string/list format, string for text and list for attributes to be used/parsed.""" split_line = [] while len(in_string) > 0: if in_string[0] == "/": if in_string[1] == "{": # attributes attribute_line, in_string = splitnum(in_string, split_char="}") attributes = attribute_line[2:].split(",") attributes_split = [] for attribute in attributes: if ":" in attribute: attribute = attribute.split(":") attributes_split.append(attribute) split_line.append(attributes_split) split_line.append("") else: split_line[-1] += in_string[0:2] in_string = in_string[2:] else: split_line[-1] += in_string[0] in_string = in_string[1:] return split_line