Files
profile-system/bot/bot.py
T
EG d4bf750c9e On branch DiscordProfile
Initial commit
2026-07-01 15:15:07 +03:00

209 lines
2.6 KiB
Python

import os
import discord
from discord.ext import commands, tasks
from services.profile_manager import set_value
from services.time_service import update_time
from services.discord_sync import sync
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TOKEN")
intents = discord.Intents.default()
bot = commands.Bot(
command_prefix="!",
intents=intents
)
@bot.event
async def on_ready():
print(
"Bot online",
bot.user,
flush=True
)
if not clock.is_running():
clock.start()
@tasks.loop(minutes=1)
async def clock():
update_time()
try:
result = sync()
if result:
print(
"AUTO SYNC:",
result.status_code,
flush=True
)
else:
print(
"AUTO SYNC: no response",
flush=True
)
except Exception as e:
print(
"SYNC ERROR",
e,
flush=True
)
@bot.slash_command(
name="ping",
description="Проверка бота"
)
async def ping(ctx):
await ctx.respond(
"Pong!"
)
@bot.slash_command(
name="refresh",
description="Принудительное обновление"
)
async def refresh(ctx):
update_time()
result = sync()
if result:
await ctx.respond(
f"✅ Widget updated\nHTTP {result.status_code}"
)
else:
await ctx.respond(
"❌ Sync failed"
)
@bot.slash_command(
name="sub2",
description="Изменить второй текст"
)
async def sub2(
ctx,
text: str
):
set_value(
"sub2",
text
)
sync()
await ctx.respond(
"✅ sub2 обновлён"
)
@bot.slash_command(
name="sub3",
description="Изменить третий текст"
)
async def sub3(
ctx,
text: str
):
set_value(
"sub3",
text
)
sync()
await ctx.respond(
"✅ sub3 обновлён"
)
@bot.slash_command(
name="subi2",
description="Иконка второго слота"
)
async def subi2(
ctx,
url: str
):
set_value(
"subi2",
url
)
sync()
await ctx.respond(
"🖼️ subi2 обновлена"
)
@bot.slash_command(
name="subi3",
description="Иконка третьего слота"
)
async def subi3(
ctx,
url: str
):
set_value(
"subi3",
url
)
sync()
await ctx.respond(
"🖼️ subi3 обновлена"
)
bot.run(TOKEN)