Some small improvements

This commit is contained in:
Marco Thomas
2020-10-08 10:05:58 +02:00
parent 24c416a80b
commit 4a5933729b
12 changed files with 48 additions and 71 deletions

View File

@@ -7,8 +7,14 @@ AquaBot
This Bot was created with the intention to be used on my own server. This Bot was created with the intention to be used on my own server.
## docker-compose ## docker
TODO
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 ## Commands

View File

@@ -13,18 +13,13 @@ This project uses discordpy:
https://discordpy.readthedocs.io/en/latest/intro.html https://discordpy.readthedocs.io/en/latest/intro.html
""" """
# IMPORTS - external
import discord import discord
from discord.ext import commands from discord.ext import commands
import logging import logging
from datetime import datetime
import platform import platform
import random
import asyncio
import sys
import os import os
# SET VARS
PREFIX = os.environ['PREFIX'] PREFIX = os.environ['PREFIX']
TOKEN = os.environ['TOKEN'] TOKEN = os.environ['TOKEN']
REDDIT_CLIENT_ID = os.environ['REDDIT_CLIENT_ID'] 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" AVATAR = "https://i.redd.it/0uajctrps9u41.jpg"
# LOGGING
logger = logging.getLogger("discord") logger = logging.getLogger("discord")
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
handler = logging.FileHandler( handler = logging.FileHandler(
filename="logs/discord.log", filename="logs/discord.log",
@@ -45,12 +38,13 @@ 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
bot = commands.Bot( bot = commands.Bot(
command_prefix=PREFIX, command_prefix=PREFIX,
description="Holy Goddess Aqua!") description="Holy Goddess Aqua!")
# LOAD COGS
########## Load Cogs
cogs = [ cogs = [
"cogs.admin", "cogs.admin",
"cogs.anime", "cogs.anime",
@@ -70,7 +64,8 @@ for cog in cogs:
else: else:
print(f"SUCCESS: Loaded {cog}") print(f"SUCCESS: Loaded {cog}")
# BOT STARTING EVENT
########## Start Bot
@bot.event @bot.event
async def on_ready(): async def on_ready():
""" """
@@ -92,9 +87,9 @@ async def on_ready():
activity = discord.Activity(name=name, type=discord.ActivityType.playing) activity = discord.Activity(name=name, type=discord.ActivityType.playing)
await bot.change_presence(activity=activity) await bot.change_presence(activity=activity)
print(f"AquaBot is ready!\n") print("AquaBot is ready!\n")
# START BOT
bot.run( bot.run(
TOKEN, TOKEN,
bot=True, bot=True,

View File

@@ -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 from discord.ext import commands
# COG INIT
class Foo(commands.Cog): class Foo(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Foo(bot)) bot.add_cog(Foo(bot))

View File

@@ -2,16 +2,14 @@
Admin commands, that can be used from within the discord-client-chat Admin commands, that can be used from within the discord-client-chat
""" """
# IMPORTS
import discord
from discord.ext import commands from discord.ext import commands
# COG INIT
class Admin(commands.Cog): class Admin(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="load", hidden=True) @commands.command(name="load", hidden=True)
@commands.is_owner() @commands.is_owner()
async def load(self, ctx, *, cog: str): async def load(self, ctx, *, cog: str):
@@ -55,6 +53,5 @@ class Admin(commands.Cog):
await ctx.send('**`SUCCESS`**') await ctx.send('**`SUCCESS`**')
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Admin(bot)) bot.add_cog(Admin(bot))

View File

@@ -2,20 +2,17 @@
Some anime-related commands Some anime-related commands
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
import random import random
# IMPORTS - internal
import loaddata import loaddata
# COG INIT
class Anime(commands.Cog): class Anime(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="animepic") @commands.command(name="animepic")
async def animemedia(self, ctx): async def animemedia(self, ctx):
""" """
@@ -26,6 +23,7 @@ class Anime(commands.Cog):
media = random.choice(media_type) media = random.choice(media_type)
await ctx.send(media) await ctx.send(media)
@commands.command(name="waifupic") @commands.command(name="waifupic")
async def waifumedia(self, ctx, name: str): async def waifumedia(self, ctx, name: str):
""" """
@@ -54,6 +52,5 @@ class Anime(commands.Cog):
await ctx.send(text) await ctx.send(text)
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Anime(bot)) bot.add_cog(Anime(bot))

View File

@@ -2,19 +2,16 @@
Some help for the users Some help for the users
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
# IMPORTS - internal
from __main__ import PREFIX from __main__ import PREFIX
# COG INIT
class Help(commands.Cog): class Help(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="aquabot") @commands.command(name="aquabot")
async def aquabot(self, ctx): async def aquabot(self, ctx):
""" """
@@ -33,6 +30,5 @@ class Help(commands.Cog):
await ctx.send(embed=embed) await ctx.send(embed=embed)
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Help(bot)) bot.add_cog(Help(bot))

View File

@@ -2,20 +2,17 @@
Send spicy memes to chat Send spicy memes to chat
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
import random import random
# IMPORTS - internal
import memes import memes
# COG INIT
class Meme(commands.Cog): class Meme(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="meme") @commands.command(name="meme")
async def meme(self, ctx, meme: str): async def meme(self, ctx, meme: str):
""" """
@@ -40,7 +37,5 @@ class Meme(commands.Cog):
await ctx.send("Meme not found in database") await ctx.send("Meme not found in database")
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Meme(bot)) bot.add_cog(Meme(bot))

View File

@@ -1,12 +1,10 @@
""" """
Play Music 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 https://gist.github.com/vbe0201/ade9b80f2d3b64643d854938d40a0a2d
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
import youtube_dl import youtube_dl
import functools import functools
@@ -16,7 +14,6 @@ import math
import random import random
from async_timeout import timeout from async_timeout import timeout
# COG BODY
class VoiceError(Exception): class VoiceError(Exception):
pass pass
@@ -300,6 +297,7 @@ class Music(commands.Cog):
ctx.voice_state.voice = await destination.connect() ctx.voice_state.voice = await destination.connect()
await ctx.message.add_reaction('🤙') await ctx.message.add_reaction('🤙')
@commands.command(name="leave", aliases=["dc"]) @commands.command(name="leave", aliases=["dc"])
async def leave(self, ctx: commands.Context): async def leave(self, ctx: commands.Context):
""" """
@@ -312,6 +310,7 @@ class Music(commands.Cog):
del self.voice_states[ctx.guild.id] del self.voice_states[ctx.guild.id]
await ctx.message.add_reaction('👋') await ctx.message.add_reaction('👋')
@commands.command(name="now", aliases=["np"]) @commands.command(name="now", aliases=["np"])
async def now(self, ctx: commands.Context): 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()) await ctx.send(embed=ctx.voice_state.current.create_embed())
@commands.command(name='pause') @commands.command(name='pause')
async def pause(self, ctx: commands.Context): async def pause(self, ctx: commands.Context):
""" """
@@ -328,6 +328,7 @@ class Music(commands.Cog):
ctx.voice_state.voice.pause() ctx.voice_state.voice.pause()
await ctx.message.add_reaction('') await ctx.message.add_reaction('')
@commands.command(name='resume') @commands.command(name='resume')
async def resume(self, ctx: commands.Context): async def resume(self, ctx: commands.Context):
""" """
@@ -337,6 +338,7 @@ class Music(commands.Cog):
ctx.voice_state.voice.resume() ctx.voice_state.voice.resume()
await ctx.message.add_reaction('') await ctx.message.add_reaction('')
@commands.command(name="skip") @commands.command(name="skip")
async def skip(self, ctx: commands.Context): async def skip(self, ctx: commands.Context):
""" """
@@ -348,6 +350,7 @@ class Music(commands.Cog):
await ctx.message.add_reaction('') await ctx.message.add_reaction('')
ctx.voice_state.skip() ctx.voice_state.skip()
@commands.command(name="clear") @commands.command(name="clear")
async def clear(self, ctx: commands.Context): async def clear(self, ctx: commands.Context):
""" """
@@ -356,6 +359,7 @@ class Music(commands.Cog):
ctx.voice_state.songs.clear() ctx.voice_state.songs.clear()
await ctx.message.add_reaction('') await ctx.message.add_reaction('')
@commands.command(name='play') @commands.command(name='play')
async def play(self, ctx: commands.Context, *, search: str): 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.voice_state.songs.put(song)
await ctx.send('Enqueued {}'.format(str(source))) await ctx.send('Enqueued {}'.format(str(source)))
@join.before_invoke @join.before_invoke
@play.before_invoke @play.before_invoke
async def ensure_voice_state(self, ctx: commands.Context): 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))) .set_footer(text='Viewing page {}/{}'.format(page, pages)))
await ctx.send(embed=embed) await ctx.send(embed=embed)
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Music(bot)) bot.add_cog(Music(bot))

