Skip to content

Thank Command Maintainence #56

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

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions cogs/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ def valid_gh_sect(name: str):

self.valid_gh_sect = valid_gh_sect

@commands.Cog.listener("on_message")
async def thank_message(self, message: discord.Message):
"""
Responsible for checking if a user is saying thanks in a help channel.
if so, the bot will inform the user that they can use the thank command
to support the user that helped them.

Parameters
----------
message : discord.Message
The message that was sent.
"""
if message.author.bot or not message.guild:
return

if message.channel.category.id == 754710748353265745:
if (
"thanks" in message.content.lower()
or "thank you" in message.content.lower()
or "thx" in message.content.lower()
or "thnx" in message.content.lower()
):
await message.reply(
"If someone has helped you, "
"you can thank them by using the `.thank` command."
)

@commands.Cog.listener("on_message")
async def afk_user_messaage(self, message: discord.Message):
"""
Expand Down
29 changes: 4 additions & 25 deletions cogs/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,7 @@ async def run(self, ctx, *, codeblock: str):
),
)

@commands.hybrid_group(name="thanks", invoke_without_command=True)
@commands.cooldown(1, 10, commands.BucketType.member)
async def thanks(self, ctx: commands.Context[CodingBot], member: discord.Member):
"""
See how many thanks someone has.

Usage:
------
`{prefix}thanks {user}`: *will show how many thanks user has*
"""
record = await self.bot.conn.select_record(
"thanks",
table="thanks_info",
arguments=("thanks_count",),
where=["guild_id", "user_id"],
values=[ctx.guild.id, member.id],
)
if not record:
return await ctx.send(f"{member.display_name} does not have any thanks")
thanks = record[0]
await ctx.send(f"{member.display_name} has `{thanks.thanks_count}` thanks")

@commands.hybrid_group(name="thank", invoke_without_command=True)
@commands.hybrid_group(name="thank", invoke_without_command=True, fallback="you")
@commands.cooldown(1, 10, commands.BucketType.member)
async def thank(
self, ctx: commands.Context[CodingBot], member: discord.Member, *, reason: str
Expand Down Expand Up @@ -279,7 +257,7 @@ async def thank_show(
timestamp = data.date
channel = ctx.guild.get_channel(channel_id)
msg_link = (
f"https://discord.com/channels/{ctx.guild.id}/{channel.id}/{msg_id}"
f"https://discord.com/channels/{ctx.guild.id}/{channel_id}/{msg_id}"
)

giver = ctx.guild.get_member(giver_id)
Expand All @@ -288,7 +266,8 @@ async def thank_show(
name=f"Thank: {thank_id}",
value=
f"Thank giver: {giver.mention}\nDate: <t:{timestamp}:R>\n"
f"Reason: {reason}\nThank given in: {channel.mention}\n"
f"Reason: {reason}\nThank given in: "
f"{channel.mention if channel else f'<#{channel_id}>'}\n"
f"Message link: [Click here!]({msg_link})",
inline=False,
)
Expand Down