From 95eac5b98c85a027b5b07a6c43c36a298eb9929f Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Wed, 26 Aug 2020 16:21:33 +0200 Subject: [PATCH] Some general cleanup --- README.md | 3 +-- aquabot.py | 12 ++++++++++-- cogs/admin.py | 2 +- cogs/anime.py | 18 ++++++++++-------- cogs/general.py | 1 - cogs/meme.py | 6 +++--- loadconfig.py | 6 +----- loadmedia.py | 11 +++++++++++ 8 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 loadmedia.py diff --git a/README.md b/README.md index 8e4c3f6..f604173 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ AquaBot ======= [![discordpy](https://img.shields.io/badge/discordpy-Core-blue)](https://github.com/Rapptz/discord.py) -[![Discord Server](https://img.shields.io/badge/Support-Discord%20Server-blue.svg)](https://discordapp.com/invite/HbYfyJT) This bot is my first personal project so expect some minor (or bigger) problems here and there. @@ -20,7 +19,7 @@ Installation - pip + Activate the virtual environment (e.g. with `source virtual/bin/activate`) -+ Use `pip install -r requirements.txt` to install all dependencies ++ Use `pip3 install -r requirements.txt` to install all dependencies needed for the bot + Create a `config` file as described below diff --git a/aquabot.py b/aquabot.py index 4148f40..68fb606 100644 --- a/aquabot.py +++ b/aquabot.py @@ -1,4 +1,12 @@ """ + ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ + █ █ █ █ █ █ █ ▄ █ █ █ + █ ▄ █ ▄ █ █ █ █ ▄ █ █▄█ █ ▄ █▄ ▄█ + █ █▄█ █ █ █ █ █▄█ █ █▄█ █ █ █ █ █ █ █ + █ █ █▄█ █ █ █ ▄ ██ █▄█ █ █ █ + █ ▄ █ ██ █ ▄ █ █▄█ █ █ █ █ + █▄▄█ █▄▄█▄▄▄▄██▄█▄▄▄▄▄▄▄█▄▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ █▄▄▄█ + AquaBot created by Marc. This project uses discordpy: @@ -19,7 +27,7 @@ import loadconfig # LOGGING logger = logging.getLogger("discord") -# https://docs.python.org/3/library/logging.html#levels + logger.setLevel(logging.INFO) handler = logging.FileHandler( filename="logs/discord.log", @@ -29,7 +37,7 @@ handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) -# INIT THE BOT +# INIT bot = commands.Bot( command_prefix=loadconfig.__prefix__, description="Holy Goddess Aqua!") diff --git a/cogs/admin.py b/cogs/admin.py index 0027546..f526a37 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -36,7 +36,7 @@ class Admin(commands.Cog): @commands.is_owner() async def unload(self, ctx, *, cog: str): """ - Used as 'unload cogs.COGNAME' + Used as 'unload cogs.COGNAME' """ try: self.bot.unload_extension(cog) diff --git a/cogs/anime.py b/cogs/anime.py index 1cbc4d2..9f175c3 100644 --- a/cogs/anime.py +++ b/cogs/anime.py @@ -1,5 +1,7 @@ """ Some anime-related commands: + - animepic + - waifupic https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html @@ -11,7 +13,7 @@ from discord.ext import commands import random # IMPORTS - internal -import loadconfig +import loadmedia # COG INIT class Anime(commands.Cog): @@ -19,18 +21,18 @@ class Anime(commands.Cog): self.bot = bot # COG BODY - @commands.command(name="animemedia") + @commands.command(name="animepic") async def animemedia(self, ctx): """ Sends a random Anime gif or picture """ - # Choose either a gif or a pic -> config/media.py - media_type = random.choice(loadconfig.__media_anime__) + + media_type = random.choice(loadmedia.__media_anime__) media = random.choice(media_type) await ctx.send(media) - @commands.command(name="animegirl", aliases=["waifu"]) - async def girlmedia(self, ctx, name: str): + @commands.command(name="waifupic") + async def waifumedia(self, ctx, name: str): """ Sends a random picture or gif of an Anime girl """ @@ -38,7 +40,7 @@ class Anime(commands.Cog): if girl == "List": girl_list = "" - for key in loadconfig.__media_girl__.keys(): + for key in loadmedia.__media_girl__.keys(): if not girl_list: girl_list = girl_list + key else: @@ -48,7 +50,7 @@ class Anime(commands.Cog): else: try: - media = random.choice(loadconfig.__media_girl__[girl]) + media = random.choice(loadmedia.__media_girl__[girl]) await ctx.send(media) except KeyError as error: text = ( diff --git a/cogs/general.py b/cogs/general.py index bb729af..11b2a3e 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -1,6 +1,5 @@ """ Some general commands: - - about https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html """ diff --git a/cogs/meme.py b/cogs/meme.py index 480fb68..cf0d562 100644 --- a/cogs/meme.py +++ b/cogs/meme.py @@ -10,7 +10,7 @@ from discord.ext import commands import random # IMPORTS - internal -import loadconfig +import loadmedia class MemeError(Exception): pass @@ -30,7 +30,7 @@ class Meme(commands.Cog): if query == "List": meme_list = "" - for key in loadconfig.__memes_list__.keys(): + for key in loadmedia.__memes_list__.keys(): if not meme_list: meme_list = meme_list + key else: @@ -39,7 +39,7 @@ class Meme(commands.Cog): await ctx.send(f"Currently listed memes: `{meme_list}`") else: try: - meme = random.choice(loadconfig.__memes_list__[query]) + meme = random.choice(loadmedia.__memes_list__[query]) await ctx.send(meme) except KeyError as e: await ctx.send("Meme not found in database") diff --git a/loadconfig.py b/loadconfig.py index 73fc1d0..0595b1a 100644 --- a/loadconfig.py +++ b/loadconfig.py @@ -2,7 +2,6 @@ Gather all config data into one file, so all other files can call it from here -loadconfig.py then gets called in aquabot.py """ # IMPORTS @@ -23,11 +22,8 @@ except yaml.YAMLError as error: except FileNotFoundError as error: print(f"Error, please create a config file: {error}") -# Import from *.py in config/ and data/ +# Load cogs activated from the start try: from config.cogs import __cogs__ - - from data.media import __media_anime__, __media_girl__ - from data.memes import __memes_list__ except ImportError as error: print(f"Error while importing: {error}") diff --git a/loadmedia.py b/loadmedia.py new file mode 100644 index 0000000..1980f8d --- /dev/null +++ b/loadmedia.py @@ -0,0 +1,11 @@ +""" +Gather all media data into one file, +so all other files can call it from here + +""" + +try: + from data.media import __media_anime__, __media_girl__ + from data.memes import __memes_list__ +except ImportError as error: + print(f"Error while importing: {error}")