Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
rev: 21.5b0
hooks:
- id: black
language_version: python3.8
language_version: python3.9
71 changes: 71 additions & 0 deletions cogs/utility/reminders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import datetime
import textwrap

from discord.utils import sleep_until
from discord.ext import commands
from datetime import datetime
from discord import Message

from internal.context import Context
from utilities.helpers import EmbedHelper, CustomTimeConverter, get_str_time_mapping
from internal.bot import Bot


class Reminders(commands.Cog):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A docstring for this class would be nice

def __init__(self, bot):
self.bot = bot
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please typehint bot to Magoji's bot class


async def send_reminder(
self,
ctx: Context,
msg: Message,
original_time: str,
time: datetime,
*,
content: str,
):

description = textwrap.dedent(
f"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrongly indented.

Your reminder from [{get_str_time_mapping(original_time)['amount']} {get_str_time_mapping(original_time)['unit']}]({msg.jump_url}) ago has arrived:
```
{content}
```
"""
)

embed = EmbedHelper(
title="Your reminder has arrived",
description=description,
timestamp=datetime.utcnow(),
)

await sleep_until(time)
return await ctx.reply(embed=embed)

@commands.command()
async def remind(self, ctx: Context, length: str, *, content: str):
time = await CustomTimeConverter.convert(self, ctx, length) + datetime.utcnow()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a blank line here? Did you mean to put in a docstring?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black™️

description = textwrap.dedent(
f"""
Your reminder will arrive in {get_str_time_mapping(length)['amount']} {get_str_time_mapping(length)['unit']}(s) with the following content:
```
{content}
```
"""
)
Comment on lines +51 to +57
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way too indented.


embed = EmbedHelper(
title="Reminder Created",
description=description,
timestamp=datetime.utcnow(),
)

msg = await ctx.send(embed=embed)

await self.send_reminder(ctx, msg, length, time, content=content)


def setup(bot: Bot) -> None:
bot.add_cog(Reminders(bot))
17 changes: 4 additions & 13 deletions internal/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from aiohttp import ClientSession
from typing import Optional
from dotenv import load_dotenv
from os import getenv
from logging import getLogger, INFO
from traceback import format_exc

Expand Down Expand Up @@ -55,6 +54,7 @@ async def login(self, *args, **kwargs) -> None:
await super().login(*args, **kwargs)

async def get_prefix(self, message: Message) -> str:
'''
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be commented out

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I didnt mean to commit it while that was commented, mb.

"""Get a dynamic prefix for the bot."""

if not message.guild:
Expand All @@ -66,21 +66,12 @@ async def get_prefix(self, message: Message) -> str:
return ">"

return guild_config[1]
'''

return ">uwu< "

async def get_context(self, message: Message, *, cls=Context) -> Context:
"""Get the custom `Context`."""
return await super().get_context(message, cls=cls)


if __name__ == "__main__":
bot = Bot()

bot.load_extension("jishaku")
bot.load_extensions(
"core.utility",
"core.config",
"utility.info",
"utility.tokens",
)

bot.run(getenv("TOKEN"))
Comment on lines -75 to -86
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this was removed.

3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

bot = Bot()


bot.load_extension("jishaku")
bot.load_extensions(
"core.utility",
Expand All @@ -13,6 +14,8 @@
"moderation.moderation",
"moderation.logging",
"core.error_handler",
"utility.reminders",
)


bot.run(getenv("TOKEN"))
Loading