This commit is contained in:
2026-04-06 13:30:19 +02:00
commit ca012cf823
3 changed files with 201 additions and 0 deletions

96
main.py Normal file
View File

@@ -0,0 +1,96 @@
import discord
import os
from discord.ext import tasks, commands
from dotenv import load_dotenv
from dom5game import Dom5game
from servermanager import create_server
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="!", intents=intents)
load_dotenv()
TOKEN = os.getenv("TOKEN")
bot.tracked_games = []
def reload_games():
bot.tracked_games = []
for _, _, files in os.walk("games"):
for name in files:
if name.endswith("json"):
bot.tracked_games.append(
Dom5game.load_json("games/" + name[:-5] + "/" + name)
)
create_server("Amogus", 7777, 831955362646851617)
reload_games()
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
await bot.load_extension("cogs.slash_commands")
# await bot.tree.sync()
reload_games()
task_loop.start()
@tasks.loop(seconds=2)
async def task_loop():
await bot.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name=str(len(bot.tracked_games)) + " Servers.",
)
)
for game in bot.tracked_games:
channel = bot.get_channel(game.channelId)
# handle turn ticks
if game.get_turn() != game.turn and game.get_turn().isdigit():
game.update_turn()
pingstr = ""
if game.members:
pingstr += "-# "
for member in game.members:
pingstr += "<@" + str(member) + "> "
await channel.send(
'Game **"'
+ game.name
+ '"** has advanced to turn '
+ game.turn
+ " \n"
+ pingstr
)
game.to_json()
# handle uploaded turns
turns = game.get_new_turns()
if turns != {}:
for key in turns:
value = turns[key]
if value == "Turn played":
await channel.send(
'Game **"'
+ game.name
+ '"**: '
+ key
+ " has played their turn."
)
if value == "Eliminated":
await channel.send(
'Game **"' + game.name + '"**: ' + key + " has been eliminated."
)
if value == "Turn unfinished":
await channel.send(
'Game **"'
+ game.name
+ '"**: '
+ key
+ " has marked their turn as unfinished."
)
game.update_players()
game.to_json()
bot.run(TOKEN)