discord_checkin_bot/checkin_bot.py

48 lines
1.5 KiB
Python
Raw Normal View History

2021-12-29 02:04:44 +01:00
import os
from discord.ext import commands
from checkin_db import CheckinDB
checkin_db = CheckinDB("checkin.db")
bot = commands.Bot(command_prefix="!")
@bot.command()
async def checkin(context: commands.Context) -> None:
2021-12-29 02:12:33 +01:00
print(f"{context.message.author.display_name} checked in")
2021-12-29 02:04:44 +01:00
checkin_db.auto_checkout()
checkin_db.update(context.message.author.display_name, True)
count = checkin_db.get_checkin_count()
if count == 1:
await context.send(f"Aktuell {count} Mensch im Erfindergeist")
else:
await context.send(f"Aktuell {count} Menschen im Erfindergeist")
@bot.command()
async def checkout(context: commands.Context) -> None:
2021-12-29 02:12:33 +01:00
print(f"{context.message.author.display_name} checked out")
2021-12-29 02:04:44 +01:00
checkin_db.update(context.message.author.display_name, False)
count = checkin_db.get_checkin_count()
if count == 1:
await context.send(f"Aktuell {count} Mensch im Erfindergeist")
else:
await context.send(f"Aktuell {count} Menschen im Erfindergeist")
@bot.command()
async def checkin_list(context: commands.Context) -> None:
2021-12-30 00:21:54 +01:00
checkin_db.auto_checkout()
2021-12-29 02:04:44 +01:00
count = checkin_db.get_checkin_count()
if count == 1:
await context.send(
f"Aktuell {checkin_db.get_checkin_count()} Mensch im Erfindergeist: {', '.join(checkin_db.get_checkin_names())}"
)
else:
await context.send(
f"Aktuell {checkin_db.get_checkin_count()} Menschen im Erfindergeist: {', '.join(checkin_db.get_checkin_names())}"
)
bot.run(os.getenv("DISCORD_KEY"))