View File

@@ -2,23 +2,20 @@
Fetch pictures from subreddits Fetch pictures from subreddits
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
import random import random
import praw import praw
# IMPORTS - internal
from __main__ import REDDIT_CLIENT_ID from __main__ import REDDIT_CLIENT_ID
from __main__ import REDDIT_CLIENT_SECRET from __main__ import REDDIT_CLIENT_SECRET
from __main__ import REDDIT_CLIENT_USERAGENT from __main__ import REDDIT_CLIENT_USERAGENT
# COG INIT
class Reddit(commands.Cog): class Reddit(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="reddit") @commands.command(name="reddit")
async def reddit(self, ctx, sub: str): 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(f"> '{post.title}' by {post.author.name}")
await ctx.send(post.url) await ctx.send(post.url)
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Reddit(bot)) bot.add_cog(Reddit(bot))

View File

@@ -2,18 +2,15 @@
A simple reminder option A simple reminder option
""" """
# IMPORTS
import discord
from discord.ext import commands from discord.ext import commands
# COG INIT
class Reminder(commands.Cog): class Reminder(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Reminder(bot)) bot.add_cog(Reminder(bot))

View File

@@ -2,17 +2,15 @@
Some (more or less) handy utility Some (more or less) handy utility
""" """
# IMPORTS - external
import discord
from discord.ext import commands from discord.ext import commands
import random import random
# COG INIT
class Utility(commands.Cog): class Utility(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.command(name="invitelink", aliases=["invite"]) @commands.command(name="invitelink", aliases=["invite"])
async def invite_link(self, ctx, age=60*10, uses=100): async def invite_link(self, ctx, age=60*10, uses=100):
""" """
@@ -57,6 +55,5 @@ class Utility(commands.Cog):
await ctx.send(response) await ctx.send(response)
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Utility(bot)) bot.add_cog(Utility(bot))

View File

@@ -2,16 +2,14 @@
Welcoming new users etc. Welcoming new users etc.
""" """
# IMPORTS
import discord
from discord.ext import commands from discord.ext import commands
# COG INIT
class Welcome(commands.Cog): class Welcome(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
# COG BODY
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_join(self, member): async def on_member_join(self, member):
""" """
@@ -30,6 +28,5 @@ class Welcome(commands.Cog):
await ctx.send(f"Hello {ctx.author.mention}!") await ctx.send(f"Hello {ctx.author.mention}!")
# COG ENDING
def setup(bot): def setup(bot):
bot.add_cog(Welcome(bot)) bot.add_cog(Welcome(bot))