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)
[![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

View File

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

View File

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

View File

@@ -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 = (

View File

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

View File

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

View File

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

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