Skip to content

Commit

Permalink
Merge pull request #18 from gustav-langer/main
Browse files Browse the repository at this point in the history
Add `!remove <DAY_NUMBER>` command
  • Loading branch information
bensonalec authored Dec 3, 2024
2 parents 01fbbad + 2f2707e commit d09a48c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ aka questions that haven't been asked yet but probably will be
| `!clb` | Prints out the custom leaderboard. This uses our custom Advent of Code scoring scheme. |
| `!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. |
| `!start <DAY_NUMBER>` | Start a day. This will set your starttime for our custom scoring. |
| `!remove <DAY_NUMBER>` | Remove your starttime for our custom scoring on a day. |
| `!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. |
| `!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. | |

Expand Down
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from src.schedule import scheduler, run_schedule
from src.register import run_register
from src.start import run_start
from src.remove import run_remove
from src.stats import run_stats
import discord
from logging import debug, info, warning, error, critical
Expand Down Expand Up @@ -64,6 +65,14 @@ async def start(ctx, arg):
if msg:
await ctx.message.channel.send(msg)

@bot.command()
async def remove(ctx, arg):
debug(f'cmd> {ctx.author}: remove {arg}')
async with data_mutex:
msg = await run_remove(ctx, arg)
if msg:
await ctx.message.channel.send(msg)

@bot.command()
async def schedule(ctx, *args):
debug(f'cmd> {ctx.author}: schedule {" ".join(args)}')
Expand All @@ -88,6 +97,7 @@ async def help(ctx, *args):
(f"`{COMMAND_PREFIX}clb`", "Prints out the custom leaderboard. This uses our custom advent of code scoring scheme.", False),
(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),
(f"`{COMMAND_PREFIX}start <DAY_NUMBER>`", "Start a day. This will set your starttime for our custom scoring.", False),
(f"`{COMMAND_PREFIX}remove <DAY_NUMBER>`", "Remove your starttime for our custom scoring on a day.", False),
(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),
(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),
]
Expand Down
23 changes: 23 additions & 0 deletions src/remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import shelve
from logging import critical, debug, error, info, warning


async def run_remove(ctx,arg):
return remove_session(arg, ctx.author)

def remove_session(day, author):
if(day.isnumeric()):
with shelve.open('hachikuji.mayoi') as db:
day = int(day) - 1
if str(author) not in db:
return "User not registered"
a = db[str(author)]
if a['start_times'][day] is None:
return "No session started."
else:
a['start_times'][day] = None
db[str(author)] = a
return f"You ({db[str(author)]['username']}) removed your start time for day {int(day) + 1}!"
else:
warning(f"invalid day {day}, day must be an integer")
return "Day must be an integer."

0 comments on commit d09a48c

Please sign in to comment.