forked from ccev/Discordopole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discordopole.py
622 lines (517 loc) · 27.8 KB
/
discordopole.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
import discord
import json
import aiomysql
import aiohttp
import asyncio
import os
import dateparser
import matplotlib.pyplot as plt
from dateutil.relativedelta import relativedelta
from itertools import islice
from datetime import datetime
from datetime import date
from discord.ext import commands
from util.mondetails import details
import util.queries
import util.config
MAX_MOVE_IN_LIST = 291
queries = util.queries
config = util.config.create_config("config/config.ini")
bot = commands.Bot(command_prefix=config['prefix'], case_insensitive=1)
with open(f"data/dts/{config['language']}.json") as localejson:
locale = json.load(localejson)
with open("config/boards.json", "r") as f:
bot.boards = json.load(f)
with open(f"data/moves/{config['language']}.json") as f:
moves = json.load(f)
with open("config/geofence.json") as f:
geofences = json.load(f)
with open("config/emotes.json") as f:
bot.custom_emotes = json.load(f)
def get_area(areaname):
stringfence = "-100 -100, -100 100, 100 100, 100 -100, -100 -100"
namefence = locale['all']
for area in geofences:
if area['name'].lower() == areaname.lower():
namefence = area['name'].capitalize()
stringfence = ""
for coordinates in area['path']:
stringfence = f"{stringfence}{coordinates[0]} {coordinates[1]},"
stringfence = f"{stringfence}{area['path'][0][0]} {area['path'][0][1]}"
area_list = [stringfence, namefence]
return area_list
async def board_loop():
while not bot.is_closed():
for board in bot.boards['raids']:
try:
channel = await bot.fetch_channel(board["channel_id"])
message = await channel.fetch_message(board["message_id"])
area = get_area(board["area"])
text = ""
raids = await queries.get_active_raids(config, area[0], board["levels"], board["timezone"])
if not raids:
text = locale["empty_board"]
else:
for start, end, lat, lon, mon_id, move_1, move_2, name, ex, level in islice(raids, 21):
end = datetime.fromtimestamp(end).strftime(locale['time_format_hm'])
ex_emote = ""
if ex == 1:
ex_emote = f"{bot.custom_emotes['ex_pass']} "
if not mon_id is None and mon_id > 0:
mon_name = details.id(mon_id, config['language'])
if move_1 > MAX_MOVE_IN_LIST:
move_1 = "?"
else:
move_1 = moves[str(move_1)]["name"]
if move_2 > MAX_MOVE_IN_LIST:
move_2 = "?"
else:
move_2 = moves[str(move_2)]["name"]
text = text + f"{ex_emote}**{name}**: {locale['until']} {end}\n**{mon_name}** - *{move_1} / {move_2}*\n\n"
embed = discord.Embed(title=locale['raids'], description=text, timestamp=datetime.utcnow())
embed.set_footer(text=area[1])
await message.edit(embed=embed)
await asyncio.sleep(board["wait"])
except Exception as err:
print(err)
print("Error while updating Raid Board. Skipping it.")
await asyncio.sleep(5)
for board in bot.boards['eggs']:
try:
channel = await bot.fetch_channel(board["channel_id"])
message = await channel.fetch_message(board["message_id"])
area = get_area(board["area"])
text = ""
raids = await queries.get_active_raids(config, area[0], board["levels"], board["timezone"])
if not raids:
text = locale["empty_board"]
else:
for start, end, lat, lon, mon_id, move_1, move_2, name, ex, level in islice(raids, 23):
start = datetime.fromtimestamp(start).strftime(locale['time_format_hm'])
end = datetime.fromtimestamp(end).strftime(locale['time_format_hm'])
ex_emote = ""
if ex == 1:
ex_emote = f"{bot.custom_emotes['ex_pass']} "
if mon_id is None or mon_id == 0:
egg_emote = bot.custom_emotes[f"raid_egg_{level}"]
text = text + f"{egg_emote} {ex_emote}**{name}**: {start} – {end}\n"
embed = discord.Embed(title=locale['eggs'], description=text, timestamp=datetime.utcnow())
embed.set_footer(text=area[1])
await message.edit(embed=embed)
await asyncio.sleep(board["wait"])
except Exception as err:
print(err)
print("Error while updating Egg Board. Skipping it.")
await asyncio.sleep(5)
for board in bot.boards['stats']:
try:
channel = await bot.fetch_channel(board["channel_id"])
message = await channel.fetch_message(board["message_id"])
area = get_area(board["area"])
text = ""
if "mon_active" in board['type']:
mon_active = await queries.statboard_mon_active(config, area[0])
if not "mon_today" in board['type']:
text = f"{text}{bot.custom_emotes['pokeball']} **{mon_active[0][0]:,}** {locale['active_pokemon']}\n\n"
if "mon_today" in board['type']:
mon_today = await queries.statboard_mon_today(config, area[0])
if "mon_active" in board['type']:
text = f"{text}{bot.custom_emotes['pokeball']} **{mon_active[0][0]:,}** {locale['active_pokemon']} | **{mon_today[0][0]:,}** {locale['today']}\n\n"
else:
text = f"{text}{bot.custom_emotes['pokeball']} **{mon_today[0][0]:,}** {locale['pokemon_seen_today']}\n\n"
if "gym_amount" in board['type']:
gym_amount = await queries.statboard_gym_amount(config, area[0])
text = f"{text}{bot.custom_emotes['gym_white']} **{gym_amount[0][0]:,}** {locale['total_gyms']}\n"
if "raid_active" in board['type']:
raid_active = await queries.statboard_raid_active(config, area[0])
if not "egg_active" in board['type']:
text = f"{text}{bot.custom_emotes['raid']} **{raid_active[0][0]:,}** {locale['active_raids']}\n"
if "egg_active" in board['type']:
egg_active = await queries.statboard_egg_active(config, area[0])
if "raid_active" in board['type']:
text = f"{text}{bot.custom_emotes['raid']} **{raid_active[0][0]:,}** {locale['active_raids']} | **{egg_active[0][0]:,}** {locale['eggs']}\n"
else:
text = f"{text}{bot.custom_emotes['raid_egg_1']} **{egg_active[0][0]:,}** {locale['active_eggs']}\n"
if "gym_teams" in board['type']:
gym_teams = await queries.statboard_gym_teams(config, area[0])
text = f"{text}{bot.custom_emotes['gym_blue']}**{gym_teams[0][1]}**{bot.custom_emotes['blank']}{bot.custom_emotes['gym_red']}**{gym_teams[0][2]}**{bot.custom_emotes['blank']}{bot.custom_emotes['gym_yellow']}**{gym_teams[0][3]}**\n"
if "stop_amount" in board['type']:
stop_amount = await queries.statboard_stop_amount(config, area[0])
text = f"{text}\n{bot.custom_emotes['pokestop']} **{stop_amount[0][0]:,}** {locale['total_stops']}\n"
if "quest_active" in board['type']:
quest_active = await queries.statboard_quest_active(config, area[0])
text = f"{text}🔎 **{quest_active[0][0]:,}** {locale['quests']}\n"
if "grunt_active" in board['type']:
grunt_active = await queries.statboard_grunt_active(config, area[0])
if not "leader_active" in board['type']:
text = f"{text}{bot.custom_emotes['grunt_female']} **{grunt_active[0][0]:,}** {locale['active_grunts']}"
if "leader_active" in board['type']:
leader_active = await queries.statboard_leader_active(config, area[0])
if "grunt_active" in board['type']:
text = f"{text}{bot.custom_emotes['grunt_female']} **{grunt_active[0][0]:,}** {locale['grunts']} | {bot.custom_emotes['cliff']} **{leader_active[0][0]:,}** {locale['leaders']}"
else:
text = f"{text}{bot.custom_emotes['cliff']} **{leader_active[0][0]:,}** {locale['leaders']}"
embed = discord.Embed(title=locale['stats'], description=text.replace(",", locale['decimal_comma']), timestamp=datetime.utcnow())
embed.set_footer(text=area[1])
await message.edit(embed=embed)
await asyncio.sleep(board["wait"])
except Exception as err:
print(err)
print("Error while updating Stat Board. Skipping it.")
await asyncio.sleep(5)
await asyncio.sleep(1)
@bot.group(pass_context=True)
async def board(ctx):
if not ctx.message.author.id in config['admins']:
return
if ctx.invoked_subcommand is None:
await ctx.send("`create/delete`")
@board.group(pass_context=True)
async def create(ctx):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to create an empty Board but is no Admin")
return
if ctx.invoked_subcommand is None:
print("Creating an empty Board")
await ctx.message.delete()
embed = discord.Embed(title="Empty board", description="")
message = await ctx.send(embed=embed)
embed.description = f"Channel ID: `{message.channel.id}`\nMessage ID: `{message.id}`\n"
await message.edit(embed=embed)
print("Done creating an empty Board")
@board.command(pass_context=True)
async def delete(ctx, deleted_message_id):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to create a delete a Board but is no Admin")
return
message_found = False
for board_type in bot.boards:
for board in bot.boards[board_type]:
if int(deleted_message_id) == board['message_id']:
message_found = True
bot.boards[board_type].remove(board)
with open("config/boards.json", "w") as f:
f.write(json.dumps(bot.boards, indent=4))
channel = await bot.fetch_channel(board["channel_id"])
message = await channel.fetch_message(deleted_message_id)
await message.delete()
await ctx.send("Successfully deleted Board.")
if not message_found:
await ctx.send("Couldn't find a board with that Message ID.")
return
@create.command(pass_context=True)
async def raid(ctx, area, levels):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to create a Raid Board but is no Admin")
return
print("Creating Raid Board")
embed = discord.Embed(title="Raid Board", description="")
message = await ctx.send(embed=embed)
level_list = list(levels.split(','))
level_list = list(map(int, level_list))
if all(i > 5 or i < 1 for i in level_list):
embed.description = "Couldn't create Raid Board. Try chosing other levels."
await message.edit(embed=embed)
return
areaexist = False
for areag in geofences:
if areag['name'].lower() == area.lower():
areaexist = True
if not areaexist:
embed.description = "Couldn't find that area. Try again."
await message.edit(embed=embed)
return
await ctx.message.delete()
bot.boards['raids'].append({"channel_id": message.channel.id, "message_id": message.id, "area": area, "timezone": config['timezone'], "wait": 15, "levels": level_list})
with open("config/boards.json", "w") as f:
f.write(json.dumps(bot.boards, indent=4))
embed.title = "Succesfully created this Raid Board"
embed.description = f"You'll see this message being filled in soon\n\n```Area: {area}\nLevels: {levels}\nChannel ID: {message.channel.id}\nMessage ID: {message.id}```"
await message.edit(embed=embed)
print("Wrote Raid Board to config/boards.json")
@create.command(pass_context=True)
async def egg(ctx, area, levels):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to create a Egg Board but is no Admin")
return
print("Creating Egg Board")
embed = discord.Embed(title="Egg Board", description="")
message = await ctx.send(embed=embed)
level_list = list(levels.split(','))
level_list = list(map(int, level_list))
if all(i > 5 or i < 1 for i in level_list):
embed.description = "Couldn't create Egg Board. Try chosing other levels."
await message.edit(embed=embed)
return
areaexist = False
for areag in geofences:
if areag['name'].lower() == area.lower():
areaexist = True
if not areaexist:
embed.description = "Couldn't find that area. Try again."
await message.edit(embed=embed)
return
await ctx.message.delete()
bot.boards['eggs'].append({"channel_id": message.channel.id, "message_id": message.id, "area": area, "timezone": config['timezone'], "wait": 15, "levels": level_list})
with open("config/boards.json", "w") as f:
f.write(json.dumps(bot.boards, indent=4))
embed.title = "Succesfully created this Egg Board"
embed.description = f"You'll see this message being filled in soon\n\n```Area: {area}\nLevels: {levels}\nChannel ID: {message.channel.id}\nMessage ID: {message.id}```"
await message.edit(embed=embed)
print("Wrote Raid Board to config/boards.json")
@create.command(pass_context=True)
async def stats(ctx, area, *, types):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to create a Stat Board but is no Admin")
return
print("Creating Stat Board")
embed = discord.Embed(title="Stat Board", description="")
message = await ctx.send(embed=embed)
stat_list = list(types.split(','))
stats = list()
for stat in stat_list:
if "mon" in stat:
if "active" in stat:
stats.append("mon_active")
elif "today" in stat:
stats.append("mon_today")
elif "gym" in stat:
if "amount" in stat:
stats.append("gym_amount")
elif "team" in stat:
stats.append("gym_teams")
elif "raid" in stat:
#if "active" in stat:
stats.append("raid_active")
elif "egg" in stat:
#if "active" in stat:
stats.append("egg_active")
elif "stop" in stat:
stats.append("stop_amount")
elif "grunt" in stat:
#if "active" in stat:
stats.append("grunt_active")
elif "leader" in stat:
stats.append("leader_active")
elif "quest" in stat:
stats.append("quest_active")
areaexist = False
for areag in geofences:
if areag['name'].lower() == area.lower():
areaexist = True
if not areaexist:
embed.description = "Couldn't find that area. Try again."
await message.edit(embed=embed)
return
await ctx.message.delete()
bot.boards['stats'].append({"channel_id": message.channel.id, "message_id": message.id, "area": area, "timezone": config['timezone'], "wait": 15, "type": stats})
with open("config/boards.json", "w") as f:
f.write(json.dumps(bot.boards, indent=4))
embed.title = "Succesfully created this Stat Board"
embed.description = f"You'll see this message being filled in soon\n\n```Area: {area}\nStats: {stats}\nChannel ID: {message.channel.id}\nMessage ID: {message.id}```"
await message.edit(embed=embed)
print("Wrote Stat Board to config/boards.json")
@bot.group(pass_context=True)
async def get(ctx):
if not ctx.message.author.id in config['admins']:
return
if ctx.invoked_subcommand is None:
await ctx.send("Be more specific")
async def download_url(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.read()
@get.command(pass_context=True)
async def emotes(ctx):
if not ctx.message.author.id in config['admins']:
print(f"@{ctx.author.name} tried to import emotes but is no Admin")
return
print(f"@{ctx.author.name} wants to import emotes in Server {ctx.guild.name}. Waiting for confirmation")
needed_emote_names = ["ex_pass", "raid_egg_1", "raid_egg_2", "raid_egg_3", "raid_egg_4", "raid_egg_5", "gym_blue", "gym_red", "gym_yellow", "gym_white", "blank", "raid", "cliff", "grunt_female", "pokeball", "pokestop"]
emotejson = json.loads("{}")
embed = discord.Embed(title="Importing emotes will overwrite all custom emotes in this Server!", description="Please make sure you're currently in a server dedicated to host Discordopole emotes.\n\nTo continue, please say the name of this Server.")
message = await ctx.send(embed=embed)
def check(m):
return m.content == ctx.guild.name and m.author == ctx.author and m.channel == ctx.channel
try:
confirm = await bot.wait_for('message', check=check, timeout=60)
except:
await ctx.send("Aborting Emote import.")
await message.delete()
print("No confirmation after 60 seconds. Aborting emote import.")
return
print("Server name matched. Deleting all emotes now.")
await confirm.delete()
embed = discord.Embed(title="Importing Emotes. Please Wait", description="")
await message.edit(embed=embed)
existing_emotes = await ctx.guild.fetch_emojis()
for emote in existing_emotes:
await emote.delete()
embed.description = f"{embed.description}Removed Emote `{emote.name}`\n"
await message.edit(embed=embed)
embed.description = ""
print(f"Done. Now importing all needed emotes from repo {config['emote_repo']}")
for emote_name in needed_emote_names:
image = await download_url(f"{config['emote_repo']}{emote_name}.png")
emote = await ctx.guild.create_custom_emoji(name=emote_name, image=image)
emote_ref = f"<:{emote.name}:{emote.id}>"
embed.description = f"{embed.description}{emote_ref} `{emote_ref}`\n"
await message.edit(embed=embed)
emotejson.update({emote_name: emote_ref})
embed.title = "Done importing Emotes"
await message.edit(embed=embed)
with open("config/emotes.json", "w") as f:
f.write(json.dumps(emotejson, indent=4))
bot.custom_emotes = emotejson
print("All emotes imported.")
@bot.command(pass_context=True, aliases=config['pokemon_aliases'])
async def pokemon(ctx, stat_name, areaname = "", *, timespan = None):
mon = details(stat_name, config['mon_icon_repo'], config['language'])
footer_text = ""
text = ""
loading = f"{locale['loading']} {mon.name} Stats"
area = get_area(areaname)
if not area[1] == locale['all']:
footer_text = area[1]
loading = f"{loading} • "
if timespan is None:
timespan = list([datetime(2010, 1, 1, 0, 0), datetime.now()])
else:
loading = ""
if "-" in timespan:
timespan = list(timespan.split('-'))
for i in [0, 1]:
timespan[i] = dateparser.parse(timespan[i])
footer_text = f"{(locale['between']).capitalize()} {timespan[0].strftime(locale['time_format_dhm'])} {locale['and']} {timespan[1].strftime(locale['time_format_dhm'])}"
else:
timespan = list([dateparser.parse(timespan), datetime.now()])
if area[1] == locale['all']:
footer_text = f"{(locale['since']).capitalize()} {timespan[0].strftime(locale['time_format_dhm'])}"
else:
footer_text = f"{footer_text}, {locale['since']} {timespan[0].strftime(locale['time_format_dhm'])}"
print(f"@{ctx.author.name} requested {mon.name} stats for area {area[1]}")
embed = discord.Embed(title=f"{mon.name}", description=text)
embed.set_thumbnail(url=mon.icon)
embed.set_footer(text=f"{loading}{footer_text}", icon_url="https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif")
message = await ctx.send(embed=embed)
shiny_count = await queries.get_shiny_count(mon.id, area[0], timespan[0], timespan[1], config)
if shiny_count > 0:
shiny_total = await queries.get_shiny_total(mon.id, area[0], timespan[0], timespan[1], config)
shiny_odds = int(round((shiny_total / shiny_count), 0))
text = text + f"{locale['shinies']}: **1:{shiny_odds}** ({shiny_count:_}/{shiny_total:_})\n"
else:
text = text + f"{locale['shinies']}: **0**\n"
embed.description = text.replace("_", locale['decimal_comma'])
await message.edit(embed=embed)
print(f" [1/3] Shiny Data for {mon.name} Stats")
scan_numbers = await queries.get_scan_numbers(mon.id, area[0], timespan[0], timespan[1], config)
for scanned, hundos, zeros, nineties in scan_numbers:
scanned_total = int(scanned)
if scanned_total > 0:
hundo_count = int(hundos)
zero_count = int(zeros)
ninety_count = int(nineties)
else:
hundo_count = 0
zero_count = 0
ninety_count = 0
if hundo_count > 0:
hundo_odds = int(round((scanned_total / hundo_count), 0))
text = text + f"{locale['hundos']}: **{hundo_count:_}** (1:{hundo_odds})\n\n"
else:
text = text + f"{locale['hundos']}: **0/{scanned_total:_}**\n\n"
if ninety_count > 0:
ninety_odds = round((scanned_total / ninety_count), 0)
text = text + f"{locale['90']}: **{ninety_count:_}** (1:{int(ninety_odds)}) | "
else:
text = text + f"{locale['90']}: **0** | "
if zero_count > 0:
zero_odds = round((scanned_total / zero_count), 0)
text = text + f"{locale['0']}: **{zero_count:_}** (1:{int(zero_odds)})\n"
else:
text = text + f"{locale['0']}: **0**\n"
embed.description = text.replace("_", locale['decimal_comma'])
await message.edit(embed=embed)
print(f" [2/3] Scan Data for {mon.name} Stats")
big_numbers = await queries.get_big_numbers(mon.id, area[0], timespan[0], timespan[1], config)
for mons, found, boosted, time in big_numbers:
mon_total = int(mons)
if found is not None:
found_count = int(found)
boosted_count = int(boosted)
else:
found_count = 0
boosted_count = 0
days = (timespan[1].date() - (big_numbers[0][3]).date()).days
if days < 1:
days = 1
if found_count > 0:
mon_odds = int(round((mon_total / found_count), 0))
mon_rate = str(round((found_count / days), 1)).replace(".", locale['decimal_dot'])
text = text.replace(f"\n{locale['90']}", f"{locale['rarity']}: **1:{mon_odds}**\n{locale['rate']}: **{mon_rate}/{locale['day']}**\n\n{locale['90']}")
boosted_odds = str(round((boosted_count / found_count * 100), 1)).replace(".", locale['decimal_dot'])
text = text + f"{locale['weatherboost']}: **{boosted_odds}%**\n"
scanned_odds = str(round((scanned_total / found_count * 100), 1)).replace(".", locale['decimal_dot'])
text = text + f"{locale['scanned']}: **{scanned_odds}%**\n\n"
text = text + f"{locale['total_found']}: **{found_count:_}**"
else:
text = text.replace(f"\n{locale['90']}", f"{locale['rarity']}: **0**\n{locale['rate']}: **0/{locale['day']}**\n\n{locale['90']}")
text = text + f"{locale['weatherboost']}: **0%**\n{locale['scanned']}: **0**\n\n{locale['total_found']}: **0**"
embed.description = text.replace("_", locale['decimal_comma'])
embed.set_footer(text=footer_text)
await message.edit(embed=embed)
print(f" [3/3] Total Data for {mon.name} Stats")
print(f"Done with {mon.name} Stats.")
@bot.command(pass_context=True, aliases=config['gyms_aliases'])
async def gyms(ctx, areaname = ""):
footer_text = ""
text = ""
loading = locale['loading_gym_stats']
area = get_area(areaname)
if not area[1] == locale['all']:
footer_text = area[1]
loading = f"{loading} • {footer_text}"
print(f"@{ctx.author.name} requested gym stats for area {area[1]}")
embed = discord.Embed(title=locale['gym_stats'], description=text)
embed.set_footer(text=loading, icon_url="https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif")
message = await ctx.send(embed=embed)
gym_stats = await queries.get_gym_stats(config, area[0])
for total, neutral, mystic, valor, instinct, ex, raids in gym_stats:
total_count = int(total)
white_count = int(neutral)
blue_count = int(mystic)
red_count = int(valor)
yellow_count = int(instinct)
ex_count = int(ex)
raid_count = int(raids)
if total_count > 0:
ex_odds = str(int(round((ex_count / total_count * 100), 0))).replace(".", locale['decimal_dot'])
text = f"{bot.custom_emotes['gym_blue']}**{blue_count}**{bot.custom_emotes['blank']}{bot.custom_emotes['gym_red']}**{red_count}**{bot.custom_emotes['blank']}{bot.custom_emotes['gym_yellow']}**{yellow_count}**\n\n{locale['total']}: **{total_count}**\n{bot.custom_emotes['ex_pass']} {locale['ex_gyms']}: **{ex_count}** ({ex_odds}%)\n\n{bot.custom_emotes['raid']} {locale['active_raids']}: **{raid_count}**"
embed.description=text
await message.edit(embed=embed)
# Pie chart
sizes = [white_count, blue_count, red_count, yellow_count]
colors = ['lightgrey', '#42a5f5', '#ef5350', '#fdd835']
plt.pie(sizes, labels=None, colors=colors, autopct='', startangle=120, wedgeprops={"edgecolor":"black", 'linewidth':5, 'linestyle': 'solid', 'antialiased': True})
plt.axis('equal')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0)
plt.margins(0,0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.savefig('gym_stats.png', transparent=True, bbox_inches = 'tight', pad_inches = 0)
channel = await bot.fetch_channel(config['host_channel'])
image_msg = await channel.send(file=discord.File("gym_stats.png"))
image = image_msg.attachments[0].url
embed.set_footer(text="")
embed.description=text
embed.set_thumbnail(url=image)
embed.set_footer(text=footer_text)
await message.edit(embed=embed)
os.remove("gym_stats.png")
print("Done with Gym Stats")
@bot.event
async def on_ready():
print("Connected to Discord. Ready to take commands.")
bot.loop.create_task(board_loop())
bot.run(config['bot_token'])