Skip to content

Commit 30f9dc4

Browse files
Merge pull request #37 from RetroArcher/nightly
v0.0.3
2 parents 16075d0 + 9a953dc commit 30f9dc4

File tree

5 files changed

+90
-85
lines changed

5 files changed

+90
-85
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.0.3] - 2022-04-06
4+
### Fixed
5+
- Environment variable names switched to uppercase
6+
37
## [0.0.2] - 2022-04-04
48
### Added
59
- (Misc.) Workflow improvements

Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
FROM python:3.9.12-slim-bullseye
22

33
# Basic config
4-
ARG daily_tasks=true
5-
ARG daily_releases=true
6-
ARG daily_tasks_utc_hour=12
4+
ARG DAILY_TASKS=true
5+
ARG DAILY_RELEASES=true
6+
ARG DAILY_TASKS_UTC_HOUR=12
77

88
# Secret config
9-
ARG bot_token
10-
ARG daily_channel_id
11-
ARG gravatar_email
12-
ARG igdb_client_id
13-
ARG igdb_client_secret
9+
ARG BOT_TOKEN
10+
ARG DAILY_CHANNEL_ID
11+
ARG GRAVATAR_EMAIL
12+
ARG IGDB_CLIENT_ID
13+
ARG IGDB_CLIENT_SECRET
1414

1515
# Environment variables
16-
ENV daily_tasks=$DAILY_TASKS
17-
ENV daily_releases=$DAILY_RELEASES
18-
ENV daily_channel_id=$DAILY_CHANNEL_ID
19-
ENV daily_tasks_utc_hour=$DAILY_TASKS_UTC_HOUR
20-
ENV bot_token=$BOT_TOKEN
21-
ENV gravatar_email=$GRAVATAR_EMAIL
22-
ENV igdb_client_id=$IGDB_CLIENT_ID
23-
ENV igdb_client_secret=$IGDB_CLIENT_SECRET
16+
ENV DAILY_TASKS=$DAILY_TASKS
17+
ENV DAILY_RELEASES=$DAILY_RELEASES
18+
ENV DAILY_CHANNEL_ID=$DAILY_CHANNEL_ID
19+
ENV DAILY_TASKS_UTC_HOUR=$DAILY_TASKS_UTC_HOUR
20+
ENV BOT_TOKEN=$BOT_TOKEN
21+
ENV GRAVATAR_EMAIL=$GRAVATAR_EMAIL
22+
ENV IGDB_CLIENT_ID=$IGDB_CLIENT_ID
23+
ENV IGDB_CLIENT_SECRET=$IGDB_CLIENT_SECRET
2424

2525
COPY requirements.txt .
2626
COPY *.py .

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ This is a custom discord bot with some slash commands to help with support on th
2121
* Server Members Intent
2222
* Copy the `Token`
2323
* Add the following as environment variables or in a `.env` file (use `sample.env` as an example).
24-
:exclamation_mark: if using Docker these can be arguments.
24+
:exclamation: if using Docker these can be arguments.
2525
:warning: Never publicly expose your tokens, secrets, or ids.
2626

2727
| variable | required | default | description |
2828
| -------------------- | -------- | ------- | ------------------------------------------------------------- |
29-
| bot_token | True | None | Token from Bot page on discord developer portal. |
30-
| daily_tasks | False | true | Daily tasks on or off. |
31-
| daily_releases | False | true | Send a message for each game released on this day in history. |
32-
| daily_channel_id | False | None | Required if daily_tasks is enabled. |
33-
| daily_tasks_utc_hour | False | 12 | The hour to run daily tasks. |
34-
| gravatar_email | False | None | Gravatar email address for bot avatar. |
35-
| igdb_client_id | False | None | Required if daily_releases is enabled. |
36-
| igdb_client_secret | False | None | Required if daily_releases is enabled. |
29+
| BOT_TOKEN | True | None | Token from Bot page on discord developer portal. |
30+
| DAILY_TASKS | False | true | Daily tasks on or off. |
31+
| DAILY_RELEASES | False | true | Send a message for each game released on this day in history. |
32+
| DAILY_CHANNEL_ID | False | None | Required if daily_tasks is enabled. |
33+
| DAILY_TASKS_UTC_HOUR | False | 12 | The hour to run daily tasks. |
34+
| GRAVATAR_EMAIL | False | None | Gravatar email address for bot avatar. |
35+
| IGDB_CLIENT_ID | False | None | Required if daily_releases is enabled. |
36+
| IGDB_CLIENT_SECRET | False | None | Required if daily_releases is enabled. |
3737

