From 4a5933729b3e00d2f37069115796225de8330de1 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Thu, 8 Oct 2020 10:05:58 +0200 Subject: [PATCH] Some small improvements --- README.md | 10 ++++++++-- aquabot.py | 21 ++++++++------------- cog_framework.py | 10 ++++------ cogs/admin.py | 7 ++----- cogs/anime.py | 9 +++------ cogs/help.py | 8 ++------ cogs/meme.py | 9 ++------- cogs/music.py | 15 ++++++++++----- cogs/reddit.py | 9 +++------ cogs/reminder.py | 7 ++----- cogs/utility.py | 7 ++----- cogs/welcome.py | 7 ++----- 12 files changed, 48 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index a30a2c7..2886ca3 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,14 @@ AquaBot This Bot was created with the intention to be used on my own server. -## docker-compose -TODO +## docker + +Create a docker image with tag 'latest' +`docker build . -t aquabot` + +In the correct path, create a docker-compose.yml and start the bot +The required env vars are found in 'aquabot.py' +`docker-compose up -d` ## Commands diff --git a/aquabot.py b/aquabot.py index e0318dd..3e587b7 100644 --- a/aquabot.py +++ b/aquabot.py @@ -13,18 +13,13 @@ This project uses discordpy: https://discordpy.readthedocs.io/en/latest/intro.html """ -# IMPORTS - external import discord from discord.ext import commands import logging -from datetime import datetime import platform -import random -import asyncio -import sys import os -# SET VARS + PREFIX = os.environ['PREFIX'] TOKEN = os.environ['TOKEN'] REDDIT_CLIENT_ID = os.environ['REDDIT_CLIENT_ID'] @@ -33,9 +28,7 @@ REDDIT_CLIENT_USERAGENT = os.environ['REDDIT_CLIENT_USERAGENT'] AVATAR = "https://i.redd.it/0uajctrps9u41.jpg" -# LOGGING logger = logging.getLogger("discord") - logger.setLevel(logging.INFO) handler = logging.FileHandler( filename="logs/discord.log", @@ -45,12 +38,13 @@ handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) -# INIT + bot = commands.Bot( command_prefix=PREFIX, description="Holy Goddess Aqua!") -# LOAD COGS + +########## Load Cogs cogs = [ "cogs.admin", "cogs.anime", @@ -70,7 +64,8 @@ for cog in cogs: else: print(f"SUCCESS: Loaded {cog}") -# BOT STARTING EVENT + +########## Start Bot @bot.event async def on_ready(): """ @@ -92,9 +87,9 @@ async def on_ready(): activity = discord.Activity(name=name, type=discord.ActivityType.playing) await bot.change_presence(activity=activity) - print(f"AquaBot is ready!\n") + print("AquaBot is ready!\n") + -# START BOT bot.run( TOKEN, bot=True, diff --git a/cog_framework.py b/cog_framework.py index ba202b7..01c0bb5 100644 --- a/cog_framework.py +++ b/cog_framework.py @@ -1,18 +1,16 @@ """ -This framework can be used to create new Cogs, remember to add them in the config """ -# IMPORTS -import discord + from discord.ext import commands -# COG INIT + class Foo(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY -# COG ENDING + + def setup(bot): bot.add_cog(Foo(bot)) diff --git a/cogs/admin.py b/cogs/admin.py index 083b681..517e86a 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -2,16 +2,14 @@ Admin commands, that can be used from within the discord-client-chat """ -# IMPORTS -import discord from discord.ext import commands -# COG INIT + class Admin(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.command(name="load", hidden=True) @commands.is_owner() async def load(self, ctx, *, cog: str): @@ -55,6 +53,5 @@ class Admin(commands.Cog): await ctx.send('**`SUCCESS`**') -# COG ENDING def setup(bot): bot.add_cog(Admin(bot)) diff --git a/cogs/anime.py b/cogs/anime.py index 6a32f16..3cf5991 100644 --- a/cogs/anime.py +++ b/cogs/anime.py @@ -2,20 +2,17 @@ Some anime-related commands """ -# IMPORTS - external -import discord from discord.ext import commands import random -# IMPORTS - internal import loaddata -# COG INIT + class Anime(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.command(name="animepic") async def animemedia(self, ctx): """ @@ -26,6 +23,7 @@ class Anime(commands.Cog): media = random.choice(media_type) await ctx.send(media) + @commands.command(name="waifupic") async def waifumedia(self, ctx, name: str): """ @@ -54,6 +52,5 @@ class Anime(commands.Cog): await ctx.send(text) -# COG ENDING def setup(bot): bot.add_cog(Anime(bot)) diff --git a/cogs/help.py b/cogs/help.py index cc592e9..214ac54 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -2,19 +2,16 @@ Some help for the users """ -# IMPORTS - external -import discord from discord.ext import commands -# IMPORTS - internal from __main__ import PREFIX -# COG INIT + class Help(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.command(name="aquabot") async def aquabot(self, ctx): """ @@ -33,6 +30,5 @@ class Help(commands.Cog): await ctx.send(embed=embed) -# COG ENDING def setup(bot): bot.add_cog(Help(bot)) diff --git a/cogs/meme.py b/cogs/meme.py index 14e8e99..1e69c26 100644 --- a/cogs/meme.py +++ b/cogs/meme.py @@ -2,20 +2,17 @@ Send spicy memes to chat """ -# IMPORTS - external -import discord from discord.ext import commands import random -# IMPORTS - internal import memes -# COG INIT + class Meme(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.command(name="meme") async def meme(self, ctx, meme: str): """ @@ -40,7 +37,5 @@ class Meme(commands.Cog): await ctx.send("Meme not found in database") - -# COG ENDING def setup(bot): bot.add_cog(Meme(bot)) diff --git a/cogs/music.py b/cogs/music.py index 9e7b368..86f89e3 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -1,12 +1,10 @@ """ Play Music -A COG NOT WRITTEN BY ME! ALTERED FROM THIS ONE: +A COG ORIGINALLY CREATED BY ME, I ALTERED THIS ONE TO FIT MY NEEDS https://gist.github.com/vbe0201/ade9b80f2d3b64643d854938d40a0a2d """ -# IMPORTS - external -import discord from discord.ext import commands import youtube_dl import functools @@ -16,7 +14,6 @@ import math import random from async_timeout import timeout -# COG BODY class VoiceError(Exception): pass @@ -300,6 +297,7 @@ class Music(commands.Cog): ctx.voice_state.voice = await destination.connect() await ctx.message.add_reaction('🤙') + @commands.command(name="leave", aliases=["dc"]) async def leave(self, ctx: commands.Context): """ @@ -312,6 +310,7 @@ class Music(commands.Cog): del self.voice_states[ctx.guild.id] await ctx.message.add_reaction('👋') + @commands.command(name="now", aliases=["np"]) async def now(self, ctx: commands.Context): """ @@ -319,6 +318,7 @@ class Music(commands.Cog): """ await ctx.send(embed=ctx.voice_state.current.create_embed()) + @commands.command(name='pause') async def pause(self, ctx: commands.Context): """ @@ -328,6 +328,7 @@ class Music(commands.Cog): ctx.voice_state.voice.pause() await ctx.message.add_reaction('⏯') + @commands.command(name='resume') async def resume(self, ctx: commands.Context): """ @@ -337,6 +338,7 @@ class Music(commands.Cog): ctx.voice_state.voice.resume() await ctx.message.add_reaction('⏯') + @commands.command(name="skip") async def skip(self, ctx: commands.Context): """ @@ -348,6 +350,7 @@ class Music(commands.Cog): await ctx.message.add_reaction('⏭') ctx.voice_state.skip() + @commands.command(name="clear") async def clear(self, ctx: commands.Context): """ @@ -356,6 +359,7 @@ class Music(commands.Cog): ctx.voice_state.songs.clear() await ctx.message.add_reaction('⏹') + @commands.command(name='play') async def play(self, ctx: commands.Context, *, search: str): """ @@ -376,6 +380,7 @@ class Music(commands.Cog): await ctx.voice_state.songs.put(song) await ctx.send('Enqueued {}'.format(str(source))) + @join.before_invoke @play.before_invoke async def ensure_voice_state(self, ctx: commands.Context): @@ -423,6 +428,6 @@ class Music(commands.Cog): .set_footer(text='Viewing page {}/{}'.format(page, pages))) await ctx.send(embed=embed) -# COG ENDING + def setup(bot): bot.add_cog(Music(bot)) diff --git a/cogs/reddit.py b/cogs/reddit.py index 38f527b..52b6a08 100644 --- a/cogs/reddit.py +++ b/cogs/reddit.py @@ -2,23 +2,20 @@ 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): """ @@ -37,6 +34,6 @@ class Reddit(commands.Cog): await ctx.send(f"> '{post.title}' by {post.author.name}") await ctx.send(post.url) -# COG ENDING + def setup(bot): bot.add_cog(Reddit(bot)) diff --git a/cogs/reminder.py b/cogs/reminder.py index 4a01fb2..7df79b3 100644 --- a/cogs/reminder.py +++ b/cogs/reminder.py @@ -2,18 +2,15 @@ A simple reminder option """ -# IMPORTS -import discord from discord.ext import commands -# COG INIT + class Reminder(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY -# COG ENDING + def setup(bot): bot.add_cog(Reminder(bot)) diff --git a/cogs/utility.py b/cogs/utility.py index d13453d..71063e5 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -2,17 +2,15 @@ Some (more or less) handy utility """ -# IMPORTS - external -import discord from discord.ext import commands import random -# COG INIT + class Utility(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.command(name="invitelink", aliases=["invite"]) async def invite_link(self, ctx, age=60*10, uses=100): """ @@ -57,6 +55,5 @@ class Utility(commands.Cog): await ctx.send(response) -# COG ENDING def setup(bot): bot.add_cog(Utility(bot)) diff --git a/cogs/welcome.py b/cogs/welcome.py index ad2fef9..9bc0984 100644 --- a/cogs/welcome.py +++ b/cogs/welcome.py @@ -2,16 +2,14 @@ Welcoming new users etc. """ -# IMPORTS -import discord from discord.ext import commands -# COG INIT + class Welcome(commands.Cog): def __init__(self, bot): self.bot = bot -# COG BODY + @commands.Cog.listener() async def on_member_join(self, member): """ @@ -30,6 +28,5 @@ class Welcome(commands.Cog): await ctx.send(f"Hello {ctx.author.mention}!") -# COG ENDING def setup(bot): bot.add_cog(Welcome(bot))