-
Notifications
You must be signed in to change notification settings - Fork 0
/
botClient_dist.py
181 lines (146 loc) · 6.26 KB
/
botClient_dist.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Python SuperTitan Bot Client
# Author: SixthTitan
# Date: 2/14/19
# Built with Python 3.6
import asyncio
import aiohttp
import json
import signal
import sys
import os
import time
from discord import Game
from discord.ext.commands import Bot
import discord
# Bot Configuration
TOKEN = "" # Get a token at discordapp.com/developers
CHANNEL = "" # The Channel ID where the bot should report invasions
USER_ID = "" # The user ID of where the bot should report to
BOT_PREFIX = ("?", "!")
description = '''Hello, I am SixthTitan's assistant: \n
I can provide information regarding titan's current software projects and novels regarding the Destiny Zero Origins book series. \n
I can also provide other useful information.'''
client = Bot(command_prefix=BOT_PREFIX, description=description)
def signal_handler(sig, frame):
print('\n Quitting')
client.close() # Disconnect
if client.is_closed:
os.system('clear')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# Available Bot Commands
@client.command(brief="Allows you to be notified when certain cogs are invading Toontown")
async def cogTracker(cogTrack):
await client.wait_until_ready()
while not client.is_closed:
url = 'https://www.toontownrewritten.com/api/invasions'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
invData = response['invasions']
currentInv = []
districtList = []
progression = []
for inv in response["invasions"]:
cog = invData[inv]['type']
progress = invData[inv]['progress']
asOf = time.ctime(invData[inv]['asOf'])
cog = cog.replace('\x03', '') # Replace Panda3d's text seperater
currentInv.append(cog)
districtList.append(inv)
progression.append(progress)
invasionReport = (
"------- COG INVASION ------- \n" +
"District: " + inv + "\n"
"Type: " + cog + "\n"
"Progress: " + progress + "\n"
"Incident Reported: " + asOf
)
if cogTrack == cog:
await client.say("Alert:" + str(cog) + " in " + "District: " + inv + "\n")
@client.event
async def on_ready():
await client.change_presence(game=Game(name="Toontown Rewritten"))
# user = await client.get_user_info(USER_ID)
# await client.send_message(user, "Logged on")
@client.command(brief="Gets current cog invasions in Toontown Rewritten")
async def invasions():
url = 'https://www.toontownrewritten.com/api/invasions'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
invData = response['invasions']
currentInv = []
districtList = []
progression = []
lastUpdated = time.ctime(response["lastUpdated"])
for inv in response["invasions"]:
print("\n")
# print("COG INVASION: \n" + "District: " + inv)
cog = invData[inv]['type']
progress = invData[inv]['progress']
asOf = time.ctime(invData[inv]['asOf'])
cog = cog.replace('\x03', '') # Replace Panda3d's text seperater
currentInv.append(cog)
districtList.append(inv)
progression.append(progress)
await client.say(
"------- COG INVASION ------- \n" +
"District: " + inv + "\n"
"Type: " + cog + "\n"
"Progress: " + progress + "\n"
"Incident Reported: " + asOf
)
@client.event
async def post_invasions():
await client.wait_until_ready()
while not client.is_closed:
url = 'https://www.toontownrewritten.com/api/invasions'
async with aiohttp.ClientSession() as session: # Async HTTP request
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
invData = response['invasions']
currentInv = []
districtList = []
progression = []
lastUpdated = time.ctime(response["lastUpdated"])
invasionreported = False
for inv in response["invasions"]:
cog = invData[inv]['type']
progress = invData[inv]['progress']
asOf = time.ctime(invData[inv]['asOf'])
cog = cog.replace('\x03', '') # Replace Panda3d's text seperater
currentInv.append(cog)
districtList.append(inv)
progression.append(progress)
invasionReport = (
"------- COG INVASION ------- \n" +
"District: " + inv + "\n"
"Type: " + cog + "\n"
"Progress: " + progress + "\n"
"Incident Reported: " + asOf
)
await client.send_message(discord.Object(id=CHANNEL), content=invasionReport, tts=True)
await asyncio.sleep(930)
async def list_servers():
await client.wait_until_ready()
while not client.is_closed:
# print("Current servers:")
for server in client.servers:
os.system('clear')
print("******************************************************")
print("* Toontown Rewritten Invasion Tracker, *")
print("* Version 1.0 Written by Sixth Titan *")
print("* Invasions are reported every 15 minutes on the *")
print("* Discord Server through the Super Titan Bot Account *")
print("******************************************************")
print("Account Username: " + client.user.name + "\n"
+ "Account Server: " + server.name + "\n")
print('Press Ctrl+C to quit')
await asyncio.sleep(600)
client.loop.create_task(list_servers())
client.loop.create_task(post_invasions())
client.run(TOKEN)