Add quote command

This commit is contained in:
2021-01-27 16:01:05 +01:00
parent 510d977cab
commit 2265d979a7

41
bot.py
View File

@@ -3,7 +3,7 @@ import os
import random
import re
import time
from typing import Optional
from typing import Optional, List
import discord
import gtts
@@ -244,6 +244,45 @@ async def flip_pipelin_command(ctx: commands.Context):
await ctx.channel.send("Pipelin " + random.choice(['schnel', 'langsam']))
@bot.command(name='quote', brief='Get a random quote or add new ones')
async def quote_command(ctx: commands.Context, author: Optional[str], *, quote: Optional[str]):
quotes: Optional[dict[str,List[str]]] = config_get("guild_quotes", guild=ctx.guild.id)
if quotes is None:
quotes = {}
config_set("guild_quotes", quotes, ctx.guild.id)
if author is None:
pass
else:
author = author.strip().title()
quote = quote.strip()
if quote:
if author in quotes:
author_quotes: List[str] = quotes[author]
regex = re.compile(r'[\W]')
stripped_quote = regex.sub(quote, '').lower()
for aq in author_quotes:
if regex.sub(aq, '').lower() == stripped_quote:
await ctx.channel.send("Quote already exists!")
return
author_quotes.append(quote)
config_save()
await ctx.channel.send("Quote added")
else:
quotes[author] = [quote]
config_save()
await ctx.channel.send("Quote added")
else:
if author in quotes:
quote = random.choice(quotes[author])
quote = '\n'.join(map(lambda line: '> ' + line, quote.splitlines()))
await ctx.channel.send(quote + '\n**' + author + '**')
else:
await ctx.channel.send("Unknown author!")
def _is_message_valid_for_selection(message: discord.Message, reaction_filter: Optional[str] = None) -> bool:
if message.clean_content.strip() == '':
return False