bot: Initial add
All checks were successful
Build Docker / Build Master (push) Successful in 23s
Build Docker / Build Bot (push) Successful in 37s

This commit is contained in:
2023-08-16 17:43:30 +10:00
parent 14ee680583
commit 036ddc7aa6
5 changed files with 90 additions and 1 deletions

6
discord-bot/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3.10-bullseye
COPY requirements.txt /app/
WORKDIR /app
RUN pip install -r requirements.txt
COPY . .
CMD ["python3", "bot.py"]

37
discord-bot/bot.py Normal file
View File

@@ -0,0 +1,37 @@
import os
from dotenv import load_dotenv
import discord
from discord import app_commands
import requests
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
ADMINID = 0
Master_IP = os.getenv('MASTER_IP')
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@tree.command(name="addworker", description="Adds a worker to the master server")
async def addworker(ctx, ip: str, name: str):
if ctx.author.id == ADMINID:
r = requests.get(f"http://{Master_IP}:5000/add-worker?worker={name}&ip={ip}")
if r.status_code == 200:
await ctx.response.send_message(f"Worker {name} added to the master server",ephemeral=True)
else:
await ctx.response.send_message(f"Error adding worker {name} to the master server\n" + r.text,ephemeral=True)
else:
await ctx.response.send_message("You do not have permission to use this command",ephemeral=True)
# When the bot is ready
@client.event
async def on_ready():
global ADMINID
ADMINID = client.application.owner.id
await tree.sync()
await client.loop.create_task(client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over HNSHosting wordpress")))
client.run(TOKEN)

View File

@@ -0,0 +1,3 @@
discord.py
python-dotenv
requests