Rework: Rework memes and audio

This commit is contained in:
Marco Thomas
2021-05-24 14:10:31 +02:00
parent b506fba338
commit d58f901cda
7 changed files with 85 additions and 73 deletions

View File

@@ -1,41 +1,46 @@
"""
Send spicy memes to chat
Send memes to chat
"""
import discord
from discord.ext import commands
import discord
import random
import memes
class Meme(commands.Cog):
def __init__(self, bot):
self.bot = bot
@staticmethod
def parse(query):
"""
Parse a request
"""
try:
to_choose = memes.memes[query.capitalize()]
return random.choice(to_choose)
except KeyError:
return None
@commands.command(name="meme")
async def meme(self, ctx, meme: str):
async def meme(self, ctx, query: str):
"""
Sends a spicy meme to the chat
Sends a meme
- marc
- cenk
- olli
"""
query = meme.capitalize()
if query == "List":
meme_list = ""
for key in memes.__memes_list__.keys():
if not meme_list:
meme_list = meme_list + key
else:
meme_list = meme_list + ", " + key
await ctx.send(f"Currently listed memes: `{meme_list}`")
meme = self.parse(query)
if meme:
await ctx.send(meme)
else:
try:
meme = random.choice(memes.__memes_list__[query])
await ctx.send(meme)
except KeyError as e:
await ctx.send("Meme not found in database")
await ctx.send(f"Meme '{query}' not found")
def setup(bot):
bot.add_cog(Meme(bot))
q