Skip to content

Commit d09a48c

Browse files
authored
Merge pull request #18 from gustav-langer/main
Add `!remove <DAY_NUMBER>` command
2 parents 01fbbad + 2f2707e commit d09a48c

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ aka questions that haven't been asked yet but probably will be
5656
| `!clb` | Prints out the custom leaderboard. This uses our custom Advent of Code scoring scheme. |
5757
| `!register [AOC_USERNAME]` | When called without argument it will print all Discord users registered on the leaderboard. When called with argument (your name on the Advent of Code leaderboard), it will associate your Discord ID with that username. |
5858
| `!start <DAY_NUMBER>` | Start a day. This will set your starttime for our custom scoring. |
59+
| `!remove <DAY_NUMBER>` | Remove your starttime for our custom scoring on a day. |
5960
| `!schedule [<+/-><MINUTES>]` | Can be called without an argument, if so will print the next scheduled send time. With an argument, will schedule a time for the leaderboard to send automatically. Takes in a indicator (either + or -) and an integer (minutes) and sends the leaderboard at the start time of the competition for that day (midnight EST), given that offset. |
6061
| `!stats [AOC_USERNAME]` | Send individual stats for a user. Can be called with and without an argument, without an argument it will use the account that is registered with your user. | |
6162

main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from src.schedule import scheduler, run_schedule
88
from src.register import run_register
99
from src.start import run_start
10+
from src.remove import run_remove
1011
from src.stats import run_stats
1112
import discord
1213
from logging import debug, info, warning, error, critical
@@ -64,6 +65,14 @@ async def start(ctx, arg):
6465
if msg:
6566
await ctx.message.channel.send(msg)
6667

68+
@bot.command()
69+
async def remove(ctx, arg):
70+
debug(f'cmd> {ctx.author}: remove {arg}')
71+
async with data_mutex:
72+
msg = await run_remove(ctx, arg)
73+
if msg:
74+
await ctx.message.channel.send(msg)
75+
6776
@bot.command()
6877
async def schedule(ctx, *args):
6978
debug(f'cmd> {ctx.author}: schedule {" ".join(args)}')
@@ -88,6 +97,7 @@ async def help(ctx, *args):
8897
(f"`{COMMAND_PREFIX}clb`", "Prints out the custom leaderboard. This uses our custom advent of code scoring scheme.", False),
8998
(f"`{COMMAND_PREFIX}register [AOC_USERNAME]`", "Associate yourself with given AoC user. Without argument will print out the list of registered users. With argument, will register your discord ID with your Advent of Code username for custom scoring.", False),
9099
(f"`{COMMAND_PREFIX}start <DAY_NUMBER>`", "Start a day. This will set your starttime for our custom scoring.", False),
100+
(f"`{COMMAND_PREFIX}remove <DAY_NUMBER>`", "Remove your starttime for our custom scoring on a day.", False),
91101
(f"`{COMMAND_PREFIX}schedule [<+/-><MINUTES>]`", "Can be called without an argument, if so will print the next scheduled send time. With an argument, will schedule a time for the leaderboard to send automatically. Takes in a indicator (either + or -) and an integer (minutes) and sends the leaderboard at the start time of the competition for that day (midnight EST), given that offset.", False),
92102
(f"`{COMMAND_PREFIX}stats [AOC_USERNAME]`", "Send individual stats for a user. Can be called with and without an argument, without an argument it will use the account that is registered with your user.", False),
93103
]

src/remove.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import shelve
2+
from logging import critical, debug, error, info, warning
3+
4+
5+
async def run_remove(ctx,arg):
6+
return remove_session(arg, ctx.author)
7+
8+
def remove_session(day, author):
9+
if(day.isnumeric()):
10+
with shelve.open('hachikuji.mayoi') as db:
11+
day = int(day) - 1
12+
if str(author) not in db:
13+
return "User not registered"
14+
a = db[str(author)]
15+
if a['start_times'][day] is None:
16+
return "No session started."
17+
else:
18+
a['start_times'][day] = None
19+
db[str(author)] = a
20+
return f"You ({db[str(author)]['username']}) removed your start time for day {int(day) + 1}!"
21+
else:
22+
warning(f"invalid day {day}, day must be an integer")
23+
return "Day must be an integer."

0 commit comments

Comments
 (0)