Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
[disboardreminder] Remove embed parsing, use interaction data instead (
Browse files Browse the repository at this point in the history
…#170)

* Check bumper with interaction.user instead of embed

* Add missing paranthesis

* revert to guard clauses and old permissions check
  • Loading branch information
i-am-zaidali committed Jun 9, 2023
1 parent 845de55 commit ed7bf43
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions disboardreminder/disboardreminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@

DISBOARD_BOT_ID = 302050872383242240
LOCK_REASON = "DisboardReminder auto-lock"
MENTION_RE = re.compile(r"<@!?(\d{15,20})>")
BUMP_RE = re.compile(r"!d bump\b")


class DisboardReminder(commands.Cog):
"""
Set a reminder to bump on Disboard.
"""

__version__ = "1.3.7"
__version__ = "1.4.0"

def format_help_for_context(self, ctx):
pre_processed = super().format_help_for_context(ctx)
Expand Down Expand Up @@ -427,46 +424,24 @@ def validate_cache(self, message: discord.Message) -> Optional[discord.TextChann
return
return guild.get_channel(bump_chan_id)

def validate_success(self, message: discord.Message) -> Optional[discord.Embed]:
if not message.embeds:
return
embed = message.embeds[0]
if ":thumbsup:" in embed.description:
return embed
if message.webhook_id and "Bump done!" in embed.description:
# slash command responses to the bump command don't have the thumbsup emoji in them
# for some reason
# this solution is a temporary fix, since it isn't language agnostic, but atm I can't
# a different telling sign that only appears on bump command responses
return embed
def validate_success(self, message: discord.Message) -> bool:
if not message.embeds or not message.interaction:
return False

return message.interaction.type == discord.InteractionType.application_command and message.interaction.name == "bump"

async def respond_to_bump(
self,
data: dict,
bump_channel: discord.TextChannel,
message: discord.Message,
embed: discord.Embed,
):
guild: discord.Guild = message.guild
my_perms = bump_channel.permissions_for(guild.me)
next_bump = message.created_at.timestamp() + 7200
await self.config.guild(guild).nextBump.set(next_bump)

member_adapter = None
match = MENTION_RE.search(embed.description)
if match:
member_id = int(match.group(1))
user = await self.bot.get_or_fetch_member(guild, member_id)
member_adapter = tse.MemberAdapter(user)
elif message.interaction:
member_adapter = tse.MemberAdapter(message.interaction.user)
elif my_perms.read_message_history:
async for m in bump_channel.history(before=message, limit=10):
if m.content and BUMP_RE.match(m.content):
member_adapter = tse.MemberAdapter(m.author)
break
if member_adapter is None:
member_adapter = tse.StringAdapter("Unknown User")
member_adapter = tse.MemberAdapter(message.interaction.user)
tymessage = data["tyMessage"]

if my_perms.send_messages:
Expand Down Expand Up @@ -503,14 +478,15 @@ async def on_message_without_command(self, message: discord.Message):
data = await self.config.guild(guild).all()
if not data["channel"]:
return

clean = data["clean"]
my_perms = channel.permissions_for(guild.me)

if embed := self.validate_success(message):
if self.validate_success(message):
last_bump = data["nextBump"]
if last_bump and last_bump - message.created_at.timestamp() > 0:
return
await self.respond_to_bump(data, bump_channel, message, embed)
await self.respond_to_bump(data, bump_channel, message)
elif my_perms.manage_messages and clean and channel == bump_channel:
await asyncio.sleep(2)
try:
Expand Down

0 comments on commit ed7bf43

Please sign in to comment.