async def summary(message: discord.Message, *options, phrase: Annotate.LowerContent=None): """ Perform a summary! """ # This dict stores all parsed options as keywords member, channel, num = [], None, None for value in options: num_match = valid_num.match(value) if num_match: assert not num num = int(num_match.group("num")) # Assign limits if num > max_summaries: num = max_summaries elif num < 1: num = 1 continue member_match = valid_member.match(value) if member_match: member.append(utils.find_member(message.server, member_match.group())) continue channel_match = valid_channel.match(value) if channel_match: assert not channel channel = utils.find_channel(message.server, channel_match.group()) assert channel.permissions_for(message.server.me).read_message_history, "**I can't see this channel.**" continue # Assign defaults if not num: num = 1 if not channel: channel = message.channel await client.send_typing(message.channel) await update_task.wait() await update_messages(channel) # Split the messages into content and filter member and phrase if member: message_content = [m.clean_content for m in stored_messages[channel.id] if m.author in member] else: message_content = [m.clean_content for m in stored_messages[channel.id]] if phrase: message_content = [s for s in message_content if phrase.lower() in s.lower()] # Clean up by removing all commands from the summaries if phrase is None or not phrase.startswith(config.command_prefix): message_content = [s for s in message_content if not s.startswith(config.command_prefix)] # Check if we even have any messages assert message_content, on_no_messages.format(message) # Generate the summary, or num summaries for i in range(num): sentence = markov_messages(message_content) await client.say(message, sentence or on_fail.format(message))
async def remove(message: discord.Message, name: Annotate.LowerContent): """ Remove a pasta with the specified name. """ # We don't even use spaces when removing pastas! parsed_name = name.replace(" ", "") assert parsed_name in pastas.data, "No pasta with name `{}`.".format(name) copypasta = pastas.data.pop(parsed_name) pastas.save() await client.say(message, "Pasta `{}` removed. In case this was a mistake, " "here's the pasta: ```{}```".format(name, copypasta))
async def pasta(message: discord.Message, name: Annotate.LowerContent): """ Use copypastas. Don't forget to enclose the copypasta in quotes: `"pasta goes here"` for multiline pasta action. You also need quotes around `<name>` if it has any spaces. """ # Display a random pasta assert not name == ".", choice(list(pastas.data.values())) # We don't use spaces in pastas at all parsed_name = name.replace(" ", "") # Pasta might not be in the set assert parsed_name in pastas.data, "Pasta `{}` is undefined.\nPerhaps you meant: `{}`?".format( name, ", ".join(get_close_matches(parsed_name, pastas.data.keys(), cutoff=0.5))) # Display the specified pasta await client.say(message, pastas.data[parsed_name])