Make 'some' changes and add Dockerfile

This commit is contained in:
Marco Thomas
2020-08-31 14:19:43 +02:00
parent 8b54dcf968
commit 6be6e96768
23 changed files with 129 additions and 179 deletions

11
.dockerignore Normal file
View File

@@ -0,0 +1,11 @@
README.md
.git
__pycache__
*.pyc
*.pyo
*.pyd
.Python
logs
*.log
env
venv

4
.gitignore vendored
View File

@@ -9,3 +9,7 @@ __pycache__/
# generated data from logging
logs/
*.log
# venv
env/
venv/

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM python:3.8
WORKDIR /data
COPY . /data
ENV PREFIX
ENV TOKEN
ENV REDDIT_CLIENT_ID
ENV REDDIT_CLIENT_SECRET
ENV REDDIT_CLIENT_USERAGENT
RUN python3 -m pip install -r requirements.txt
CMD python3 aquabot.py --prefix=$PREFIX --token=$TOKEN --reddit_client_id=$REDDIT_CLIENT_ID --reddit_client_secret=$REDDIT_CLIENT_SECRET --reddit_client_useragent=$REDDIT_CLIENT_USERAGENT

View File

@@ -21,9 +21,34 @@ from datetime import datetime
import platform
import random
import asyncio
import sys
import argparse
# IMPORTS - internal
import loadconfig
# SET VARS
parser = argparse.ArgumentParser()
parser.add_argument("--prefix", help="Command Prefix")
parser.add_argument("--token", help="Discord Bot Token")
parser.add_argument("--reddit_client_id", help="Reddit Client ID")
parser.add_argument("--reddit_client_secret", help="Reddit Client Secret")
parser.add_argument("--reddit_client_useragent", help="Reddit Client User-Agent")
args = parser.parse_args()
if args.prefix:
prefix = args.prefix
if args.token:
token = args.token
if args.reddit_client_id:
reddit_client_id = args.reddit_client_id
if args.reddit_client_secret:
reddit_client_secret = args.reddit_client_secret
if args.reddit_client_useragent:
reddit_client_useragent = args.reddit_client_useragent
avatar = "https://i.redd.it/0uajctrps9u41.jpg"
# LOGGING
logger = logging.getLogger("discord")
@@ -39,11 +64,22 @@ logger.addHandler(handler)
# INIT
bot = commands.Bot(
command_prefix=loadconfig.__prefix__,
command_prefix=prefix,
description="Holy Goddess Aqua!")
# LOAD COGS SPECIFIED IN 'config/cogs.py'
for cog in loadconfig.__cogs__:
# LOAD COGS
cogs = [
"cogs.admin",
"cogs.anime",
"cogs.help",
"cogs.meme",
"cogs.music",
"cogs.reddit",
"cogs.utility",
"cogs.welcome"
]
for cog in cogs:
try:
bot.load_extension(cog)
except Exception as e:
@@ -62,14 +98,14 @@ async def on_ready():
startup = f"""
Bot Name: {bot.user.name} - {bot.user.id}\n
Owner: {bot.AppInfo.owner}\n
Command Prefix: {loadconfig.__prefix__}\n
Command Prefix: {prefix}\n
discord.py Version: {discord.__version__}\n
python Version: {platform.python_version()}\n
OS: {platform.system()} {platform.release()} {platform.version()}\n
"""
print(startup)
name = f"with water | {loadconfig.__prefix__}aquabot"
name = f"with water | {prefix}aquabot"
activity = discord.Activity(name=name, type=discord.ActivityType.playing)
await bot.change_presence(activity=activity)
@@ -77,6 +113,6 @@ async def on_ready():
# START BOT
bot.run(
loadconfig.__token__,
token,
bot=True,
reconnect=True)

View File

@@ -1,11 +1,5 @@
"""
Admin commands, that can be used from within the chat:
- load
- unload
- reload
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
https://gist.github.com/EvieePy/d78c061a4798ae81be9825468fe146be
Admin commands, that can be used from within the discord-client-chat
"""
# IMPORTS

View File

@@ -1,10 +1,5 @@
"""
Some anime-related commands:
- animepic
- waifupic
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
Some anime-related commands
"""
# IMPORTS - external

View File

@@ -1,7 +1,5 @@
"""
This framework can be used to create new Cogs, remember to add them in the config
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
"""
# IMPORTS

View File

@@ -1,25 +0,0 @@
"""
Some general commands:
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
"""
# IMPORTS - external
import discord
from discord.ext import commands
import platform
# IMPORTS - internal
import loadconfig
# COG INIT
class General(commands.Cog):
def __init__(self, bot):
self.bot = bot
# COG BODY
# COG ENDING
def setup(bot):
bot.add_cog(General(bot))

View File

@@ -1,8 +1,5 @@
"""
Some help for the users:
- aquabot
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
Some help for the users
"""
# IMPORTS - external
@@ -10,7 +7,7 @@ import discord
from discord.ext import commands
# IMPORTS - internal
import loadconfig
from __main__ import prefix
# COG INIT
class Help(commands.Cog):
@@ -27,7 +24,7 @@ class Help(commands.Cog):
embed.set_thumbnail(url=ctx.me.avatar_url)
embed.add_field(name="Owner", value=self.bot.AppInfo.owner, inline=True)
embed.add_field(name="Command Prefix", value=loadconfig.__prefix__, inline=True)
embed.add_field(name="Command Prefix", value=prefix, inline=True)
embed.add_field(name="Source Code", value="[GitHub](https://github.com/crammk/aquabot)", inline=True)
footer_text = "This Bot is a project by MarcMK."

View File

