-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor the application code * Bump to Python 3.10 * Fix issues with running in docker containers * Set activity on start
- Loading branch information
1 parent
c1aeff3
commit 7119ef8
Showing
10 changed files
with
128 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
BOT_TOKEN="" | ||
BOT_DEV_TOKEN="" | ||
OWNER_ID="" | ||
TESTING="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.9-slim | ||
FROM python:3.10-slim | ||
LABEL Maintainer="Klaas Schoute" | ||
|
||
WORKDIR /usr/src/bot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters