From 0de62cc2ba50b2cef6e998cc797aaba1685d50b1 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 16:46:06 -0500 Subject: Refactor aoc join to DM user with join code --- bot/seasons/christmas/adventofcode.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 458eb19f..b61e77c0 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -19,6 +19,7 @@ log = logging.getLogger(__name__) AOC_REQUEST_HEADER = {"user-agent": "PythonDiscord AoC Event Bot"} AOC_SESSION_COOKIE = {"session": Tokens.aoc_session_cookie} +AOC_JOIN_CODE = AocConfig.leaderboard_join_code # Constant so staff can update without redeploying EST = timezone("EST") COUNTDOWN_STEP = 60 * 5 @@ -196,14 +197,23 @@ class AdventOfCode: @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join PyDis' private AoC leaderboard") async def join_leaderboard(self, ctx: commands.Context): """ - Retrieve the link to join the PyDis AoC private leaderboard + DM the user the information for joining the PyDis AoC private leaderboard """ + author = ctx.message.author + log.info(f"{author.name} ({author.id}) has requested the PyDis AoC leaderboard code") + info_str = ( "Head over to https://adventofcode.com/leaderboard/private " - f"with code `{AocConfig.leaderboard_join_code}` to join the PyDis private leaderboard!" + f"with code `{AOC_JOIN_CODE}` to join the PyDis private leaderboard!" ) - await ctx.send(info_str) + try: + await author.send(info_str) + except discord.errors.Forbidden: + log.debug(f"{author.name} ({author.id}) has disabled DMs from server members") + await ctx.send( + f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' + ) @adventofcode_group.command( name="leaderboard", -- cgit v1.2.3 From acde36e17e0a3365f5db7357d76b5a9c8ddc0ff2 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 17:30:01 -0500 Subject: Add staff command to change AoC leaderboard join code --- bot/seasons/christmas/adventofcode.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index b61e77c0..0d4fd966 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,7 +13,8 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Tokens +from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Roles, Tokens +from bot.decorators import with_role log = logging.getLogger(__name__) @@ -215,6 +216,20 @@ class AdventOfCode: f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' ) + @with_role(Roles.admin, Roles.owner) + @adventofcode_group.command(name="changecode", hidden=True) + async def update_aoc_join_code(self, ctx: commands.Context, new_code: str): + """ + Staff command to update the AoC join code constant locally to allow for the code to be updated + on regeneration without having to redeploy the bot + """ + + author = ctx.message.author + log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") + + global AOC_JOIN_CODE # Necessary (probably?) evil to update the code without redeploying + AOC_JOIN_CODE = new_code + @adventofcode_group.command( name="leaderboard", aliases=("board", "lb"), -- cgit v1.2.3 From ebe67c3b469a52a1f4b4bcb2a6c2f231c30cfdd1 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 17:34:38 -0500 Subject: Remove extraneous whitespace --- bot/seasons/christmas/adventofcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 0d4fd966..056c36ab 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -223,7 +223,7 @@ class AdventOfCode: Staff command to update the AoC join code constant locally to allow for the code to be updated on regeneration without having to redeploy the bot """ - + author = ctx.message.author log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") -- cgit v1.2.3 From 191d8abceabff5b442cf1e0ce0aa5fe238520341 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 26 Dec 2018 10:00:08 -0500 Subject: Remove local env var modification command --- bot/seasons/christmas/adventofcode.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 056c36ab..113f959d 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -20,7 +20,6 @@ log = logging.getLogger(__name__) AOC_REQUEST_HEADER = {"user-agent": "PythonDiscord AoC Event Bot"} AOC_SESSION_COOKIE = {"session": Tokens.aoc_session_cookie} -AOC_JOIN_CODE = AocConfig.leaderboard_join_code # Constant so staff can update without redeploying EST = timezone("EST") COUNTDOWN_STEP = 60 * 5 @@ -206,7 +205,7 @@ class AdventOfCode: info_str = ( "Head over to https://adventofcode.com/leaderboard/private " - f"with code `{AOC_JOIN_CODE}` to join the PyDis private leaderboard!" + f"with code `{AocConfig.leaderboard_join_code}` to join the PyDis private leaderboard!" ) try: await author.send(info_str) @@ -216,20 +215,6 @@ class AdventOfCode: f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' ) - @with_role(Roles.admin, Roles.owner) - @adventofcode_group.command(name="changecode", hidden=True) - async def update_aoc_join_code(self, ctx: commands.Context, new_code: str): - """ - Staff command to update the AoC join code constant locally to allow for the code to be updated - on regeneration without having to redeploy the bot - """ - - author = ctx.message.author - log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") - - global AOC_JOIN_CODE # Necessary (probably?) evil to update the code without redeploying - AOC_JOIN_CODE = new_code - @adventofcode_group.command( name="leaderboard", aliases=("board", "lb"), -- cgit v1.2.3 From 01470fc31cd429164a7c314f01fb5b3c81f600d2 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 26 Dec 2018 10:01:30 -0500 Subject: Remove unused imports --- bot/seasons/christmas/adventofcode.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 113f959d..e9853222 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,8 +13,7 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Roles, Tokens -from bot.decorators import with_role +from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Tokens log = logging.getLogger(__name__) -- cgit v1.2.3 From 00dbe8b2cb64991102be0e242d3e54175d207814 Mon Sep 17 00:00:00 2001 From: sco1 Date: Sat, 5 Jan 2019 14:09:12 -0500 Subject: Review-directed reformatting --- bot/seasons/christmas/adventofcode.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index e9853222..f0e4f0da 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -210,9 +210,7 @@ class AdventOfCode: await author.send(info_str) except discord.errors.Forbidden: log.debug(f"{author.name} ({author.id}) has disabled DMs from server members") - await ctx.send( - f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' - ) + await ctx.send(f":x: {author.mention}, please (temporarily) enable DMs to receive the join code") @adventofcode_group.command( name="leaderboard", -- cgit v1.2.3