-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
69 lines (48 loc) · 1.56 KB
/
bot.py
File metadata and controls
69 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# bot.py
import os
import socket
import discord
from discord.ext import commands
#developing
from dotenv import load_dotenv
#do not include when shipping
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
#do not include when code visiable
#TOKEN = 'TOKEN KEY FROM ENV'
REQUEST_SERVER_UP = 1
REQUEST_SERVER_DOWN = 2
REQUEST_SERVER_STATUS = 3
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="/", intents=intents)
def handle_request(request):
s = socket.socket()
s.connect(("127.0.0.1",25566))
s.send(request.to_bytes(2,'big'))
result = s.recv(2048)
print(result)
s.close()
return result
@bot.event
async def on_ready():
print("online")
await bot.change_presence(activity=discord.Game('Server Down'))
@bot.command(name="up")
async def up(ctx):
await ctx.send("Sending Server Up")
message = handle_request(REQUEST_SERVER_UP)
await ctx.send("[SERVER] "+message.decode("utf-8"))
if handle_request(REQUEST_SERVER_STATUS) == b'UP':
await bot.change_presence(activity=discord.Game('Server Running!'))
else:
await bot.change_presence(activity=discord.Game('Server Down'))
@bot.command(name="down")
async def down(ctx):
await ctx.send("Sending Server Down")
message = handle_request(REQUEST_SERVER_DOWN)
await ctx.send("[SERVER] "+message.decode("utf-8"))
if handle_request(REQUEST_SERVER_STATUS) == b'UP':
await bot.change_presence(activity=discord.Game('Server Running!'))
else:
await bot.change_presence(activity=discord.Game('Server Down'))
bot.run(TOKEN)