Compare commits
1 Commits
6803b130f7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 665d21e7bf |
9
LICENSE.md
Normal file
9
LICENSE.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* ------------------------------------------------------------
|
||||||
|
* "THE BEERWARE LICENSE" (Revision 42):
|
||||||
|
* DerGrubengräber / Carl Hinze wrote this code. As long as you retain this
|
||||||
|
* notice, you can do whatever you want with this stuff. If we
|
||||||
|
* meet someday, and you think this stuff is worth it, you can
|
||||||
|
* buy me a beer in return.
|
||||||
|
* ------------------------------------------------------------
|
||||||
|
*/
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from discord.ext import commands
|
|
||||||
import discord
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
|
||||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
||||||
|
|
||||||
bot.tracked_games = []
|
|
||||||
42
main.py
42
main.py
@@ -1,23 +1,19 @@
|
|||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
from discord.ext import tasks
|
from discord.ext import tasks, commands
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from dom5game import Dom5game
|
from dom5game import Dom5game
|
||||||
from servermanager import create_server
|
from servermanager import create_server
|
||||||
from nicegui import ui
|
|
||||||
from webui import create_ui
|
|
||||||
from bot_instance import bot
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
bot_started = False # prolly only need this in dev mode
|
intents = discord.Intents.default()
|
||||||
|
bot = commands.Bot(command_prefix="!", intents=intents)
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
TOKEN = os.getenv("TOKEN")
|
TOKEN = os.getenv("TOKEN")
|
||||||
if not TOKEN:
|
|
||||||
raise ValueError("No token found")
|
bot.tracked_games = []
|
||||||
|
|
||||||
|
|
||||||
def reload_games():
|
def reload_games():
|
||||||
with bot.tracked_games_lock:
|
|
||||||
bot.tracked_games = []
|
bot.tracked_games = []
|
||||||
for _, _, files in os.walk("games"):
|
for _, _, files in os.walk("games"):
|
||||||
for name in files:
|
for name in files:
|
||||||
@@ -27,30 +23,16 @@ def reload_games():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def start_discord_bot():
|
create_server("Amogus", 7777, 831955362646851617)
|
||||||
await bot.load_extension("cogs.slash_commands")
|
reload_games()
|
||||||
await bot.start(TOKEN)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
global bot_started
|
|
||||||
create_ui()
|
|
||||||
if not bot_started:
|
|
||||||
bot_started = True
|
|
||||||
ui.timer(0, lambda: asyncio.create_task(start_discord_bot()), once=True)
|
|
||||||
ui.run()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ in {"__main__", "__mp_main__"}:
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f"Logged in as {bot.user}")
|
print(f"Logged in as {bot.user}")
|
||||||
|
await bot.load_extension("cogs.slash_commands")
|
||||||
# await bot.tree.sync()
|
# await bot.tree.sync()
|
||||||
reload_games()
|
reload_games()
|
||||||
if not task_loop.is_running():
|
|
||||||
task_loop.start()
|
task_loop.start()
|
||||||
|
|
||||||
|
|
||||||
@@ -64,11 +46,8 @@ async def task_loop():
|
|||||||
)
|
)
|
||||||
for game in bot.tracked_games:
|
for game in bot.tracked_games:
|
||||||
channel = bot.get_channel(game.channelId)
|
channel = bot.get_channel(game.channelId)
|
||||||
if channel is None:
|
|
||||||
continue
|
|
||||||
# handle turn ticks
|
# handle turn ticks
|
||||||
new_turn = game.get_turn()
|
if game.get_turn() != game.turn and game.get_turn().isdigit():
|
||||||
if new_turn != game.turn and new_turn.isdigit():
|
|
||||||
game.update_turn()
|
game.update_turn()
|
||||||
pingstr = ""
|
pingstr = ""
|
||||||
if game.members:
|
if game.members:
|
||||||
@@ -112,3 +91,6 @@ async def task_loop():
|
|||||||
)
|
)
|
||||||
game.update_players()
|
game.update_players()
|
||||||
game.to_json()
|
game.to_json()
|
||||||
|
|
||||||
|
|
||||||
|
bot.run(TOKEN)
|
||||||
|
|||||||
@@ -1,56 +1,18 @@
|
|||||||
aiofiles==25.1.0
|
|
||||||
aiohappyeyeballs==2.6.1
|
aiohappyeyeballs==2.6.1
|
||||||
aiohttp==3.13.5
|
aiohttp==3.13.5
|
||||||
aiosignal==1.4.0
|
aiosignal==1.4.0
|
||||||
annotated-doc==0.0.4
|
|
||||||
annotated-types==0.7.0
|
|
||||||
anyio==4.13.0
|
|
||||||
attrs==26.1.0
|
attrs==26.1.0
|
||||||
audioop-lts==0.2.2
|
audioop-lts==0.2.2
|
||||||
bidict==0.23.1
|
|
||||||
certifi==2026.2.25
|
|
||||||
click==8.3.2
|
|
||||||
discord==2.3.2
|
discord==2.3.2
|
||||||
discord.py==2.7.1
|
discord.py==2.7.1
|
||||||
docutils==0.22.4
|
|
||||||
dotenv==0.9.9
|
dotenv==0.9.9
|
||||||
fastapi==0.135.3
|
|
||||||
frozenlist==1.8.0
|
frozenlist==1.8.0
|
||||||
h11==0.16.0
|
|
||||||
httpcore==1.0.9
|
|
||||||
httptools==0.7.1
|
|
||||||
httpx==0.28.1
|
|
||||||
idna==3.11
|
idna==3.11
|
||||||
ifaddr==0.2.0
|
|
||||||
itsdangerous==2.2.0
|
|
||||||
Jinja2==3.1.6
|
|
||||||
lxml==6.0.2
|
|
||||||
lxml_html_clean==0.4.4
|
|
||||||
markdown2==2.5.5
|
|
||||||
MarkupSafe==3.0.3
|
|
||||||
multidict==6.7.1
|
multidict==6.7.1
|
||||||
nicegui==3.10.0
|
|
||||||
numpy==2.4.4
|
numpy==2.4.4
|
||||||
orjson==3.11.8
|
|
||||||
pandas==3.0.2
|
pandas==3.0.2
|
||||||
propcache==0.4.1
|
propcache==0.4.1
|
||||||
pydantic==2.12.5
|
|
||||||
pydantic_core==2.41.5
|
|
||||||
Pygments==2.20.0
|
|
||||||
python-dateutil==2.9.0.post0
|
python-dateutil==2.9.0.post0
|
||||||
python-dotenv==1.2.2
|
python-dotenv==1.2.2
|
||||||
python-engineio==4.13.1
|
|
||||||
python-multipart==0.0.24
|
|
||||||
python-socketio==5.16.1
|
|
||||||
PyYAML==6.0.3
|
|
||||||
simple-websocket==1.1.0
|
|
||||||
six==1.17.0
|
six==1.17.0
|
||||||
starlette==1.0.0
|
|
||||||
typing-inspection==0.4.2
|
|
||||||
typing_extensions==4.15.0
|
|
||||||
uvicorn==0.44.0
|
|
||||||
uvloop==0.22.1
|
|
||||||
watchfiles==1.1.1
|
|
||||||
websockets==16.0
|
|
||||||
wsproto==1.3.2
|
|
||||||
yarl==1.23.0
|
yarl==1.23.0
|
||||||
|
|||||||
17
webui.py
17
webui.py
@@ -1,17 +0,0 @@
|
|||||||
from nicegui import ui
|
|
||||||
from bot_instance import bot
|
|
||||||
|
|
||||||
# reminder:
|
|
||||||
# tracked_games etc erst in andere variable kopieren und lock benutzen.
|
|
||||||
|
|
||||||
|
|
||||||
def create_ui():
|
|
||||||
ui.label("Amogus")
|
|
||||||
|
|
||||||
with bot.tracked_games_lock:
|
|
||||||
games = list(bot.tracked_games)
|
|
||||||
rows = []
|
|
||||||
for game in games:
|
|
||||||
rows.append({"Name": game.name})
|
|
||||||
|
|
||||||
ui.table(rows=rows)
|
|
||||||
Reference in New Issue
Block a user