@@ -1,7 +1,5 @@
"""
Send spicy memes to chat
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
"""
# IMPORTS - external
@@ -12,9 +10,6 @@ import random
# IMPORTS - internal
import loaddata
class MemeError(Exception):
pass
# COG INIT
class Meme(commands.Cog):
def __init__(self, bot):

View File

@@ -1,7 +1,7 @@
"""
Play Music
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
A COG NOT WRITTEN BY ME! ALTERED FROM THIS ONE:
https://gist.github.com/vbe0201/ade9b80f2d3b64643d854938d40a0a2d
"""

41
cogs/reddit.py Normal file
View File

@@ -0,0 +1,41 @@
"""
Fetch pictures from subreddits
"""
# IMPORTS - external
import discord
from discord.ext import commands
import random
import praw
# IMPORTS - internal
from __main__ import reddit_client_id
from __main__ import reddit_client_secret
from __main__ import reddit_client_useragent
# COG INIT
class Reddit(commands.Cog):
def __init__(self, bot):
self.bot = bot
# COG BODY
@commands.command(name="reddit")
async def reddit(self, ctx, sub: str):
"""
Send a post from a subreddit to chat
"""
reddit = praw.Reddit(client_id=reddit_client_id,
client_secret=reddit_client_secret,
user_agent=reddit_client_useragent)
posts = reddit.subreddit(sub).hot()
rand_post = random.randint(1, 100)
# Make sure you're not sending a pinned post
for i in range(0, rand_post):
selected_post = next(x for x in posts if not x.stickied)
await ctx.send(selected_post.url)
# COG ENDING
def setup(bot):
bot.add_cog(Reddit(bot))

View File

@@ -1,7 +1,5 @@
"""
A simple reminder option
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
"""
# IMPORTS

View File

@@ -1,9 +1,5 @@
"""
Some (more or less) handy utility:
- invitelink
- pat
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
Some (more or less) handy utility
"""
# IMPORTS - external
@@ -12,7 +8,7 @@ from discord.ext import commands
import random
# IMPORTS - internal
import loadconfig
from __main__ import avatar
# COG INIT
class Utility(commands.Cog):
@@ -43,7 +39,7 @@ class Utility(commands.Cog):
inline=True)
link_embed.set_footer(
text=f"Age: {age}, Uses: {uses}",
icon_url=loadconfig.__avatar__
icon_url=avatar
)
await ctx.send(embed=link_embed)
@@ -58,8 +54,6 @@ class Utility(commands.Cog):
author = ctx.message.author
if target is None:
response = "No one to pat..."
elif target.capitalize() == "Noel":
response = "NNN-GYAAAA!"
else:
response = f"{target} got pat by {author.mention}"

View File

@@ -1,12 +1,7 @@
"""
Welcoming new users etc.:
- listener: join
- hello
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
Welcoming new users etc.
"""
# IMPORTS
import discord
from discord.ext import commands

View File

View File

@@ -1,16 +0,0 @@
"""
Initally loaded cogs
Don't remove the "admin" cog or you won't be able to load cogs
from the Discord-Client
"""
__cogs__ = [
"cogs.admin",
"cogs.anime",
"cogs.general",
"cogs.help",
"cogs.meme",
"cogs.music",
"cogs.utility",
"cogs.welcome",
]

View File

@@ -1,6 +0,0 @@
---
token: ''
prefix: ''
...

View File

@@ -1,48 +0,0 @@
"""
Media, which can be accessed from the bot.
"""
# Internal lists
gifs_anime = []
pics_anime = [
"https://i.imgur.com/4xnJN9x.png",
]
aqua = []
noel = [
"https://i.imgur.com/qSAjVSL.png",
]
megumin = [
"https://i.imgur.com/mSBfcXA.jpg",
"https://i.imgur.com/Dqua2lX.jpg",
"https://i.imgur.com/1jzaE3y.png",
"https://i.imgur.com/KpGSYD2.png",
]
akeno = []
rem = [
"https://i.imgur.com/8HNv6ow.jpg",
"https://i.imgur.com/GEhYHKi.png",
"https://i.imgur.com/5dtXgEc.jpg",
"https://i.imgur.com/MV3ancf.png",
"https://i.imgur.com/yJCw8MX.jpg",
"https://i.imgur.com/jEGpRn2.jpg",
"https://i.imgur.com/y0DP3wL.jpg",
"https://i.imgur.com/cVNMUgi.jpg",
]
# Exports
__media_anime__ = [gifs_anime, pics_anime]
__media_girl__ = {
"Aqua": aqua,
"Noel": noel,
"Megumin": megumin,
"Akeno": akeno,
"Rem": rem
}

View File

@@ -1,29 +0,0 @@
"""
Gather all config data into one file,
so all other files can call it from here
"""
# IMPORTS
import yaml
__avatar__ = "https://i.redd.it/0uajctrps9u41.jpg"
# Import from yaml
try:
with open("config/config.yml") as file:
config = yaml.safe_load(file)
__token__ = config['token']
__prefix__ = config['prefix']
except yaml.YAMLError as error:
print(f"Error while parsing: {error}")
except FileNotFoundError as error:
print(f"Error, please create a config file: {error}")
# Load cogs activated from the start
try:
from config.cogs import __cogs__
except ImportError as error:
print(f"Error while importing: {error}")

View File

@@ -5,7 +5,6 @@ so all other files can call it from here
"""
try:
from data.media import __media_anime__, __media_girl__
from data.memes import __memes_list__
from memes import __memes_list__
except ImportError as error:
print(f"Error while importing: {error}")

View File

@@ -1,3 +1,5 @@
discord.py[voice]
youtube-dl
pyyaml
praw
argparse