def wiki_command(arg, packet, shared): ''' The wiki command Usage :w George Washington :wiki Monty Python ''' if len(arg) < 2: return ircp.make_notice('You need to list something to search', packet.sender) query = ' '.join(arg[1:]) print('search query: "{}"'.format(query)) summary = get_summary(query) if summary == '...' or summary is None: return None elif isinstance(summary, tuple) or isinstance(summary, list): output = [] for line in summary: output.append(ircp.make_message(line.strip(), packet.target)) return output else: print('summary: ') print(summary) print('that was the last time!') return ircp.make_message(summary, packet.target)
def handle_incoming(line, shared_data): ''' Handles, and replies to incoming IRC messages line - the line to parse shared_data - the shared_data with literally everything in it ''' config = shared_data['conf'] reply = None # Reset reply msg_packet = ircp.Packet(line) # Determine if prefix is at beginning of message # If it is, then parse for commands if msg_packet.msg_type == 'PRIVMSG': # TODO: Let use know they are being penalized for cooldown reply = handle_commands(msg_packet, shared_data) if reply is None: reply = handle_regexes(msg_packet, shared_data) elif msg_packet.msg_type == 'NUMERIC': if (config['password'] and not config['logged_in'] and msg_packet.numeric == ircp.numerics.RPL_ENDOFMOTD): reply = [] # pylint: disable=redefined-variable-type reply.append(ircp.make_message('identify {} {}'.format(config['bot_nick'], config['password']), 'nickserv')) for channel in config['channels'].split(' '): reply.append(ircp.join_chan(channel)) shared_data['conf']['logged_in'] = True # Stop checking for login numerics elif msg_packet.numeric == ircp.numerics.RPL_ENDOFMOTD: reply = (ircp.join_chan(c) for c in shared_data['conf']['channels'].split(' ')) elif msg_packet.msg_type == 'PING': reply = 'PONG {}'.format(msg_packet.host) elif msg_packet.msg_type == 'NICK': print('{} changed nick to {}'.format(msg_packet.sender, msg_packet.nick_to)) if msg_packet.sender in shared_data['auth']: shared_data['auth'].remove(msg_packet.sender) shared_data['auth'].add(msg_packet.nick_to) print('moved {} to {} on auth list'.format(msg_packet.sender, msg_packet.nick_to)) elif msg_packet.msg_type in ('PART', 'QUIT'): if msg_packet.sender in shared_data['auth']: shared_data['auth'].remove(msg_packet.sender) print('removed {} from auth list'.format(msg_packet.sender)) elif msg_packet.msg_type == 'JOIN': if msg_packet.sender == shared_data['conf']['bot_nick']: shared_data['chan'].add(msg_packet.target) reply = ircp.make_message(shared_data['conf']['intro'], msg_packet.target) if isinstance(reply, int): flag = int(reply) reply = [ircp.make_message('kthxbai', c) for c in shared_data['chan']] reply.append(flag) # Makes sure to close out. shared_data['recent_messages'].append(msg_packet) shared_data['stats']['num_messages'] += 1 return reply
def rekt_command(arg, packet, shared, is_rekt=True): """ Tells a user that they got rekt is_rekt - if True: user is rekt, else: user is not rekt """ person = '' if len(arg) < 2: return ircp.make_notice('You need to specify who got rekt', packet.sender) else: person = ' '.join(arg[1:]) logging.info('reking %s', person) rekt_tuple = shared['rekt.tuple'] checked = '[X] ' unchecked = '[ ] ' random_rekt = sorted(sample(rekt_tuple[2:], 3), key=len) if is_rekt: # Use appropriate checkboxes if using `rekt` or `notrekt` rekts = [unchecked + rekt_tuple[0], checked + rekt_tuple[1], checked + random_rekt[0], checked + random_rekt[1], checked + random_rekt[2]] else: rekts = [checked + rekt_tuple[0], unchecked + rekt_tuple[1], unchecked + random_rekt[0], unchecked + random_rekt[1], unchecked + random_rekt[2]] rekts = [phrase for phrase in rekts] # throttler.add_message() return ircp.make_message(('{0}{1}{2} just got: {3[0]} {3[1]} {3[2]} ' '{3[3]} {3[4]}').format(CLR_NICK, person, CLR_RESET, rekts), packet.target)
def told_command(arg, packet, shared, is_told=True): """ Tells a user that they got told is_told - if True: user is told, else: user is not told """ person = '' if len(arg) < 2: return ircp.make_notice('You need to specify who got told', packet.sender) else: person = ' '.join(arg[1:]) logging.info('telling %s', person) told_tuple = shared['told.tuple'] checked = '[X] ' unchecked = '[ ] ' random_told = sorted(sample(told_tuple[2:], 3), key=len) if is_told: # Use appropriate checkboxes if using `told` or `nottold` tolds = [unchecked + told_tuple[0], checked + told_tuple[1], checked + random_told[0], checked + random_told[1], checked + random_told[2]] else: tolds = [checked + told_tuple[0], unchecked + told_tuple[1], unchecked + random_told[0], unchecked + random_told[1], unchecked + random_told[2]] tolds = [phrase for phrase in tolds] # throttler.add_message() return ircp.make_message(('{0}{1}{2} just got: {3[0]} {3[1]} {3[2]} ' '{3[3]} {3[4]}').format(CLR_NICK, person, CLR_RESET, tolds), packet.target)
def say_command(arg: tuple, packet: ircp.Packet, shared: dict): """ Echoes text than an admin tells the bot to """ if len(arg) < 3: return packet.notice('Usage - {}:say <channel> <message>'.format(CLR_HGLT)) else: target = arg[1] message = packet.text.split(target)[1].lstrip() return (packet.notice('Message sent to {}'.format(target)), ircp.make_message(message, target))
def say_command(arg: tuple, packet: ircp.Packet, shared: dict): """ Echoes text than an admin tells the bot to """ if len(arg) < 3: return packet.notice( 'Usage - {}:say <channel> <message>'.format(CLR_HGLT)) else: target = arg[1] message = packet.text.split(target)[1].lstrip() return (packet.notice('Message sent to {}'.format(target)), ircp.make_message(message, target))
def command(arg: tuple, packet: ircp.Packet, shared: dict): """ Prints out a party boat to the chat """ words = list(arg[1:]) print('words: {}'.format(words)) if len(words) == 0: words = list(DEFAULT_MSG.split(' ')) if len(words) == 1: if len(words[0]) > 5: words.append(words[0][5:]) else: words.append(' ') # CAPSLOCK IS CRUISE CONTROL FOR COOL words = [l.upper() for l in words] # [:5] is used to keep the argument length to five characters # The string '123456' is used to make sure that the zip pairs is at least 5 tuples long zip_pairs = tuple( zip_longest(words[0][:5], words[1][:5], '123456', fillvalue=' ')) message = [] for num, line in enumerate(shared['boat']): boat_line = '' if num != 5: first_letter = zip_pairs[num][0] second_letter = zip_pairs[num][1] if num == 0: # the first line of the boat thing has 3 arguments name = '' # pad name to at least 11 chars if len(packet.sender) <= 11: name = packet.sender + ' ' * ( 11 - len(packet.sender)) + '1,11|' else: name = packet.sender boat_line = line.format(first_letter, second_letter, name) else: boat_line = line.format(first_letter, second_letter) else: # on the sixth line, there is no formatting boat_line = line message.append(ircp.make_message(boat_line, packet.target)) return message
def command(arg: tuple, packet: ircp.Packet, shared: dict): """ Prints out a party boat to the chat """ words = list(arg[1:]) print('words: {}'.format(words)) if len(words) == 0: words = list(DEFAULT_MSG.split(' ')) if len(words) == 1: if len(words[0]) > 5: words.append(words[0][5:]) else: words.append(' ') # CAPSLOCK IS CRUISE CONTROL FOR COOL words = [l.upper() for l in words] # [:5] is used to keep the argument length to five characters # The string '123456' is used to make sure that the zip pairs is at least 5 tuples long zip_pairs = tuple(zip_longest(words[0][:5], words[1][:5], '123456', fillvalue=' ')) message = [] for num, line in enumerate(shared['boat']): boat_line = '' if num != 5: first_letter = zip_pairs[num][0] second_letter = zip_pairs[num][1] if num == 0: # the first line of the boat thing has 3 arguments name = '' # pad name to at least 11 chars if len(packet.sender) <= 11: name = packet.sender + ' ' * (11 - len(packet.sender)) + '1,11|' else: name = packet.sender boat_line = line.format(first_letter, second_letter, name) else: boat_line = line.format(first_letter, second_letter) else: # on the sixth line, there is no formatting boat_line = line message.append(ircp.make_message(boat_line, packet.target)) return message
def rekt_command(arg, packet, shared, is_rekt=True): """ Tells a user that they got rekt is_rekt - if True: user is rekt, else: user is not rekt """ person = '' if len(arg) < 2: return ircp.make_notice('You need to specify who got rekt', packet.sender) else: person = ' '.join(arg[1:]) logging.info('reking %s', person) rekt_tuple = shared['rekt.tuple'] checked = '[X] ' unchecked = '[ ] ' random_rekt = sorted(sample(rekt_tuple[2:], 3), key=len) if is_rekt: # Use appropriate checkboxes if using `rekt` or `notrekt` rekts = [ unchecked + rekt_tuple[0], checked + rekt_tuple[1], checked + random_rekt[0], checked + random_rekt[1], checked + random_rekt[2] ] else: rekts = [ checked + rekt_tuple[0], unchecked + rekt_tuple[1], unchecked + random_rekt[0], unchecked + random_rekt[1], unchecked + random_rekt[2] ] rekts = [phrase for phrase in rekts] # throttler.add_message() return ircp.make_message(('{0}{1}{2} just got: {3[0]} {3[1]} {3[2]} ' '{3[3]} {3[4]}').format(CLR_NICK, person, CLR_RESET, rekts), packet.target)
def handle_incoming(line, shared_data): ''' Handles, and replies to incoming IRC messages line - the line to parse shared_data - the shared_data with literally everything in it ''' config = shared_data['conf'] reply = None # Reset reply msg_packet = ircp.Packet(line) # Determine if prefix is at beginning of message # If it is, then parse for commands if msg_packet.msg_type == 'PRIVMSG': # TODO: Let use know they are being penalized for cooldown reply = handle_commands(msg_packet, shared_data) if reply is None: reply = handle_regexes(msg_packet, shared_data) elif msg_packet.msg_type == 'NUMERIC': if (config['password'] and not config['logged_in'] and msg_packet.numeric == ircp.numerics.RPL_ENDOFMOTD): reply = [] # pylint: disable=redefined-variable-type reply.append( ircp.make_message( 'identify {} {}'.format(config['bot_nick'], config['password']), 'nickserv')) for channel in config['channels'].split(' '): reply.append(ircp.join_chan(channel)) shared_data['conf'][ 'logged_in'] = True # Stop checking for login numerics elif msg_packet.numeric == ircp.numerics.RPL_ENDOFMOTD: reply = (ircp.join_chan(c) for c in shared_data['conf']['channels'].split(' ')) elif msg_packet.msg_type == 'PING': reply = 'PONG {}'.format(msg_packet.host) elif msg_packet.msg_type == 'NICK': print('{} changed nick to {}'.format(msg_packet.sender, msg_packet.nick_to)) if msg_packet.sender in shared_data['auth']: shared_data['auth'].remove(msg_packet.sender) shared_data['auth'].add(msg_packet.nick_to) print('moved {} to {} on auth list'.format(msg_packet.sender, msg_packet.nick_to)) elif msg_packet.msg_type in ('PART', 'QUIT'): if msg_packet.sender in shared_data['auth']: shared_data['auth'].remove(msg_packet.sender) print('removed {} from auth list'.format(msg_packet.sender)) elif msg_packet.msg_type == 'JOIN': if msg_packet.sender == shared_data['conf']['bot_nick']: shared_data['chan'].add(msg_packet.target) reply = ircp.make_message(shared_data['conf']['intro'], msg_packet.target) if isinstance(reply, int): flag = int(reply) reply = [ircp.make_message('kthxbai', c) for c in shared_data['chan']] reply.append(flag) # Makes sure to close out. shared_data['recent_messages'].append(msg_packet) shared_data['stats']['num_messages'] += 1 return reply