3838
* Running bot:
3939
* `python discord_bot.py`

discord_bot.py

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import random
1010
import requests
1111
import sys
12-
import urllib
12+
from urllib import parse
1313

1414
# local imports
1515
import keep_alive
@@ -44,7 +44,6 @@ def get_bot_avatar(gravatar: str) -> str:
4444

4545
g = Gravatar(email=gravatar)
4646
image_url = g.get_image()
47-
print(image_url)
4847

4948
return image_url
5049

@@ -115,14 +114,14 @@ def post_json(url: str, headers: dict) -> dict:
115114

116115

117116
# constants
118-
bot_token = os.environ['bot_token']
117+
bot_token = os.environ['BOT_TOKEN']
119118
bot = discord.Bot(intents=discord.Intents.all(), auto_sync_commands=True)
120119

121120
bot_name = 'RetroArcher Bot'
122121
bot_url = 'https://RetroArcher.github.io'
123122

124-
# gravatar
125-
gravatar = get_bot_avatar(gravatar=os.environ['gravatar_email'])
123+
# avatar
124+
avatar = get_bot_avatar(gravatar=os.environ['GRAVATAR_EMAIL'])
126125

127126
# context reference
128127
# https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context
@@ -170,14 +169,14 @@ async def on_ready():
170169
)
171170

172171
try:
173-
os.environ['daily_tasks']
172+
os.environ['DAILY_TASKS']
174173
except KeyError:
175174
daily_task.start()
176175
else:
177-
if os.environ['daily_tasks'].lower() == 'true':
176+
if os.environ['DAILY_TASKS'].lower() == 'true':
178177
daily_task.start()
179178
else:
180-
print("'daily_tasks' environment variable is disabled")
179+
print("'DAILY_TASKS' environment variable is disabled")
181180

182181

