Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sticky] Add user configurable cooldown #92

Open
wants to merge 2 commits into
base: V3
Choose a base branch
from
Open
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
41 changes: 32 additions & 9 deletions sticky/sticky.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from redbot.core import Config, checks, commands
from redbot.core.utils.menus import start_adding_reactions
from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate
from redbot.core.commands import TimedeltaConverter

UNIQUE_ID = 0x6AFE8000

Expand All @@ -18,8 +19,6 @@
class Sticky(commands.Cog):
"""Sticky messages to your channels."""

REPOST_COOLDOWN = 3

def __init__(self, bot):
super().__init__()

Expand All @@ -30,16 +29,24 @@ def __init__(self, bot):
header_enabled=True,
advstickied={"content": None, "embed": {}}, # This is for [p]stickyexisting
last=None,
cooldown=3
)
self.locked_channels = set()
self._channel_cvs: Dict[discord.TextChannel, asyncio.Condition] = {}

@checks.mod_or_permissions(manage_messages=True)
@commands.guild_only()
@commands.group(invoke_without_command=True)
async def sticky(self, ctx: commands.Context, *, content: str):
"""Sticky a message to this channel."""
channel = ctx.channel
async def sticky(
self,
ctx: commands.Context,
channel: Optional[discord.TextChannel] = None,
*,
content: str
):
"""Sticky a message to the specified channel or this channel if none given."""
if channel is None:
channel = ctx.channel
settings = self.conf.channel(channel)

async with settings.all() as settings_dict:
Expand All @@ -61,9 +68,13 @@ async def sticky(self, ctx: commands.Context, *, content: str):
@commands.guild_only()
@sticky.command(name="existing")
async def sticky_existing(
self, ctx: commands.Context, *, message_id_or_url: discord.Message
self,
ctx: commands.Context,
channel: Optional[discord.TextChannel] = None,
*,
message_id_or_url: discord.Message
):
"""Sticky an existing message to this channel.
"""Sticky an existing message to the specified channel or this channel if none given.

This will try to sticky the content and embed of the message.
Attachments will not be added to the stickied message.
Expand All @@ -74,7 +85,8 @@ async def sticky_existing(
"""
message = message_id_or_url
del message_id_or_url
channel = ctx.channel
if channel is None:
channel = ctx.channel
settings = self.conf.channel(channel)
if not (message.content or message.embeds):
await ctx.send("That message doesn't have any content or embed!")
Expand Down Expand Up @@ -109,6 +121,17 @@ async def sticky_toggleheader(self, ctx: commands.Context, true_or_false: bool):
await self.conf.channel(ctx.channel).header_enabled.set(true_or_false)
await ctx.tick()

@checks.mod_or_permissions(manage_messages=True)
@commands.guild_only()
@sticky.command(name="setcooldown")
async def sticky_setcooldown(self, ctx: commands.Context, cooldown: TimedeltaConverter):
"""Set the cooldown for bumping stickied messages in this channel.
e.g. 10 seconds, 1 minute, 5 minutes

Default = 3 seconds
"""
await self.conf.channel(ctx.channel).cooldown.set(cooldown.total_seconds())

@checks.mod_or_permissions(manage_messages=True)
@commands.guild_only()
@commands.command()
Expand Down Expand Up @@ -201,7 +224,7 @@ async def _maybe_repost_stickied_message(
utcnow = datetime.now(timezone.utc)

time_since = utcnow - last_message.created_at
time_to_wait = self.REPOST_COOLDOWN - time_since.total_seconds()
time_to_wait = settings_dict["cooldown"] - time_since.total_seconds()
if time_to_wait > 0:
await asyncio.sleep(time_to_wait)

Expand Down