Skip to content

Commit

Permalink
cleaned up thistracker.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed May 21, 2024
1 parent e628f39 commit d194188
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sizebot/cogs/thistracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def fromJSON(cls, jsondata: Any) -> ThisTracker:
return ThisTracker(points)


def is_agreement_emoji(emoji: str) -> bool:
def _is_agreement_emoji(emoji: str) -> bool:
unicodeagreements = ["🔼", "⬆️", "⤴️", "☝️", "👆"]
if isinstance(emoji, (discord.Emoji, discord.PartialEmoji)):
if "this" in emoji.name.lower():
Expand All @@ -68,14 +68,14 @@ def is_agreement_emoji(emoji: str) -> bool:
return False


def is_agreement_message(message: str) -> bool:
def _is_agreement_message(message: str) -> bool:
textagreements = ["this", "^", "agree"]
return is_agreement_emoji(message) or message.lower() in textagreements or message.startswith("^")
return _is_agreement_emoji(message) or message.lower() in textagreements or message.startswith("^")


def find_latest_non_this(messages: list[discord.Message]) -> discord.Message:
def _find_latest_non_this(messages: list[discord.Message]) -> discord.Message:
for message in messages:
if not is_agreement_message(message.content):
if not _is_agreement_message(message.content):
return message


Expand Down Expand Up @@ -111,13 +111,13 @@ async def leaderboard(self, ctx: BotContext):
async def on_message(self, m: discord.Message):
if m.author.bot:
return
if is_agreement_message(m.content):
if _is_agreement_message(m.content):
channel = m.channel
messages = [m async for m in channel.history(limit=100)]
if find_latest_non_this(messages).author.id == m.author.id:
if _find_latest_non_this(messages).author.id == m.author.id:
return
tracker = ThisTracker.load()
tracker.increment_points(find_latest_non_this(messages).author.id)
tracker.increment_points(_find_latest_non_this(messages).author.id)
tracker.save()

@commands.Cog.listener()
Expand All @@ -126,7 +126,7 @@ async def on_reaction_add(self, reaction: discord.Reaction, reacter: discord.Mem
return
if reaction.message.author.id == reacter.id:
return
if is_agreement_emoji(reaction.emoji):
if _is_agreement_emoji(reaction.emoji):
tracker = ThisTracker.load()
tracker.increment_points(reaction.message.author.id)
tracker.save()
Expand Down

0 comments on commit d194188

Please sign in to comment.