183182
@bot.slash_command(name="help",
@@ -205,7 +204,7 @@ async def help_command(ctx):
205204
"""
206205

207206
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)
209208

210209
await ctx.respond(embed=embed)
211210

@@ -224,28 +223,32 @@ async def donate_command(ctx, user: Option(discord.Member, description='Select t
224223
embeds = []
225224

226225
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+
)
231231

232232
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+
)
237238

238239
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+
)
243245

244246
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+
)
249252

250253
if user:
251254
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
312315
quote = random.choice(seq=quote_list)
313316

314317
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)
316319

317320
if user:
318321
await ctx.respond(user.mention, embed=embed)
@@ -351,13 +354,13 @@ async def wiki_command(ctx,
351354

352355
git_user = 'RetroArcher'
353356
git_repo = 'RetroArcher.bundle'
354-
wiki_file = urllib.parse.quote(v)
357+
wiki_file = parse.quote(v)
355358
title = v.replace('-', ' ').replace('_', ' ').strip()
356359
color = 0xE5A00D
357360

358361
url, embed_message, color = discord_message(git_user=git_user, git_repo=git_repo, wiki_file=wiki_file, color=color)
359362
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)
361364

362365
if user:
363366
await ctx.respond(user.mention, embed=embed)
@@ -375,32 +378,32 @@ async def daily_task():
375378
if datetime.utcnow().hour == int(os.getenv(key='daily_tasks_utc_hour', default=12)):
376379
daily_releases = False
377380
try:
378-
os.environ['daily_releases']
381+
os.environ['DAILY_RELEASES']
379382
except KeyError:
380383
daily_releases = True
381384
else:
382-
if os.environ['daily_tasks'].lower() == 'true':
385+
if os.environ['DAILY_TASKS'].lower() == 'true':
383386
daily_releases = True
384387
else:
385-
print("'daily_releases' environment variable is disabled")
388+
print("'DAILY_RELEASES' environment variable is disabled")
386389

387390
if daily_releases:
388391
try:
389-
channel = bot.get_channel(int(os.environ['daily_channel_id']))
392+
channel = bot.get_channel(int(os.environ['DAILY_CHANNEL_ID']))
390393
except KeyError:
391-
print("'daily_channel_id' not defined in environment variables.")
394+
print("'DAILY_CHANNEL_ID' not defined in environment variables.")
392395
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'])
396399

397400
end_point = 'release_dates'
398401
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'
399402
where = f'human="{month_dictionary[datetime.utcnow().month]} {datetime.utcnow().day:02d}"*'
400403
limit = 500
401404
query = f'fields {fields}; where {where}; limit {limit};'
402405

403-
byte_array = wrapper.api_request(endpoint=end_point, query=query)
406+
byte_array = bytes(wrapper.api_request(endpoint=end_point, query=query))
404407
json_result = json.loads(byte_array)
405408
# print(json.dumps(json_result, indent=2))
406409

@@ -411,11 +414,11 @@ async def daily_task():
411414

412415
try:
413416
game_id = game['game']['id']
414-
except KeyError as e:
417+
except KeyError:
415418
continue
416419
else:
417420
if game_id not in game_ids:
418-
game_ids.append(__object=game_id)
421+
game_ids.append(game_id)
419422
else: # do not repeat the same game... even though it could be a different platform
420423
continue
421424

@@ -426,7 +429,7 @@ async def daily_task():
426429
description=game['game']['summary'][0:2000-1],
427430
color=color
428431
)
429-
except KeyError as e:
432+
except KeyError:
430433
continue
431434

432435
try:
@@ -435,7 +438,7 @@ async def daily_task():
435438
value=game['human'],
436439
inline=True
437440
)
438-
except KeyError as e:
441+
except KeyError:
439442
pass
440443

441444
try:
@@ -448,21 +451,21 @@ async def daily_task():
448451

449452
if rating < 4.0: # reduce number of messages per day
450453
continue
451-
except KeyError as e:
454+
except KeyError:
452455
continue
453456

454457
try:
455458
embed.set_thumbnail(
456459
url=f"https:{game['game']['cover']['url'].replace('_thumb', '_original')}"
457460
)
458-
except KeyError as e:
461+
except KeyError:
459462
pass
460463

461464
try:
462465
embed.set_image(
463466
url=f"https:{game['game']['artworks'][0]['url'].replace('_thumb', '_original')}"
464467
)
465-
except KeyError as e:
468+
except KeyError:
466469
pass
467470

468471
try:
@@ -480,7 +483,7 @@ async def daily_task():
480483
value=platforms,
481484
inline=False
482485
)
483-
except KeyError as e:
486+
except KeyError:
484487
pass
485488

486489
try:
@@ -498,16 +501,16 @@ async def daily_task():
498501
value=genres,
499502
inline=False
500503
)
501-
except KeyError as e:
504+
except KeyError:
502505
pass
503506

504507
try:
505508
embed.set_author(
506509
name=bot_name,
507510
url=bot_url,
508-
icon_url=gravatar
511+
icon_url=avatar
509512
)
510-
except KeyError as e:
513+
except KeyError:
511514
pass
512515

513516
embed.set_footer(
@@ -518,6 +521,8 @@ async def daily_task():
518521
message = await channel.send(embed=embed)
519522
thread = await message.create_thread(name=embed.title)
520523

524+
print(f'thread created: {thread.name}')
525+
521526
# to run in replit
522527
try:
523528
os.environ['REPL_SLUG']

sample.env

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# General settings
2-
daily_tasks=true
3-
daily_releases=true
4-
daily_channel_id=
5-
daily_tasks_utc_hour=12
2+
DAILY_TASKS=true
3+
DAILY_RELEASES=true
4+
DAILY_CHANNEL_ID=
5+
DAILY_TASKS_UTC_HOUR=12
66

77
# Secret settings
8-
bot_token=
9-
igdb_client_id=
10-
igdb_client_secret=
11-
12-
# Development settings
13-
# Fake these when running locally
14-
REPL_SLUG=
15-
REPL_OWNER=
8+
BOT_TOKEN=
9+
GRAVATAR_EMAIL=
10+
IGDB_CLIENT_ID=
11+
IGDB_CLIENT_SECRET=

0 commit comments

Comments
 (0)