From 60ba3ee1a80b7aca3af83f6d10f5af93b1863d14 Mon Sep 17 00:00:00 2001 From: ByteCommander Date: Mon, 3 Dec 2018 01:20:17 +0100 Subject: Split .notifications toggle command into .subscribe and .unsubscribe --- bot/seasons/christmas/adventofcode.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'bot/seasons/christmas/adventofcode.py') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 4c766703..b428896b 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -130,23 +130,35 @@ class AdventOfCode: await ctx.invoke(self.bot.get_command("help"), "adventofcode") - @adventofcode_group.command(name="notifications", aliases=("notify", "notifs"), brief="Notifications for new days") - async def aoc_notifications(self, ctx: commands.Context): + @adventofcode_group.command(name="subscribe", + aliases=("sub", "notifications", "notify", "notifs"), + brief="Notifications for new days") + async def aoc_subscribe(self, ctx: commands.Context): """ Assign the role for notifications about new days being ready. + """ + role = ctx.guild.get_role(AocConfig.role_id) - Call the same command again to end notifications and remove the role. + if role not in ctx.author.roles: + await ctx.author.add_roles(role) + await ctx.send("Okay! You have been __subscribed__ to notifications about new Advent of Code tasks. " + f"You can run `{ctx.prefix}unsubscribe` to disable them again for you.") + else: + await ctx.send("Hey, you already are receiving notifications about new Advent of Code tasks. " + f"If you don't want them any more, run `{ctx.prefix}unsubscribe` instead.") + + @adventofcode_group.command(name="unsubscribe", aliases=("unsub"), brief="Notifications for new days") + async def aoc_unsubscribe(self, ctx: commands.Context): + """ + Remove the role for notifications about new days being ready. """ role = ctx.guild.get_role(AocConfig.role_id) if role in ctx.author.roles: await ctx.author.remove_roles(role) - await ctx.send("Okay! You have been unsubscribed from notifications. If in future you want to" - " resubscribe just run this command again.") + await ctx.send("Okay! You have been __unsubscribed__ from notifications about new Advent of Code tasks.") else: - await ctx.author.add_roles(role) - await ctx.send("Okay! You have been subscribed to notifications about new Advent of Code tasks." - " To unsubscribe in future run the same command again.") + await ctx.send("Hey, you don't even get any notifications about new Advent of Code tasks currently anyway.") @adventofcode_group.command(name="countdown", aliases=("count", "c"), brief="Return time left until next day") async def aoc_countdown(self, ctx: commands.Context): -- cgit v1.2.3 From 80e12b556ea605fd2a41330839c4ab159612b658 Mon Sep 17 00:00:00 2001 From: ByteCommander Date: Mon, 3 Dec 2018 03:00:00 +0100 Subject: Various fixes from review (squished) --- bot/seasons/christmas/adventofcode.py | 7 ++++--- 1 file changed, 4 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 b428896b..527697f2 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -138,16 +138,17 @@ class AdventOfCode: Assign the role for notifications about new days being ready. """ role = ctx.guild.get_role(AocConfig.role_id) + unsubscribe_command = f"{ctx.prefix}{ctx.command.root_parent} unsubscribe" if role not in ctx.author.roles: await ctx.author.add_roles(role) await ctx.send("Okay! You have been __subscribed__ to notifications about new Advent of Code tasks. " - f"You can run `{ctx.prefix}unsubscribe` to disable them again for you.") + f"You can run `{unsubscribe_command}` to disable them again for you.") else: await ctx.send("Hey, you already are receiving notifications about new Advent of Code tasks. " - f"If you don't want them any more, run `{ctx.prefix}unsubscribe` instead.") + f"If you don't want them any more, run `{unsubscribe_command}` instead.") - @adventofcode_group.command(name="unsubscribe", aliases=("unsub"), brief="Notifications for new days") + @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") async def aoc_unsubscribe(self, ctx: commands.Context): """ Remove the role for notifications about new days being ready. -- cgit v1.2.3 From 7bb80935eec880ad27279fbc45d2ffb54475d849 Mon Sep 17 00:00:00 2001 From: ByteCommander Date: Mon, 3 Dec 2018 23:48:14 +0100 Subject: Adapt code style according to review --- bot/seasons/christmas/adventofcode.py | 8 +++++--- 1 file changed, 5 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 527697f2..e9726752 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -130,9 +130,11 @@ class AdventOfCode: await ctx.invoke(self.bot.get_command("help"), "adventofcode") - @adventofcode_group.command(name="subscribe", - aliases=("sub", "notifications", "notify", "notifs"), - brief="Notifications for new days") + @adventofcode_group.command( + name="subscribe", + aliases=("sub", "notifications", "notify", "notifs"), + brief="Notifications for new days" + ) async def aoc_subscribe(self, ctx: commands.Context): """ Assign the role for notifications about new days being ready. -- cgit v1.2.3