init
This commit is contained in:
5
discord-bot/.env-bot
Normal file
5
discord-bot/.env-bot
Normal file
@@ -0,0 +1,5 @@
|
||||
TOKEN='MTI1ODE0NDgxODk3OTE0Nzg5Ng.GKTl0Q.4vzvSFiPs8tl93B42R7PcqpM70C2Ov0YXHQdVU'
|
||||
GUILD_ID=938745671870185482
|
||||
CHANNEL_ID=1382456524009640057
|
||||
MC_HOST='147.185.221.29'
|
||||
MC_PORT=7272
|
||||
11
discord-bot/Dockerfile
Normal file
11
discord-bot/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
# discord-bot/Dockerfile
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /discord-bot
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["python", "frankstein-bot.py"]
|
||||
52
discord-bot/frankstein-bot.py
Normal file
52
discord-bot/frankstein-bot.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import discord
|
||||
from discord.ext import tasks, commands
|
||||
from mcstatus import JavaServer
|
||||
|
||||
import os
|
||||
|
||||
TOKEN = os.environ['TOKEN']
|
||||
MC_HOST = os.environ.get('MC_HOST', 'localhost')
|
||||
MC_PORT = int(os.environ.get('MC_PORT', 7272))
|
||||
CHANNEL_ID = int(os.environ['CHANNEL_ID'])
|
||||
|
||||
|
||||
|
||||
intents = discord.Intents.default()
|
||||
bot = commands.Bot(command_prefix='!', intents=intents)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'Přihlášen jako {bot.user}')
|
||||
update_status.start()
|
||||
|
||||
@tasks.loop(seconds=5)
|
||||
async def update_status():
|
||||
channel = bot.get_channel(CHANNEL_ID)
|
||||
if channel is None:
|
||||
print("Kanál nenalezen.")
|
||||
return
|
||||
|
||||
try:
|
||||
server = JavaServer(MC_HOST, MC_PORT)
|
||||
status = server.status()
|
||||
|
||||
player_count = status.players.online
|
||||
name = f'🟢|online|👤:{player_count}'
|
||||
|
||||
except Exception as e:
|
||||
print("Server offline nebo nelze připojit:", e)
|
||||
name = '🔴|server down!!!'
|
||||
|
||||
try:
|
||||
if name != channel.name:
|
||||
await channel.edit(name=name)
|
||||
|
||||
|
||||
except discord.Forbidden:
|
||||
|
||||
print("Bot nemá oprávnění měnit název kanálu.")
|
||||
|
||||
except discord.HTTPException as e:
|
||||
print("HTTP chyba:", e)
|
||||
|
||||
bot.run(TOKEN)
|
||||
3
discord-bot/requirements.txt
Normal file
3
discord-bot/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
discord.py
|
||||
mcstatus
|
||||
python-dotenv
|
||||
Reference in New Issue
Block a user