From fb24a6b0b4763d27ed4760cda68e54d418250cba Mon Sep 17 00:00:00 2001 From: Dylan Sheffer Date: Fri, 24 Mar 2023 14:44:24 -0400 Subject: [PATCH 1/2] docs: add additional comments to the code --- berry_bot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/berry_bot.py b/berry_bot.py index df05ac4..75d1be0 100644 --- a/berry_bot.py +++ b/berry_bot.py @@ -3,11 +3,15 @@ import datetime from discord.ext import commands +# Initialize intents and bot intents = discord.Intents.all() intents.members = True bot = commands.Bot(command_prefix='!', intents=intents) + +# Initialize reminders dictionary reminders = {} +# Callback functions for reminders async def remind_leppa(member): await asyncio.sleep(60) await member.send(f'{member.mention} time to harvest your Leppa Berries!') @@ -20,20 +24,20 @@ async def remind_gracidea(member): if member.id in reminders: reminders[member.id].remove("gracidea") +# Function to schedule reminders async def schedule_reminder(member, delay, callback, reminder_name): - # Schedule the reminder to be sent after the specified delay await asyncio.sleep(delay) await callback(member) - # Remove the reminder from the dictionary after it has been completed if member.id in reminders and reminder_name in reminders[member.id]: reminders[member.id].remove(reminder_name) - +# Event to print bot's login name @bot.event async def on_ready(): print(f'Logged in as {bot.user.name}') +# Command to set a Leppa Berry reminder @bot.command() async def leppa(ctx): delay = 0.01 * 60 * 60 # 20 hours in seconds @@ -44,6 +48,7 @@ async def leppa(ctx): reminders[member.id].append("leppa") await schedule_reminder(member, delay, remind_leppa, "leppa") +# Command to set a Gracidea Flower reminder @bot.command() async def gracidea(ctx): delay = 44 * 60 * 60 # 44 hours in seconds @@ -54,6 +59,7 @@ async def gracidea(ctx): reminders[member.id].append("gracidea") await schedule_reminder(member, delay, remind_gracidea, "gracidea") +# Command to set a custom water reminder @bot.command() async def water(ctx, duration: int): delay = duration * 60 * 60 # Convert hours to seconds @@ -64,6 +70,7 @@ async def water(ctx, duration: int): reminders[member.id].append("water") await schedule_reminder(member, delay, lambda m: m.send(f"{m.mention} it's time to water your berries!"), "water") +# Command to list all active reminders @bot.command(name='reminders', help='Lists all the active reminders') async def list_reminders(ctx): member = ctx.author @@ -73,6 +80,7 @@ async def list_reminders(ctx): else: await ctx.send(f"{member.mention}, you have no active reminders.") +# Command to cancel all of a user's reminders @bot.command(name='cancel', help='Cancels the specified user\'s reminder') async def cancel(ctx, member: discord.Member): if member.id in reminders: @@ -83,3 +91,4 @@ async def cancel(ctx, member: discord.Member): # Run the bot bot.run("MTA4Nzc3NjgwMTI1MTY3NjE3MA.GkQkka.4XNUcvIjo3_ja2hVq90pEeyaZNX460G884XGVA") + From ddda738f3a0a7a1b4bedf5c00d23f2c81c94f1de Mon Sep 17 00:00:00 2001 From: Dylan Sheffer Date: Fri, 24 Mar 2023 14:54:09 -0400 Subject: [PATCH 2/2] docs: convert to markdown and expand on some docs --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README.txt | 34 ---------------------------------- 2 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 README.md delete mode 100644 README.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..42dd16d --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# [ROO] Berry Reminder Bot + +This is a simple Discord bot to help users set reminders for harvesting Leppa Berries and Gracidea Flowers, as well as watering their berries. + +The bot can be found at {TODO Add Link to Bot} + +## Usage + +### Commands + +- `!leppa`: Sets a reminder to harvest Leppa Berries in 20 hours. +- `!gracidea`: Sets a reminder to harvest Gracidea Flowers in 44 hours. +- `!water `: Sets a custom reminder to water berries in the specified duration (in hours). +- `!reminders`: Lists all active reminders for the user. +- `!cancel`: Cancels all active reminders for the user. + +### Example + +User: `!leppa` +Bot: `Reminding @User to harvest Leppa Berry in 20 hours` + +User: `!gracidea` +Bot: `Reminding @User to harvest Gracidea Flower in 44 hours` + +User: `!water 3` +Bot: `Reminding @User to water their berries in 3 hours` + +User: `!reminders` +Bot: `@User, you have the following active reminders: +leppa +gracidea +water` + +User: `!cancel` +Bot: `@User, all of your reminders have been cancelled.` + + +## Project Setup + +1. Install the required dependencies using pip: `pip install discord.py` +2. Replace `YOUR_TOKEN_HERE` in the last line of the code with your bot's token (or better yet, use an environment variable) + +### Running the Bot Locally + +To run the bot, simply execute the Python script: `python berry_reminder_bot.py` + + + + diff --git a/README.txt b/README.txt deleted file mode 100644 index a92c750..0000000 --- a/README.txt +++ /dev/null @@ -1,34 +0,0 @@ -ROO Reminder Bot Readme - -This bot is designed to help remind users to perform certain actions related to berries and flowers in a game. It uses Discord's API to communicate with users and schedule reminders. - -Usage -This bot has the following commands: - -!leppa -Reminds the user to harvest their Leppa Berries in 20 hours. - -Example usage: !leppa - -!gracidea -Reminds the user to harvest their Gracidea Flowers in 44 hours. - -Example usage: !gracidea - -!water duration -Reminds the user to water their berries after a specified duration (in hours). - -Example usage: !water 6 - -This will remind the user to water their berries in 6 hours. - -!reminders -Lists all of the user's active reminders. - -Example usage: !reminders - -!cancel @user -Cancels all of the specified user's active reminders. - -Example usage: !cancel @example-user -