bot: Initial add
This commit is contained in:
6
discord-bot/Dockerfile
Normal file
6
discord-bot/Dockerfile
Normal 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
37
discord-bot/bot.py
Normal 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)
|
||||
3
discord-bot/requirements.txt
Normal file
3
discord-bot/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
discord.py
|
||||
python-dotenv
|
||||
requests
|
||||
Reference in New Issue
Block a user