9
9
import random
10
10
import requests
11
11
import sys
12
- import urllib
12
+ from urllib import parse
13
13
14
14
# local imports
15
15
import keep_alive
@@ -44,7 +44,6 @@ def get_bot_avatar(gravatar: str) -> str:
44
44
45
45
g = Gravatar (email = gravatar )
46
46
image_url = g .get_image ()
47
- print (image_url )
48
47
49
48
return image_url
50
49
@@ -115,14 +114,14 @@ def post_json(url: str, headers: dict) -> dict:
115
114
116
115
117
116
# constants
118
- bot_token = os .environ ['bot_token ' ]
117
+ bot_token = os .environ ['BOT_TOKEN ' ]
119
118
bot = discord .Bot (intents = discord .Intents .all (), auto_sync_commands = True )
120
119
121
120
bot_name = 'RetroArcher Bot'
122
121
bot_url = 'https://RetroArcher.github.io'
123
122
124
- # gravatar
125
- gravatar = get_bot_avatar (gravatar = os .environ ['gravatar_email ' ])
123
+ # avatar
124
+ avatar = get_bot_avatar (gravatar = os .environ ['GRAVATAR_EMAIL ' ])
126
125
127
126
# context reference
128
127
# https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context
@@ -170,14 +169,14 @@ async def on_ready():
170
169
)
171
170
172
171
try :
173
- os .environ ['daily_tasks ' ]
172
+ os .environ ['DAILY_TASKS ' ]
174
173
except KeyError :
175
174
daily_task .start ()
176
175
else :
177
- if os .environ ['daily_tasks ' ].lower () == 'true' :
176
+ if os .environ ['DAILY_TASKS ' ].lower () == 'true' :
178
177
daily_task .start ()
179
178
else :
180
- print ("'daily_tasks ' environment variable is disabled" )
179
+ print ("'DAILY_TASKS ' environment variable is disabled" )
181
180
182
181
183
182
@bot .slash_command (name = "help" ,
@@ -205,7 +204,7 @@ async def help_command(ctx):
205
204
"""
206
205
207
206
embed = discord .Embed (description = description , color = 0xE5A00D )
208
- embed .set_footer (text = 'RetroArcher Bot' , icon_url = gravatar )
207
+ embed .set_footer (text = 'RetroArcher Bot' , icon_url = avatar )
209
208
210
209
await ctx .respond (embed = embed )
211
210
@@ -224,28 +223,32 @@ async def donate_command(ctx, user: Option(discord.Member, description='Select t
224
223
embeds = []
225
224
226
225
embeds .append (discord .Embed (color = 0x333 ))
227
- embeds [- 1 ].set_author (name = 'Github Sponsors' ,
228
- url = 'https://github.com/sponsors/ReenigneArcher' ,
229
- icon_url = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
230
- )
226
+ embeds [- 1 ].set_author (
227
+ name = 'Github Sponsors' ,
228
+ url = 'https://github.com/sponsors/ReenigneArcher' ,
229
+ icon_url = 'https://github.com/fluidicon.png'
230
+ )
231
231
232
232
embeds .append (discord .Embed (description = 'Includes Discord benefits.' , color = 0x60D1F6 ))
233
- embeds [- 1 ].set_author (name = 'MEE6' ,
234
- url = 'https://mee6.xyz/m/804382334370578482' ,
235
- icon_url = 'https://mee6.xyz/icons-decf734e1b14376075878ea568aa8d3b/apple-touch-icon-180x180.png'
236
- )
233
+ embeds [- 1 ].set_author (
234
+ name = 'MEE6' ,
235
+ url = 'https://mee6.xyz/m/804382334370578482' ,
236
+ icon_url = 'https://mee6.xyz/icons-decf734e1b14376075878ea568aa8d3b/apple-touch-icon-180x180.png'
237
+ )
237
238
238
239
embeds .append (discord .Embed (description = 'Includes Discord benefits.' , color = 0xf96854 ))
239
- embeds [- 1 ].set_author (name = 'Patreon' ,
240
- url = 'https://www.patreon.com/RetroArcher' ,
241
- icon_url = 'https://th.bing.com/th/id/OIP.suF0Aufc2rX2gzgPB2mXpAHaHa?pid=ImgDet&rs=1'
242
- )
240
+ embeds [- 1 ].set_author (
241
+ name = 'Patreon' ,
242
+ url = 'https://www.patreon.com/RetroArcher' ,
243
+ icon_url = 'https://c5.patreon.com/external/favicon/apple-touch-icon.png?v=jw6AR4Rg74'
244
+ )
243
245
244
246
embeds .append (discord .Embed (color = 0x003087 ))
245
- embeds [- 1 ].set_author (name = 'PayPal' ,
246
- url = 'https://paypal.me/ReenigneArcher' ,
247
- icon_url = 'https://img.etimg.com/thumb/msid-60762134,width-300,imgsize-9757,resizemode-4/paypal-reduces-remittance-certificate-charges-by-50-for-small-sellers.jpg'
248
- )
247
+ embeds [- 1 ].set_author (
248
+ name = 'PayPal' ,
249
+ url = 'https://paypal.me/ReenigneArcher' ,
250
+ icon_url = 'https://www.paypalobjects.com/webstatic/icon/pp196.png'
251
+ )
249
252
250
253
if user :
251
254
await ctx .respond (f'Thank you for your support { user .mention } !' ,
@@ -312,7 +315,7 @@ async def random_command(ctx, user: Option(discord.Member, description='Select t
312
315
quote = random .choice (seq = quote_list )
313
316
314
317
embed = discord .Embed (description = quote , color = 0xE5A00D )
315
- embed .set_footer (text = 'RetroArcher Bot' , icon_url = gravatar )
318
+ embed .set_footer (text = 'RetroArcher Bot' , icon_url = avatar )
316
319
317
320
if user :
318
321
await ctx .respond (user .mention , embed = embed )
@@ -351,13 +354,13 @@ async def wiki_command(ctx,
351
354
352
355
git_user = 'RetroArcher'
353
356
git_repo = 'RetroArcher.bundle'
354
- wiki_file = urllib . parse .quote (v )
357
+ wiki_file = parse .quote (v )
355
358
title = v .replace ('-' , ' ' ).replace ('_' , ' ' ).strip ()
356
359
color = 0xE5A00D
357
360
358
361
url , embed_message , color = discord_message (git_user = git_user , git_repo = git_repo , wiki_file = wiki_file , color = color )
359
362
embed = discord .Embed (title = title , url = url , description = embed_message , color = color )
360
- embed .set_footer (text = 'RetroArcher Bot' , icon_url = gravatar )
363
+ embed .set_footer (text = 'RetroArcher Bot' , icon_url = avatar )
361
364
362
365
if user :
363
366
await ctx .respond (user .mention , embed = embed )
@@ -375,32 +378,32 @@ async def daily_task():
375
378
if datetime .utcnow ().hour == int (os .getenv (key = 'daily_tasks_utc_hour' , default = 12 )):
376
379
daily_releases = False
377
380
try :
378
- os .environ ['daily_releases ' ]
381
+ os .environ ['DAILY_RELEASES ' ]
379
382
except KeyError :
380
383
daily_releases = True
381
384
else :
382
- if os .environ ['daily_tasks ' ].lower () == 'true' :
385
+ if os .environ ['DAILY_TASKS ' ].lower () == 'true' :
383
386
daily_releases = True
384
387
else :
385
- print ("'daily_releases ' environment variable is disabled" )
388
+ print ("'DAILY_RELEASES ' environment variable is disabled" )
386
389
387
390
if daily_releases :
388
391
try :
389
- channel = bot .get_channel (int (os .environ ['daily_channel_id ' ]))
392
+ channel = bot .get_channel (int (os .environ ['DAILY_CHANNEL_ID ' ]))
390
393
except KeyError :
391
- print ("'daily_channel_id ' not defined in environment variables." )
394
+ print ("'DAILY_CHANNEL_ID ' not defined in environment variables." )
392
395
else :
393
- igdb_auth = igdb_authorization (client_id = os .environ ['igdb_client_id ' ],
394
- client_secret = os .environ ['igdb_client_secret ' ])
395
- wrapper = IGDBWrapper (client_id = os .environ ['igdb_client_id ' ], auth_token = igdb_auth ['access_token' ])
396
+ igdb_auth = igdb_authorization (client_id = os .environ ['IGDB_CLIENT_ID ' ],
397
+ client_secret = os .environ ['IGDB_CLIENT_SECRET ' ])
398
+ wrapper = IGDBWrapper (client_id = os .environ ['IGDB_CLIENT_ID ' ], auth_token = igdb_auth ['access_token' ])
396
399
397
400
end_point = 'release_dates'
398
401
fields = 'human, game.name, game.summary, game.url, game.genres.name, game.rating, game.cover.url, game.artworks.url, game.platforms.name, game.platforms.url'
399
402
where = f'human="{ month_dictionary [datetime .utcnow ().month ]} { datetime .utcnow ().day :02d} "*'
400
403
limit = 500
401
404
query = f'fields { fields } ; where { where } ; limit { limit } ;'
402
405
403
- byte_array = wrapper .api_request (endpoint = end_point , query = query )
406
+ byte_array = bytes ( wrapper .api_request (endpoint = end_point , query = query ) )
404
407
json_result = json .loads (byte_array )
405
408
# print(json.dumps(json_result, indent=2))
406
409
@@ -411,11 +414,11 @@ async def daily_task():
411
414
412
415
try :
413
416
game_id = game ['game' ]['id' ]
414
- except KeyError as e :
417
+ except KeyError :
415
418
continue
416
419
else :
417
420
if game_id not in game_ids :
418
- game_ids .append (__object = game_id )
421
+ game_ids .append (game_id )
419
422
else : # do not repeat the same game... even though it could be a different platform
420
423
continue
421
424
@@ -426,7 +429,7 @@ async def daily_task():
426
429
description = game ['game' ]['summary' ][0 :2000 - 1 ],
427
430
color = color
428
431
)
429
- except KeyError as e :
432
+ except KeyError :
430
433
continue
431
434
432
435
try :
@@ -435,7 +438,7 @@ async def daily_task():
435
438
value = game ['human' ],
436
439
inline = True
437
440
)
438
- except KeyError as e :
441
+ except KeyError :
439
442
pass
440
443
441
444
try :
@@ -448,21 +451,21 @@ async def daily_task():
448
451
449
452
if rating < 4.0 : # reduce number of messages per day
450
453
continue
451
- except KeyError as e :
454
+ except KeyError :
452
455
continue
453
456
454
457
try :
455
458
embed .set_thumbnail (
456
459
url = f"https:{ game ['game' ]['cover' ]['url' ].replace ('_thumb' , '_original' )} "
457
460
)
458
- except KeyError as e :
461
+ except KeyError :
459
462
pass
460
463
461
464
try :
462
465
embed .set_image (
463
466
url = f"https:{ game ['game' ]['artworks' ][0 ]['url' ].replace ('_thumb' , '_original' )} "
464
467
)
465
- except KeyError as e :
468
+ except KeyError :
466
469
pass
467
470
468
471
try :
@@ -480,7 +483,7 @@ async def daily_task():
480
483
value = platforms ,
481
484
inline = False
482
485
)
483
- except KeyError as e :
486
+ except KeyError :
484
487
pass
485
488
486
489
try :
@@ -498,16 +501,16 @@ async def daily_task():
498
501
value = genres ,
499
502
inline = False
500
503
)
501
- except KeyError as e :
504
+ except KeyError :
502
505
pass
503
506
504
507
try :
505
508
embed .set_author (
506
509
name = bot_name ,
507
510
url = bot_url ,
508
- icon_url = gravatar
511
+ icon_url = avatar
509
512
)
510
- except KeyError as e :
513
+ except KeyError :
511
514
pass
512
515
513
516
embed .set_footer (
@@ -518,6 +521,8 @@ async def daily_task():
518
521
message = await channel .send (embed = embed )
519
522
thread = await message .create_thread (name = embed .title )
520
523
524
+ print (f'thread created: { thread .name } ' )
525
+
521
526
# to run in replit
522
527
try :
523
528
os .environ ['REPL_SLUG' ]
0 commit comments