async def new_reminder(self, ctx: Context, expiration: Duration, *, content: str) -> t.Optional[discord.Message]: """ Set yourself a simple reminder. Expiration is parsed per: http://strftime.org/ """ embed = discord.Embed() # If the user is not staff, we need to verify whether or not to make a reminder at all. if without_role_check(ctx, *STAFF_ROLES): # If they don't have permission to set a reminder in this channel if ctx.channel.id not in WHITELISTED_CHANNELS: embed.colour = discord.Colour.red() embed.title = random.choice(NEGATIVE_REPLIES) embed.description = "Sorry, you can't do that here!" return await ctx.send(embed=embed) # Get their current active reminders active_reminders = await self.bot.api_client.get( 'bot/reminders', params={ 'author__id': str(ctx.author.id) } ) # Let's limit this, so we don't get 10 000 # reminders from kip or something like that :P if len(active_reminders) > MAXIMUM_REMINDERS: embed.colour = discord.Colour.red() embed.title = random.choice(NEGATIVE_REPLIES) embed.description = "You have too many active reminders!" return await ctx.send(embed=embed) # Now we can attempt to actually set the reminder. reminder = await self.bot.api_client.post( 'bot/reminders', json={ 'author': ctx.author.id, 'channel_id': ctx.message.channel.id, 'jump_url': ctx.message.jump_url, 'content': content, 'expiration': expiration.isoformat() } ) now = datetime.utcnow() - timedelta(seconds=1) humanized_delta = humanize_delta(relativedelta(expiration, now)) # Confirm to the user that it worked. await self._send_confirmation( ctx, on_success=f"Your reminder will arrive in {humanized_delta}!", reminder_id=reminder["id"], delivery_dt=expiration, ) self.schedule_task(reminder["id"], reminder)
async def edit_reminder_duration(self, ctx: Context, id_: int, expiration: Duration) -> None: """ Edit one of your reminder's expiration. Expiration is parsed per: http://strftime.org/ """ await self.edit_reminder(ctx, id_, {'expiration': expiration.isoformat()})
async def edit_reminder_duration(self, ctx: Context, id_: int, expiration: Duration) -> None: """ Edit one of your reminder's expiration. Expiration is parsed per: http://strftime.org/ """ # Send the request to update the reminder in the database reminder = await self.bot.api_client.patch( 'bot/reminders/' + str(id_), json={'expiration': expiration.isoformat()}) # Send a confirmation message to the channel await self._send_confirmation( ctx, on_success="That reminder has been edited successfully!") await self._reschedule_reminder(reminder)
async def edit_reminder_duration(self, ctx: Context, id_: int, expiration: Duration) -> None: """ Edit one of your reminder's expiration. 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()})
async def new_reminder(self, ctx: Context, mentions: Greedy[Mentionable], expiration: Duration, *, content: str) -> None: """ Set yourself a simple reminder. Expiration is parsed per: http://strftime.org/ """ # If the user is not staff, we need to verify whether or not to make a reminder at all. if without_role_check(ctx, *STAFF_ROLES): # If they don't have permission to set a reminder in this channel if ctx.channel.id not in WHITELISTED_CHANNELS: await send_denial(ctx, "Sorry, you can't do that here!") return # Get their current active reminders active_reminders = await self.bot.api_client.get( 'bot/reminders', params={'author__id': str(ctx.author.id)}) # Let's limit this, so we don't get 10 000 # reminders from kip or something like that :P if len(active_reminders) > MAXIMUM_REMINDERS: await send_denial(ctx, "You have too many active reminders!") return # Remove duplicate mentions mentions = set(mentions) mentions.discard(ctx.author) # Filter mentions to see if the user can mention members/roles if not await self.validate_mentions(ctx, mentions): return mention_ids = [mention.id for mention in mentions] # Now we can attempt to actually set the reminder. reminder = await self.bot.api_client.post('bot/reminders', json={ 'author': ctx.author.id, 'channel_id': ctx.message.channel.id, 'jump_url': ctx.message.jump_url, 'content': content, 'expiration': expiration.isoformat(), 'mentions': mention_ids, }) now = datetime.utcnow() - timedelta(seconds=1) humanized_delta = humanize_delta(relativedelta(expiration, now)) mention_string = (f"Your reminder will arrive in {humanized_delta} " f"and will mention {len(mentions)} other(s)!") # Confirm to the user that it worked. await self._send_confirmation( ctx, on_success=mention_string, reminder_id=reminder["id"], delivery_dt=expiration, ) self.schedule_reminder(reminder)
async def new_reminder(self, ctx: Context, mentions: Greedy[ReminderMention], expiration: Duration, *, content: str) -> None: """ Set yourself a simple reminder. 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. if await has_no_roles_check(ctx, *STAFF_PARTNERS_COMMUNITY_ROLES): # If they don't have permission to set a reminder in this channel if ctx.channel.id not in WHITELISTED_CHANNELS: await send_denial(ctx, "Sorry, you can't do that here!") return # Get their current active reminders active_reminders = await self.bot.api_client.get( 'bot/reminders', params={'author__id': str(ctx.author.id)}) # Let's limit this, so we don't get 10 000 # reminders from kip or something like that :P if len(active_reminders) > MAXIMUM_REMINDERS: await send_denial(ctx, "You have too many active reminders!") return # Remove duplicate mentions mentions = set(mentions) mentions.discard(ctx.author) # Filter mentions to see if the user can mention members/roles if not await self.validate_mentions(ctx, mentions): return mention_ids = [mention.id for mention in mentions] # Now we can attempt to actually set the reminder. reminder = await self.bot.api_client.post('bot/reminders', json={ 'author': ctx.author.id, 'channel_id': ctx.message.channel.id, 'jump_url': ctx.message.jump_url, 'content': content, 'expiration': expiration.isoformat(), 'mentions': mention_ids, }) mention_string = f"Your reminder will arrive on {discord_timestamp(expiration, TimestampFormats.DAY_TIME)}" if mentions: mention_string += f" and will mention {len(mentions)} other(s)" mention_string += "!" # Confirm to the user that it worked. await self._send_confirmation(ctx, on_success=mention_string, reminder_id=reminder["id"]) self.schedule_reminder(reminder)