From 506f1d2ff8cb8927175a45317bc47f1f3f449192 Mon Sep 17 00:00:00 2001 From: Izan Date: Wed, 25 Aug 2021 10:57:16 +0100 Subject: Add time units and example to docstring of `!remind` and `!remind new` Supported time units and an example invocation are now displayed in the help message for `!remind` and `!remind new` --- bot/exts/utils/reminders.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 90ad7ef2e..9d567cdbc 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -217,7 +217,20 @@ class Reminders(Cog): async def remind_group( self, ctx: Context, mentions: Greedy[ReminderMention], expiration: Duration, *, content: str ) -> None: - """Commands for managing your reminders.""" + """ + Commands for managing your reminders. + + The `expiration` duration of `!remind new` supports the following symbols for each unit of time: + - years: `Y`, `y`, `year`, `years` + - months: `m`, `month`, `months` + - weeks: `w`, `W`, `week`, `weeks` + - days: `d`, `D`, `day`, `days` + - hours: `H`, `h`, `hour`, `hours` + - minutes: `M`, `minute`, `minutes` + - seconds: `S`, `s`, `second`, `seconds` + + For example, to set a reminder that expires in 3 days and 1 minute, you can do `!remind new 3d1M Do something`. + """ await self.new_reminder(ctx, mentions=mentions, expiration=expiration, content=content) @remind_group.command(name="new", aliases=("add", "create")) @@ -227,7 +240,16 @@ class Reminders(Cog): """ Set yourself a simple reminder. - Expiration is parsed per: http://strftime.org/ + The `expiration` duration supports the following symbols for each unit of time: + - years: `Y`, `y`, `year`, `years` + - months: `m`, `month`, `months` + - weeks: `w`, `W`, `week`, `weeks` + - days: `d`, `D`, `day`, `days` + - hours: `H`, `h`, `hour`, `hours` + - minutes: `M`, `minute`, `minutes` + - seconds: `S`, `s`, `second`, `seconds` + + For example, to set a reminder that expires in 3 days and 1 minute, you can do `!remind new 3d1M Do something`. """ # If the user is not staff, partner or part of the python community, # we need to verify whether or not to make a reminder at all. -- cgit v1.2.3 From fe840ca63647d6d6e92760cb4f0f49ac67926954 Mon Sep 17 00:00:00 2001 From: Izan Date: Wed, 25 Aug 2021 17:32:06 +0100 Subject: Add time units to the `!remind edit` and `!remind edit duration` help messages --- bot/exts/utils/reminders.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 9d567cdbc..2bed5157f 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -372,7 +372,20 @@ class Reminders(Cog): @remind_group.group(name="edit", aliases=("change", "modify"), invoke_without_command=True) async def edit_reminder_group(self, ctx: Context) -> None: - """Commands for modifying your current reminders.""" + """ + Commands for modifying your current reminders. + + The `expiration` duration supports the following symbols for each unit of time: + - years: `Y`, `y`, `year`, `years` + - months: `m`, `month`, `months` + - weeks: `w`, `W`, `week`, `weeks` + - days: `d`, `D`, `day`, `days` + - hours: `H`, `h`, `hour`, `hours` + - minutes: `M`, `minute`, `minutes` + - seconds: `S`, `s`, `second`, `seconds` + + For example, to edit a reminder to expire in 3 days and 1 minute, you can do `!remind edit duration 1234 3d1M`. + """ await ctx.send_help(ctx.command) @edit_reminder_group.command(name="duration", aliases=("time",)) @@ -380,7 +393,16 @@ class Reminders(Cog): """ Edit one of your reminder's expiration. - Expiration is parsed per: http://strftime.org/ + The `expiration` duration supports the following symbols for each unit of time: + - years: `Y`, `y`, `year`, `years` + - months: `m`, `month`, `months` + - weeks: `w`, `W`, `week`, `weeks` + - days: `d`, `D`, `day`, `days` + - hours: `H`, `h`, `hour`, `hours` + - minutes: `M`, `minute`, `minutes` + - seconds: `S`, `s`, `second`, `seconds` + + For example, to edit a reminder to expire in 3 days and 1 minute, you can do `!remind edit duration 1234 3d1M`. """ await self.edit_reminder(ctx, id_, {'expiration': expiration.isoformat()}) -- cgit v1.2.3 From 52bed3d8fab847d7eb9df003b6be7758f6cdbd1d Mon Sep 17 00:00:00 2001 From: Izan Date: Thu, 26 Aug 2021 08:15:32 +0100 Subject: Add message link support to `!user` command --- bot/exts/info/information.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 38b436b7d..ae547b1b8 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -221,8 +221,13 @@ class Information(Cog): await ctx.send(embed=embed) @command(name="user", aliases=["user_info", "member", "member_info", "u"]) - async def user_info(self, ctx: Context, user: MemberOrUser = None) -> None: + async def user_info(self, ctx: Context, user_or_message: Union[MemberOrUser, Message] = None) -> None: """Returns info about a user.""" + if isinstance(user_or_message, Message): + user = user_or_message.author + else: + user = user_or_message + if user is None: user = ctx.author -- cgit v1.2.3 From 78d8bde653187cbf23a2f0ef8a6952058ad95bf4 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 26 Aug 2021 16:39:04 +0100 Subject: Use publically available URL when outputting metabase share URL In production we use the internal URL to call the metabase API, to avoid egress but we still want to output the public url when giving the sharing link. Making it a constant like this makes it easier to change/overwrite in future if needed. --- bot/constants.py | 1 + bot/exts/moderation/metabase.py | 2 +- config-default.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/constants.py b/bot/constants.py index 80e01b174..4e99df7f3 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -569,6 +569,7 @@ class Metabase(metaclass=YAMLGetter): username: Optional[str] password: Optional[str] base_url: str + public_url: str max_session_age: int diff --git a/bot/exts/moderation/metabase.py b/bot/exts/moderation/metabase.py index 3b454ab18..9eeeec074 100644 --- a/bot/exts/moderation/metabase.py +++ b/bot/exts/moderation/metabase.py @@ -167,7 +167,7 @@ class Metabase(Cog): async with self.bot.http_session.post(url, headers=self.headers, raise_for_status=True) as resp: response_json = await resp.json(encoding="utf-8") - sharing_url = f"{MetabaseConfig.base_url}/public/question/{response_json['uuid']}" + sharing_url = f"{MetabaseConfig.public_url}/public/question/{response_json['uuid']}" await ctx.send(f":+1: {ctx.author.mention} Here's your sharing link: {sharing_url}") # This cannot be static (must have a __func__ attribute). diff --git a/config-default.yml b/config-default.yml index 8e0b97a51..baece5c51 100644 --- a/config-default.yml +++ b/config-default.yml @@ -441,6 +441,7 @@ metabase: username: !ENV "METABASE_USERNAME" password: !ENV "METABASE_PASSWORD" base_url: "http://metabase.default.svc.cluster.local" + public_url: "https://metabase.pythondiscord.com" # 14 days, see https://www.metabase.com/docs/latest/operations-guide/environment-variables.html#max_session_age max_session_age: 20160 -- cgit v1.2.3 From b0ea616add8f6122ba5b98b348a4fa5d41774d21 Mon Sep 17 00:00:00 2001 From: Hunter2807 <46440327+Hunter2807@users.noreply.github.com> Date: Fri, 27 Aug 2021 07:39:26 +0530 Subject: Added bot variables tag (#1784) * Added a new tag with the name bot_var Co-authored-by: Bluenix --- bot/resources/tags/bot_var.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bot/resources/tags/bot_var.md diff --git a/bot/resources/tags/bot_var.md b/bot/resources/tags/bot_var.md new file mode 100644 index 000000000..6833b3cd8 --- /dev/null +++ b/bot/resources/tags/bot_var.md @@ -0,0 +1,23 @@ +Python allows you to set custom attributes to class instances, like your bot! By adding variables as attributes to your bot you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below: + +```py +bot = commands.Bot(command_prefix="!") +# Set an attribute on our bot +bot.test = "I am accessible everywhere!" + +@bot.command() +async def get(ctx: commands.Context): + """A command to get the current value of `test`.""" + # Send what the test attribute is currently set to + await ctx.send(ctx.bot.test) + +@bot.command() +async def setval(ctx: commands.Context, *, new_text: str): + """A command to set a new value of `test`.""" + # Here we change the attribute to what was specified in new_text + bot.test = new_text +``` + +This all applies to cogs as well! You can set attributes to `self` as you wish. + +*Be sure **not** to overwrite attributes discord.py uses, like `cogs` or `users`. Name your attributes carefully!* -- cgit v1.2.3