This commit is contained in:
2022-08-16 21:00:17 +02:00
parent 6a74b32e45
commit ce462433c1
3 changed files with 92 additions and 0 deletions

2
.env Normal file
View File

@@ -0,0 +1,2 @@
TOKEN=<YOUR_DISCORD_TOKEN>
LOGLEVEL=INFO/ERROR

10
Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM python:3
FROM gorialis/discord.py
RUN pip install --upgrade python-dotenv
WORKDIR /usr/src/bot
COPY . .
CMD ["python3", "discord_bot.py"]

80
discord_bot.py Normal file
View File

@@ -0,0 +1,80 @@
import os, discord, aiohttp
from discord.ext import commands
from dotenv import load_dotenv
import logging
load_dotenv()
TOKEN = os.getenv("TOKEN")
LOGLEVEL = os.getenv("LOGLEVEL", "INFO").upper()
log = logging.getLogger("discord")
log.setLevel(LOGLEVEL)
handler = logging.StreamHandler()
handler.setFormatter(
logging.Formatter("%(asctime)s : %(levelname)s : %(name)s : %(message)s")
)
log.addHandler(handler)
async def post_request(session, user, message):
url = "https://schmoekerei.com/mail.php"
async with session.post(
url,
data={
"username": user,
"email": "discord@schmoekerei.com",
"request": f"Anfrage über Discord: {message}",
},
) as response:
data = await response.text()
log.info(f"POST response: {data.splitlines()[0]}")
bot = commands.Bot(
command_prefix=".",
activity=discord.Activity(name=".request", type=discord.ActivityType.listening),
)
@bot.event
async def on_ready():
log.info(f"Bot is ready! Loglevel: {LOGLEVEL}")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.MissingRole):
log.info("Denied {0.author} usage of {0.command}: Missing Role".format(ctx))
await ctx.send(
f"Du brauchst zur Nutzung dieses Befehls die Rolle {error.missing_role}.",
delete_after=10.0,
)
else:
log.info(
f"Command error occurred: User {ctx.author} / {error.__class__.__name__} : {error}"
)
@bot.command()
@commands.has_role("Admin")
async def clear(ctx, amount=1):
"""[Admin] Löscht x Nachrichten"""
log.info("Clearing {0} Messages".format(amount))
await ctx.channel.purge(limit=amount)
@bot.command()
async def request(ctx, *args):
"""Erstellt ein Support-Ticket mit deiner Nachricht."""
if ctx.channel.name in ["requests", "system"]:
if " ".join(args) == "test":
await ctx.message.add_reaction("👍")
else:
async with aiohttp.ClientSession() as session:
await post_request(session, ctx.author, " ".join(args))
await ctx.message.add_reaction("")
bot.run(TOKEN)