Skip to content

Commit

Permalink
[snipe] 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flaree committed Jan 25, 2024
1 parent 09e3089 commit 8f93c26
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can contact me in the Red 3rd party server in #support_flare-cogs
| R6 | 1.6.0 | <details><summary>Show R6 Statistics.</summary>List R6 Statistics from seasons, individual operators, all operators and more!</details> | flare(flare#0001) |
| RedditPost | 0.6.0 | <details><summary>Reddit Autoposting of new content.</summary></details> | flare(flare#0001) |
| RoleHistory | 0.1.0 | <details><summary>Visualize the history of a user's roles.</summary></details> | flare(flare#0001) |
| Snipe | 0.5.0 | <details><summary>Snipe the last message deleted in a channel.</summary>Snipe command converted to Red, get the last message deleted in a channel.</details> | flare(flare#0001) |
| Snipe | 0.6.0 | <details><summary>Snipe the last message deleted in a channel.</summary>Snipe command converted to Red, get the last message deleted in a channel.</details> | flare(flare#0001) |
| StickBugged | 0.0.1 | <details><summary>Get stickbugged.</summary></details> | flare(flare#0001) |
| ThreadBumper | 0.0.1 | <details><summary>Bump threads to keep them alive forever.</summary></details> | flare(flare#0001) |
| trigger | 0.2.2 | <details><summary>Allow for the creation of triggers to respond to keywords in messages.</summary></details> | flare(flare#0001) |
Expand Down
32 changes: 31 additions & 1 deletion snipe/snipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class Snipe(commands.Cog):
"""Snipe the last message from a server."""

__version__ = "0.5.0"
__version__ = "0.6.0"

def format_help_for_context(self, ctx):
"""Thanks Sinbad."""
Expand Down Expand Up @@ -236,6 +236,36 @@ async def snipe(
embeds.append(embed)
await self.reply(ctx, embeds=embeds)

@commands.guild_only()
@commands.cooldown(rate=1, per=5, type=commands.BucketType.channel)
@commands.bot_has_permissions(embed_links=True)
async def clearsnipes(self, ctx, type: str = "delete"):
"""Clears snipes from the current channel by the current user."""
guild: discord.Guild = ctx.guild
if not await self.config.guild(guild).toggle():
await self.reply(
ctx,
f"Sniping is not allowed in this server! An admin may turn it on by typing `{ctx.clean_prefix}snipeset enable true`.",
)
return

cache = self.delete_cache if type == "delete" else self.edit_cache
if cache[guild.id].get(ctx.channel.id) is None:
await self.reply(ctx, "There's nothing to clear!")
return

author_id = ctx.author.id
snipes = []
for snipe in cache[guild.id][ctx.channel.id]:
if snipe["author"] == author_id:
snipes.append(snipe)
if not snipes:
await self.reply(ctx, "There's nothing to clear!")
return
for snipe in snipes:
cache[guild.id][ctx.channel.id].remove(snipe)
await self.reply(ctx, f"{len(snipes)} snipes cleared.")

@staticmethod
def get_content(content: str, limit: int = 1024):
return content if len(content) <= limit else f"{content[:limit - 3]}..."
Expand Down

0 comments on commit 8f93c26

Please sign in to comment.