-
Notifications
You must be signed in to change notification settings - Fork 2
/
pub_bot.py
336 lines (263 loc) · 10.9 KB
/
pub_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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
from discord.ext import commands
from bs4 import BeautifulSoup
from datetime import datetime
import requests
import discord
import ssl
import os
from tabulate import tabulate
# .o8 .o8 oooo
# "888 "888 `888
# .oooo888 .oooo. .ooooo. .oooo888 .oooo. 888 oooo oooo .oooo.o
# d88' `888 `P )88b d88' `88b d88' `888 `P )88b 888 `888 `888 d88( "8
# 888 888 .oP"888 888ooo888 888 888 .oP"888 888 888 888 `"Y88b.
# 888 888 d8( 888 888 .o 888 888 d8( 888 888 888 888 o. )88b
# `Y8bod88P" `Y888""8o `Y8bod8P' `Y8bod88P" `Y888""8o o888o `V88V"V8P' 8""888P'
# SPECIFY REMOTE HERE AND YOUR BOT Token HERE
remote = ''
bot_id = ''
empty_space = " "
# COMMAND PREFIX
client = commands.Bot(command_prefix='d ')
def get_time():
time = 'Score Reported at: {}'.format(datetime.now())
return time
@client.event
async def on_ready():
print('Daedalus is ready!')
@client.command()
async def ping(ctx):
await ctx.send('Pong!')
@client.command()
async def server(ctx):
message = 'Server is located at: {}'.format(remote)
await ctx.send(message)
@client.command()
async def daedalus(ctx):
logo = '''```css
.o8 .o8 oooo
"888 "888 `888
.oooo888 .oooo. .ooooo. .oooo888 .oooo. 888 oooo oooo .oooo.o
d88' `888 `P )88b d88' `88b d88' `888 `P )88b 888 `888 `888 d88( "8
888 888 .oP"888 888ooo888 888 888 .oP"888 888 888 888 `"Y88b.
888 888 d8( 888 888 .o 888 888 d8( 888 888 888 888 o. )88b
`Y8bod88P" `Y888""8o `Y8bod8P' `Y8bod88P" `Y888""8o o888o `V88V"V8P' 8""888P'
```'''
await ctx.send(logo)
@client.command()
async def man(ctx):
embed = discord.Embed(color=0x6393f)
embed.title = 'Commands:'
embed.add_field(name='`ping`', value='Pong!', inline=True)
embed.add_field(name='`daedalus`', value='Display ASCII art', inline=True)
embed.add_field(
name='`help`', value='Will display all commands and their uses', inline=False)
embed.add_field(
name='`server`', value='Will display the server the bot is currently pulling scores from', inline=False)
embed.add_field(
name='`top`', value='Will fetch the top 10 scores', inline=False)
embed.add_field(name='`team <team_name>`',
value='Will fetch score details for the team specified', inline=False)
embed.add_field(
name='`export`', value='Will fetch a file containing current scores', inline=False)
embed.add_field(name='`scoreboard <number>` or `sc <number>`',
value='Will fetch the top <number> scores. If the message is too large to be sent on Discord, it will be sent as a text file', inline=False)
embed.add_field(name='`image <image_name> <number>`',
value='Will fetch the top <number> scores for the image specified. If the message is too large to be sent on discord it will be sent as a text file', inline=False)
embed.add_field(name='`rank <image_name> <team_id>`',
value='Will return the rank of the given ID for the given image if it exists', inline=False)
await ctx.send(embed=embed)
@client.command()
async def top(ctx):
data = requests.get(remote)
content = data.content
soup = BeautifulSoup(content, 'html.parser')
scores = soup.find_all('tr')
top_comp = [[" ════ ", " ", " ════ ", " ", " ════ ", " ", " ════ "]]
header = ['Rank',' ', 'Team', ' ', 'Time', ' ', 'Score']
for team in scores[0:10]:
team = team.find_all('a')
team_info = [team[0].contents[0], team[1].contents[0],
team[2].contents[0], team[3].contents[0], team[4].contents[0]]
team_info_fixed = []
for element in team_info:
team_info_fixed.append(element.strip())
top_comp.append([team_info_fixed[0], " ", team_info_fixed[1], " ", team_info_fixed[3], " ", team_info_fixed[4]])
formatted = "```" + tabulate(top_comp, header, stralign="left", numalign="left", tablefmt="plain") + "```"
h_find = soup.find_all('h4')
round_title = h_find[0].text
embed = discord.Embed(color=0x36393f)
embed.title = round_title
embed.set_footer(text=empty_space + "\n" + get_time() + "\n" + empty_space)
embed.add_field(name="\u200b", value=formatted, inline=False)
await ctx.send(embed=embed)
@client.command(aliases=["sc"])
async def scoreboard(ctx, num=None):
data = requests.get(remote)
if num is not None:
num = int(num)
content = data.content
soup = BeautifulSoup(content, 'html.parser')
h_find = soup.find_all('h4')
round_title = h_find[0].text
scores = soup.find_all('tr')
top_comp = [[" ════ ", " ", " ════ ", " ", " ════ ", " ", " ════ "]]
header = ['Rank',' ', 'Team', ' ', 'Time', ' ', 'Score']
for team in scores[0:num]:
team = team.find_all('a')
team_info = [team[0].contents[0], team[1].contents[0],
team[2].contents[0], team[3].contents[0], team[4].contents[0]]
team_info_fixed = []
for element in team_info:
team_info_fixed.append(element.strip())
top_comp.append([team_info_fixed[0], " ", team_info_fixed[1], " ", team_info_fixed[3], " ", team_info_fixed[4]])
formatted = "```" + tabulate(top_comp, header, stralign="left", numalign="left", tablefmt="plain") + "```"
h_find = soup.find_all('h4')
round_title = h_find[0].text
embed = discord.Embed(color=0x36393f)
embed.title = round_title
embed.set_footer(text=empty_space + "\n" + get_time() + "\n" + empty_space)
embed.add_field(name="\u200b", value=formatted, inline=False)
try:
await ctx.send(embed=embed)
except:
fle = open('scoreboard.txt', 'w+')
formatted.split('```')
fle.write(formatted[1])
fle.close()
await ctx.send(file=discord.File('scoreboard.txt'))
@client.command()
async def team(ctx, arg):
global remote
url = '{}/team/{}'.format(remote, str(arg))
team_data = requests.get(url)
content = team_data.content
soup = BeautifulSoup(content, 'html.parser')
scores = soup.find_all(
'table', {"class": "table table-borderless table-dark table-striped"})
image_tags = soup.find('tbody')
tds = []
image_scores_bad = image_tags[1]
try_to_fix_image_scores = image_scores_bad.find_all('td')
for score in try_to_fix_image_scores.find_all('a'):
print(score)
for thing in scores:
tds.append(thing.find_all('tr'))
general_tags = tds[0]
temp = []
for gentag in general_tags:
gentemp = gentag.find_all('td')
for j, gentag in enumerate(gentemp):
gentemp[j] = '`{}`'.format(gentag.text)
for tag in image_tags:
temp.append(tag.find_all('td'))
for list in temp:
for i, tag in enumerate(list):
list[i] = tag.text
report = []
for list in temp:
message = '''Image: {} Time: {} Score: ({}/{}) {}'''.format(
list[0], list[1], list[2], list[3], list[4])
report.append(message)
formatted = '\n'
formatted = formatted.join(report)
formatted = '```' + formatted + '```'
title = 'Scores for {}:'.format(arg)
embed = discord.Embed(color=0x36393f)
embed.title = title
embed.add_field(name="Elapsed Time", value=gentemp[0], inline=False)
embed.add_field(name="Play Time", value=gentemp[1], inline=False)
embed.add_field(name="Total Score", value=gentemp[2], inline=False)
embed.add_field(name="Current Image Scores", value=formatted, inline=False)
embed.add_field(name="Time", value=get_time(), inline=False)
embed.add_field(name="Link", value=url, inline=False)
await ctx.send(embed=embed)
@client.command()
async def export(ctx):
data = requests.get(remote)
content = data.content
soup = BeautifulSoup(content, 'html.parser')
h_find = soup.find_all('h4')
round_title = h_find[0].text
scores = soup.find_all('tr')
top_comp = []
header = ['Rank','Team','Images','Time','Score']
for team in scores:
team = team.find_all('a')
team_info = [team[0].contents[0], team[1].contents[0],
team[2].contents[0], team[3].contents[0], team[4].contents[0]]
team_info_fixed = []
for element in team_info:
team_info_fixed.append(element.strip())
detail = '''{} {} {} {} {}'''.format(team_info_fixed[0], team_info_fixed[1], team_info_fixed[2], team_info_fixed[3], team_info_fixed[4])
detail = detail.split()
top_comp.append(detail)
print(tabulate(top_comp, header))
table = tabulate(top_comp, header)
top_title = '''{} | Report Generated on {} | Server at {}'''.format(
round_title, get_time(), remote)
fle = open('scoreboard.txt', 'w+')
fle.write(top_title + '\n')
fle.write(table)
fle.close()
await ctx.send(file=discord.File('scoreboard.txt'))
@client.command()
async def image(ctx, name, num):
num = int(num)
url = '{}/image/{}'.format(remote, str(name))
team_image_data = requests.get(url)
content = team_image_data.content
soup = BeautifulSoup(content, 'html.parser')
h_find = soup.find_all('h4')
round_title = h_find[0].text
scores = soup.find_all('tr')
comp = []
header = ['Rank','Team','Time','Score']
for team in scores:
team = team.find_all('a')
team_info = [team[0].contents[0],
team[1].contents[0], team[2].contents[0], team[3].contents[0]]
team_info_fixed = []
for element in team_info:
team_info_fixed.append(element.strip())
detail = '''{} {} {} {}'''.format(
team_info_fixed[0], team_info_fixed[1], team_info_fixed[2], team_info_fixed[3])
detail = detail.split()
comp.append(detail)
formatted = "```" + tabulate(comp, header) + "```"
h_find = soup.find_all('h4')
round_title = h_find[0].text
embed = discord.Embed(color=0x36393f)
embed.title = round_title
embed.add_field(name="Time", value=get_time(), inline=False)
embed.description = formatted
try:
await ctx.send(embed=embed)
except:
fle = open('scoreboard.txt', 'w+')
fle.write(formatted_old)
fle.close()
await ctx.send(file=discord.File('scoreboard.txt'))
@client.command()
async def rank(ctx, image, id):
id = str(id)
image = str(image)
url = '{}image/{}'.format(remote, str(image))
team_image_data = requests.get(url)
content = team_image_data.content
soup = BeautifulSoup(content, 'html.parser')
scores = soup.find_all('tr')
rank = -1
for score in scores:
if str(score.find_all('a')[1].text).strip() == str(id).strip():
rank = int(score.find_all('a')[0].text)
break
if rank == -1:
embed = discord.Embed(color=0x36393f)
embed.title ="ID not found for this image"
await ctx.send(embed=embed)
else:
embed = discord.Embed(color=0x36393f)
embed.title = str(id) + "'s rank is " + str(rank)
await ctx.send(embed=embed)
client.run(bot_id)