Some general cleanup

This commit is contained in:
Marco Thomas
2020-08-26 16:21:33 +02:00
parent 983a88c2d3
commit 95eac5b98c
8 changed files with 37 additions and 22 deletions

View File

@@ -4,7 +4,6 @@ AquaBot
======= =======
[![discordpy](https://img.shields.io/badge/discordpy-Core-blue)](https://github.com/Rapptz/discord.py) [![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 This bot is my first personal project so expect some minor (or bigger) problems
here and there. here and there.
@@ -20,7 +19,7 @@ Installation - pip
+ Activate the virtual environment (e.g. with `source virtual/bin/activate`) + 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 needed for the bot
+ Create a `config` file as described below + Create a `config` file as described below

View File

@@ -1,4 +1,12 @@
""" """
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄
█ █ █ █ █ █ █ ▄ █ █ █
█ ▄ █ ▄ █ █ █ █ ▄ █ █▄█ █ ▄ █▄ ▄█
█ █▄█ █ █ █ █ █▄█ █ █▄█ █ █ █ █ █ █ █
█ █ █▄█ █ █ █ ▄ ██ █▄█ █ █ █
█ ▄ █ ██ █ ▄ █ █▄█ █ █ █ █
█▄▄█ █▄▄█▄▄▄▄██▄█▄▄▄▄▄▄▄█▄▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ █▄▄▄█
AquaBot created by Marc. AquaBot created by Marc.
This project uses discordpy: This project uses discordpy:
@@ -19,7 +27,7 @@ import loadconfig
# LOGGING # LOGGING
logger = logging.getLogger("discord") logger = logging.getLogger("discord")
# https://docs.python.org/3/library/logging.html#levels
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = logging.FileHandler( handler = logging.FileHandler(
filename="logs/discord.log", filename="logs/discord.log",
@@ -29,7 +37,7 @@ handler.setFormatter(
logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
logger.addHandler(handler) logger.addHandler(handler)
# INIT THE BOT # INIT
bot = commands.Bot( bot = commands.Bot(
command_prefix=loadconfig.__prefix__, command_prefix=loadconfig.__prefix__,
description="Holy Goddess Aqua!") description="Holy Goddess Aqua!")

View File

@@ -1,5 +1,7 @@
""" """
Some anime-related commands: Some anime-related commands:
- animepic
- waifupic
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
@@ -11,7 +13,7 @@ from discord.ext import commands
import random import random
# IMPORTS - internal # IMPORTS - internal
import loadconfig import loadmedia
# COG INIT # COG INIT
class Anime(commands.Cog): class Anime(commands.Cog):
@@ -19,18 +21,18 @@ class Anime(commands.Cog):
self.bot = bot self.bot = bot
# COG BODY # COG BODY
@commands.command(name="animemedia") @commands.command(name="animepic")
async def animemedia(self, ctx): async def animemedia(self, ctx):
""" """
Sends a random Anime gif or picture 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) media = random.choice(media_type)
await ctx.send(media) await ctx.send(media)
@commands.command(name="animegirl", aliases=["waifu"]) @commands.command(name="waifupic")
async def girlmedia(self, ctx, name: str): async def waifumedia(self, ctx, name: str):
""" """
Sends a random picture or gif of an Anime girl Sends a random picture or gif of an Anime girl
""" """
@@ -38,7 +40,7 @@ class Anime(commands.Cog):
if girl == "List": if girl == "List":
girl_list = "" girl_list = ""
for key in loadconfig.__media_girl__.keys(): for key in loadmedia.__media_girl__.keys():
if not girl_list: if not girl_list:
girl_list = girl_list + key girl_list = girl_list + key
else: else:
@@ -48,7 +50,7 @@ class Anime(commands.Cog):
else: else:
try: try:
media = random.choice(loadconfig.__media_girl__[girl]) media = random.choice(loadmedia.__media_girl__[girl])
await ctx.send(media) await ctx.send(media)
except KeyError as error: except KeyError as error:
text = ( text = (

View File

@@ -1,6 +1,5 @@
""" """
Some general commands: Some general commands:
- about
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
""" """

View File

@@ -10,7 +10,7 @@ from discord.ext import commands
import random import random
# IMPORTS - internal # IMPORTS - internal
import loadconfig import loadmedia
class MemeError(Exception): class MemeError(Exception):
pass pass
@@ -30,7 +30,7 @@ class Meme(commands.Cog):
if query == "List": if query == "List":
meme_list = "" meme_list = ""
for key in loadconfig.__memes_list__.keys(): for key in loadmedia.__memes_list__.keys():
if not meme_list: if not meme_list:
meme_list = meme_list + key meme_list = meme_list + key
else: else:
@@ -39,7 +39,7 @@ class Meme(commands.Cog):
await ctx.send(f"Currently listed memes: `{meme_list}`") await ctx.send(f"Currently listed memes: `{meme_list}`")
else: else:
try: try:
meme = random.choice(loadconfig.__memes_list__[query]) meme = random.choice(loadmedia.__memes_list__[query])
await ctx.send(meme) await ctx.send(meme)
except KeyError as e: except KeyError as e:
await ctx.send("Meme not found in database") await ctx.send("Meme not found in database")

View File

@@ -2,7 +2,6 @@
Gather all config data into one file, Gather all config data into one file,
so all other files can call it from here so all other files can call it from here
loadconfig.py then gets called in aquabot.py
""" """
# IMPORTS # IMPORTS
@@ -23,11 +22,8 @@ except yaml.YAMLError as error:
except FileNotFoundError as error: except FileNotFoundError as error:
print(f"Error, please create a config file: {error}") print(f"Error, please create a config file: {error}")
# Import from *.py in config/ and data/ # Load cogs activated from the start
try: try:
from config.cogs import __cogs__ from config.cogs import __cogs__
from data.media import __media_anime__, __media_girl__
from data.memes import __memes_list__
except ImportError as error: except ImportError as error:
print(f"Error while importing: {error}") print(f"Error while importing: {error}")

11
loadmedia.py Normal file
View File

@@ -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}")