This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
forked from Mekolaos/Aternos-On-Discord
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBot.py
105 lines (68 loc) · 2.52 KB
/
Bot.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import datetime
import time
import Settings
import discord
import connect_and_launch
import colorama
from discord.ext import tasks, commands
from Embeds import server_info_embed, help_embed
bot = discord.ext.commands.Bot(command_prefix='--',
description=Settings.description,
case_insensitive=True,
help_command=None)
@bot.event
async def on_ready():
#Set basic status
status = "Please wait..."
await bot.change_presence(activity=discord.Game(name=status))
#Login to aternos here
connect_and_launch.connect_account()
#Wait a second
time.sleep(3)
#Start both tasks
reloadBrowser.start()
updateStatus.start()
@bot.command()
async def launch(ctx):
status = connect_and_launch.get_status()
if status == "Offline":
await ctx.send("Starting the server...")
connect_and_launch.start_server()
author = ctx.author
print("[" + datetime.datetime.now().strftime("%H:%M:%S") + "]" + colorama.Fore.GREEN + " Server launched by " + colorama.Fore.CYAN + author.name, author.discriminator + colorama.Style.RESET_ALL)
while True:
time.sleep(5)
if connect_and_launch.get_status() == "Online":
await ctx.send(f"{author.mention}, the server has started!")
break
elif connect_and_launch.get_status() == "Online":
await ctx.send("The server is already online.")
else:
await ctx.send("Could not start the server. Reason: server is " + connect_and_launch.get_status())
@bot.command()
async def status(ctx):
await ctx.send(embed=server_info_embed())
@bot.command()
async def help(ctx):
await ctx.send(embed=help_embed())
#T A S K S
@tasks.loop(seconds=15.0)
async def updateStatus():
server_status = connect_and_launch.get_status()
if server_status == "Online":
text = f"Server: Online | " \
f"{len(connect_and_launch.get_players())} | " \
f"--help"
else:
text = f"Server: {connect_and_launch.get_status()} | " \
f"--help"
activity = discord.Activity(type=discord.ActivityType.watching, name=text)
await bot.change_presence(activity=activity)
@tasks.loop(hours=1.0)
async def reloadBrowser():
connect_and_launch.refreshBrowser()
def print_out(out, color):
print("")
print("[" + datetime.datetime.now().strftime("%H:%M:%S") + "]" + color, out, colorama.Style.RESET_ALL)
#Run bot
bot.run(Settings.Token)