diff --git a/.env.sample b/.env.sample index 6d13a74..2ea97d6 100644 --- a/.env.sample +++ b/.env.sample @@ -1,3 +1,4 @@ DISCORD_TOKEN="" # Discord Bot Application Token MONGO_URI="" # Mongo Connection URI string PREFIX="" +DISCORD_GUILD_ID="" # ID of the guild this bot is supposed to run in. diff --git a/README.md b/README.md index c9d5a4d..a706fed 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,7 @@ I did something on Saturday. I also did some work on Sunday, and implemented XYZ. ``` -- The bot would also send a weekly reminder to everyone in the bot's DB, to remind them that they need to report their progress for this week. - +- The bot also sends a weekly reminder to everyone in the bot's DB, to remind them that they need to report their progress for this week. These are optional, and can be opted out of. - Bonus: The bot keeps track of whether the person sticks to what they say they will do by checking if they received a checkmark emoji on their report from the guild leader or "verifier". ## How to contribute to this project? @@ -78,6 +77,11 @@ This might be slightly confusing at first, due to the large amounts of ways of s ``` DISCORD_TOKEN="the token you just copied" ``` +- It would be recommended that you set up a new test discord server, and invite the bot there. Also, you would have to turn on Developer Mode on discord(If you don't know how to do that, you can find out [here](https://helpdeskgeek.com/how-to/how-to-enable-and-use-developer-mode-on-discord/)). After doing that you can go to your server, right click on the server icon and click on `Copy ID` to copy the copy the `DISCORD_GUILD_ID` from there. + Open the `.env` file, and set the value- + ``` + DISCORD_GUILD_ID="" + ``` - Inviting this test-discord-bot to your server: Go to the `General Information` tab on that bot's dashboard on Discord Developers Portal, and copy the bot's Client ID: Replace `` in below with the Client ID you just copied- ``` @@ -85,7 +89,6 @@ This might be slightly confusing at first, due to the large amounts of ways of s ``` Visit the link, and add this bot to a test server. - #### **B. Set up the dev environment** This project adds some tools and dependencies to the project, so that it is easier for you to pass the CI, and checks on the repo, and also to maintain some amount of clean formatting and clean code. This would also add some pre-push hooks to your project. diff --git a/src/bot.py b/src/bot.py index 56d9aca..9b2137d 100644 --- a/src/bot.py +++ b/src/bot.py @@ -10,6 +10,7 @@ class Bot(commands.Bot): def __init__(self): intents = Intents.default() intents.members = True + intents.reactions = True super().__init__( command_prefix=consts.PREFIX, case_insensitive=True, intents=intents diff --git a/src/cogs/helpers.py b/src/cogs/helpers.py deleted file mode 100644 index eb93b62..0000000 --- a/src/cogs/helpers.py +++ /dev/null @@ -1,79 +0,0 @@ -from discord import Embed -from discord.ext import commands -from discord.ext.commands import Cog, Context - -from src.consts import META, Colo - - -def HelpEmbed(title="Help", description="\u200b"): - return Embed(title=title, description=description, color=Colo.purple) - - -class CustomHelpCommand(commands.HelpCommand): - def get_cmd_usage(self, command): - cmd = "%s%s %s" % (self.clean_prefix, command.qualified_name, command.signature) - return f"`{cmd.strip()}`" - - def get_help_text(self, command): - usage = self.get_cmd_usage(command) - return usage, command.short_doc - - async def send_bot_help(self, mapping): - embed = HelpEmbed() - for cog, cmds in mapping.items(): - filtered_cmds = await self.filter_commands(cmds, sort=True) - cmd_data = [self.get_cmd_usage(cmd) for cmd in filtered_cmds] - if cmd_data: - cog_name = getattr(cog, "qualified_name", "No Category") - cmd_data = "\n".join(cmd_data) - embed.add_field( - name=cog_name, value=f"{cog.description}\n{cmd_data}", inline=False - ) - await self.context.send(embed=embed) - - async def send_command_help(self, command): - embed = HelpEmbed(title=self.get_cmd_usage(command)) - embed.add_field(name="Help for `{command.name}`", value=command.short_doc) - aliases = command.aliases - if aliases: - embed.add_field(name="Aliases", value=", ".join(aliases), inline=False) - await self.context.send(embed=embed) - - async def send_cog_help(self, cog): - cog_name = getattr(cog, "qualified_name", "No Category") - embed = HelpEmbed( - f"Help for Category: `{cog_name}`", - f"Use `^help command` for more info on a command\n\n{cog.description}", - ) - cmds = [ - self.get_help_text(c) - for c in await self.filter_commands(cog.walk_commands(), sort=True) - ] - if cmds: - for cmd in cmds: - embed.add_field( - name=cmd[0], value=f"{cog.description}{cmd[1]}", inline=False - ) - await self.context.send(embed=embed) - - -class Helpers(Cog): - """Help command and some other helper commands""" - - def __init__(self, bot): - bot._default_help_command = bot.help_command - bot.help_command = CustomHelpCommand() - bot.help_command.cog = self - self.bot = bot - - @Cog.listener() - async def on_ready(self): - print("Bot is online! Currently running version - v%s" % META["version"]) - - @commands.command() - async def ping(self, ctx: Context): - await ctx.send("Pong! Running version - v%s" % META["version"]) - - -def setup(bot): - bot.add_cog(Helpers(bot)) diff --git a/src/cogs/standup.py b/src/cogs/standup.py deleted file mode 100644 index b3615e6..0000000 --- a/src/cogs/standup.py +++ /dev/null @@ -1,130 +0,0 @@ -from datetime import datetime - -from discord import Color, Embed -from discord.ext import commands -from discord.ext.commands import Cog, Context -from motor.motor_asyncio import AsyncIOMotorClient as MotorClient - -from src.consts import MONGO_URI - - -def formatted(ctx: Context, tasks: str): - data = { - "approved": False, - "date_reported": ctx.message.created_at.timestamp(), - "last_edited": ctx.message.created_at.timestamp(), - } - data["tasks"] = tasks.split("\n") - return data - - -class Standup(Cog): - def __init__(self, bot): - self.bot = bot - self.DB = MotorClient(MONGO_URI).players.tasks - self.messages = [] - - @Cog.listener() - async def on_reaction_add(self, reaction, user): - if reaction.emoji == "👍" and str(reaction.message.id) in self.messages: - record = await self.DB.find_one({"_id": str(user.id)}) - field = f"data.{len(record['data']) - 1}.approved" - await self.DB.update_one(record, {"$set": {field: True}}) - await reaction.message.channel.send("Your tasks just got verified") - - @commands.group(invoke_without_command=True, case_insensitive=True) - async def standup(self, ctx: Context, *, content: str): - """Standup Commands Group. Stores tasks from standup messages""" - await self.create(ctx, tasks=content) - - @standup.command() - async def create(self, ctx: Context, *, tasks: str): - """Command for creating standups and storing tasks""" - record = await self.DB.find_one({"_id": str(ctx.author.id)}) - - tasks = formatted(ctx, tasks) - - if record: - data = record["data"] + [tasks] - await self.DB.update_one(record, {"$set": {"data": data}}) - else: - self.DB.insert_one( - {"_id": str(ctx.author.id), "alerts": True, "data": [tasks]} - ) - tasks = "\n".join(tasks["tasks"]) - await ctx.author.send(f"Successfully submitted your tasks:\n{tasks}") - self.messages.append(str(ctx.message.id)) - - @standup.command() - async def log(self, ctx: Context): - """Command for showing latest standup""" - record = await self.DB.find_one({"_id": str(ctx.author.id)}) - if record: - data = record["data"][-1] - tasks = "\n".join(data["tasks"]) - embed = Embed( - title="Standup Log", - description=f"Your latest reported tasks -\n{tasks}", - color=Color.green(), - ) - embed.add_field( - name="Date Added", - value="%s UTC" - % datetime.fromtimestamp(data["date_reported"]).strftime( - "%b-%d-%Y %H:%M" - ), - ) - embed.add_field( - name="Status", value="Verified" if data["approved"] else "Unapproved" - ) - else: - embed = Embed( - title="It looks like there is no record of you or your tasks", - color=Color.red(), - ) - await ctx.send(embed=embed) - - @standup.command() - @commands.dm_only() - async def edit(self, ctx: Context, *, content: str = None): - """Command for editing latest standup""" - if not content: - await ctx.send( - embed=Embed( - description="Content not specified.\n\ -Reuse the command with all the tasks that you'd like to replace the old tasks with", - color=Color.red(), - ) - ) - await self.log(ctx) - else: - record = await self.DB.find_one({"_id": str(ctx.author.id)}) - if record: - embed = Embed( - description="The relevant edits have been made to the record of your tasks", - color=Color.green(), - ) - - field = len(record["data"]) - 1 - - await self.DB.update_one( - record, - { - "$set": { - f"data.{field}.approved": False, - f"data.{field}.last_edited": datetime.now().timestamp(), - f"data.{field}.tasks": content.split("\n"), - } - }, - ) - else: - embed = Embed( - description="No previous records found. A new record with these tasks has been created.", - color=Color.gold(), - ) - await ctx.create(ctx, content) - await ctx.send(embed=embed) - - -def setup(bot): - bot.add_cog(Standup(bot)) diff --git a/src/consts.py b/src/consts.py index e326168..7b9e27a 100644 --- a/src/consts.py +++ b/src/consts.py @@ -9,8 +9,13 @@ PREFIX = os.getenv("PREFIX") or "^" TOKEN = os.getenv("DISCORD_TOKEN") or "foo" MONGO_URI = os.getenv("MONGO_URI") or "bar" +GUILD_ID = int(os.getenv("DISCORD_GUILD_ID") or "629411177947987986") -COGS = ["src.cogs.helpers", "src.cogs.standup"] +COGS = [ + "src.commands.helpers", + "src.commands.standup", + "src.tasks.reminder" +] # "src.cogs.help", # "src.cogs.goals"]