diff --git a/.env.example b/.env.example index c55f009..f33c046 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ BOT_TOKEN="" BOT_DEV_TOKEN="" +OWNER_ID="" TESTING="true" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 574e9c7..6331480 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-slim +FROM python:3.10-slim LABEL Maintainer="Klaas Schoute" WORKDIR /usr/src/bot diff --git a/config.py b/config.py new file mode 100644 index 0000000..87953fb --- /dev/null +++ b/config.py @@ -0,0 +1,12 @@ +import os +from dotenv import load_dotenv + +load_dotenv() + +# Bot setup +VERSION = "0.2.0" +TESTING = os.getenv("TESTING", "false") +PREFIX = "!" +BOT_TOKEN = os.getenv("BOT_TOKEN", "") +BOT_DEV_TOKEN = os.getenv("BOT_DEV_TOKEN", "") +OWNER_ID = int(os.getenv("OWNER_ID")) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 86a284c..4004061 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,5 +8,6 @@ services: dockerfile: Dockerfile container_name: DDS-Bot-Dev environment: - TOKEN: ${BOT_DEV_TOKEN} + BOT_TOKEN: ${BOT_DEV_TOKEN} + OWNER_ID: ${OWNER_ID} restart: unless-stopped \ No newline at end of file diff --git a/main.py b/main.py index 61bd69b..093d34d 100644 --- a/main.py +++ b/main.py @@ -1,86 +1,57 @@ import discord import os +import config from discord.ext import commands -from dotenv import load_dotenv -import modules.quote as quote - -VERSION = "0.2.0" - -# load_dotenv reads from a file called .env in the same directory as the python files which should roughly look like BOT_TOKEN="1234567890" -load_dotenv() - -intents = discord.Intents.default() -intents.message_content = True -bot = commands.Bot(command_prefix="!", intents=intents) - -@bot.event -async def on_ready(): - print("--- Bot is online and ready to interact! ---") - print(f'Logged in as {bot.user} (ID: {bot.user.id})') - -@bot.command() -async def inspire(ctx): - """ - command: !inspire - Get a inspiration quote - """ - inspire = quote.get_quote() - await ctx.reply(inspire) - -@bot.command(name="hallo") -async def hello(ctx): - """ - command: !hallo - Say hello to the users - """ - await ctx.send('Hee hallo! Welkom op de server') - -@bot.command(name="vliegavond") -async def trainings(ctx): - """ - command: !vliegavond - """ - await ctx.send('Een lijst van de aankomende vliegdata is te vinden op: https://dutchdronesquad.nl/trainingen en hier vind je ook uitleg, hoe je kan aanmelden voor een vliegavond.') - -@bot.command() -async def track(ctx): - """ - command: !track - """ - await ctx.send('Informatie over de huidige racetrack kan je vinden op: https://dutchdronesquad.nl/racetrack, of verken de track alvast in Velocidrone.') - -@bot.command() -@commands.has_permissions(administrator=True) -async def version(ctx): - """ - command: !version - admin only - """ - await ctx.send(f'Versie: {VERSION}') - -@bot.event -async def on_message(message: discord.Message): - username = str(message.author).split('#')[0] - user_message = str(message.content) - channel = str(message.channel.name) - print(f'{username} in #{channel}: {user_message}') - - if message.author == bot.user: - return - - # msg = message.content - - # if any(word in msg for word in sad_words): - # await message.reply(random.choice(happy_response)) - - # Leave this here, otherwise commands wil stop running - await bot.process_commands(message) +def main(): + intents = discord.Intents.default() + intents.message_content = True + + activity = discord.Activity( + type=discord.ActivityType.watching, name="de DDS server" + ) + + bot = commands.Bot( + command_prefix=commands.when_mentioned_or(config.PREFIX), + intents=intents, + activity=activity, + owner_id=config.OWNER_ID, + ) + + @bot.event + async def on_ready(): + print("--- Bot is online and ready to interact! ---") + print(f'{bot.user.name} has connected to Discord (ID: {bot.user.id})') + + @bot.event + async def on_message(message: discord.Message): + username = str(message.author).split('#')[0] + user_message = str(message.content) + channel = str(message.channel.name) + print(f'{username} in #{channel}: {user_message}') + + if message.author == bot.user: + return + + # msg = message.content + + # if any(word in msg for word in sad_words): + # await message.reply(random.choice(happy_response)) + + # Leave this here, otherwise commands wil stop running + await bot.process_commands(message) + + # Load all modules + for folder in os.listdir('modules'): + bot.load_extension(f'modules.{folder}') + + # Run the bot + if config.TESTING == "true": + bot.run(config.BOT_DEV_TOKEN) + else: + bot.run(config.BOT_TOKEN) # Run the bot if __name__ == "__main__": - if os.getenv('TESTING') == "true": - bot.run(os.getenv('BOT_DEV_TOKEN')) - else: - bot.run(os.getenv('BOT_TOKEN')) \ No newline at end of file + main() \ No newline at end of file diff --git a/modules/__init__.py b/modules/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/modules/racing/__init__.py b/modules/racing/__init__.py new file mode 100644 index 0000000..ff5b7a1 --- /dev/null +++ b/modules/racing/__init__.py @@ -0,0 +1,22 @@ +from discord.ext import commands + +class Racing(commands.Cog, name="Racing"): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="vliegavond") + async def trainings(self, ctx: commands.Context): + """ + command: !vliegavond + """ + await ctx.send('Een lijst van de aankomende vliegdata is te vinden op: https://dutchdronesquad.nl/trainingen en hier vind je ook uitleg, hoe je kan aanmelden voor een vliegavond.') + + @commands.command(name="track") + async def track(self, ctx: commands.Context): + """ + command: !track + """ + await ctx.send('Informatie over de huidige racetrack kan je vinden op: https://dutchdronesquad.nl/racetrack, of verken de track alvast in Velocidrone.') + +def setup(bot: commands.Bot): + bot.add_cog(Racing(bot)) \ No newline at end of file diff --git a/modules/system/__init__.py b/modules/system/__init__.py new file mode 100644 index 0000000..d6a701c --- /dev/null +++ b/modules/system/__init__.py @@ -0,0 +1,37 @@ +import config + +from discord.ext import commands +from .quote import get_quote + +class System(commands.Cog, name="System"): + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="hallo") + async def hello(self, ctx: commands.Context): + """ + command: !hallo + Say hello to the users + """ + await ctx.send('Hee hallo! Welkom op de server') + + @commands.command(name="version") + @commands.has_permissions(administrator=True) + async def version(self, ctx: commands.Context): + """ + command: !version + admin only + """ + await ctx.send(f'Versie: {config.VERSION}') + + @commands.command(name="inspire") + async def inspire(self, ctx: commands.Context): + """ + command: !inspire + Get a inspiration quote + """ + inspire = get_quote() + await ctx.reply(inspire) + +def setup(bot: commands.Bot): + bot.add_cog(System(bot)) \ No newline at end of file diff --git a/modules/quote.py b/modules/system/quote.py similarity index 100% rename from modules/quote.py rename to modules/system/quote.py diff --git a/production.example.yml b/production.example.yml index 6643eec..4617a7a 100644 --- a/production.example.yml +++ b/production.example.yml @@ -5,9 +5,11 @@ services: discord-bot: image: "ghcr.io/dutchdronesquad/dds-bot:latest" environment: - TOKEN: "" + BOT_TOKEN: "" + OWNER_ID: "" deploy: mode: replicated replicas: 1 restart_policy: - condition: on-failure \ No newline at end of file + condition: on-failure + delay: 1m \ No newline at end of file