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

Sherpmail #88

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
68 changes: 68 additions & 0 deletions cogs/sherpmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import discord
from discord.ext import commands
from discord import app_commands

# I couldn't work out replying directly to the initial messages so this is not the best
# Nonetheless it is nearly 6am and I felt the need to complete this
# I hope it works out and nobody abuses it lol good luck

class sherpMailbox(commands.Cog):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class sherpMailbox(commands.Cog):
class SherpMailbox(commands.Cog):

(style)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Applied to the incoming commit.

def __init__(self, bot):
self.bot = bot
self.sherp = ""

async def cog_load(self):
await super().cog_load()
print("Sherpmail loaded.")

@app_commands.command(
name = "sherpmail",
description = "Leave a message directly to Sherp's DMs"
)
@app_commands.describe(
msg = "The message you would like to leave for Sherp (be respectful)"
)
async def sendMessage(self, interaction: discord.Interaction, msg: str):
# Sherp's Discord ID is currently 212613981465083906
self.sherp = await interaction.client.fetch_user(212613981465083906)
try:
embed = discord.Embed(
title = f"📬 You've got mail! **@{interaction.user} | ID: {interaction.user.id}** sent you the following:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect, unless discord.py has some special __repr__ stuff I'm ignorning. I think we should mention interaction.user.global_name and interaction.user.name. The numeric ID isn't too useful IDT.

https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=interaction#discord.Interaction.user

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique UID and user would prevent someone from writing stupid things as they would know that their identifiers were also being sent to Sherp. I did rewrite it and have it stated in the footer of the embed instead.

description = f"{msg}",
colour = discord.Colour.gold()
)
await self.sherp.send(embed = embed)

embed = discord.Embed(
title = f"📫 Outgoing! The following message has been mailed to {self.sherp.display_name}:",
description = f"{msg}",
colour = discord.Colour.green()
)
await interaction.response.send_message(embed = embed)
except:
await interaction.response.send_message(f"❌ An unexpected error has occurred!")

@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if (message.guild == None) and (message.author.id == 214657501193306112):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (message.guild == None) and (message.author.id == 214657501193306112):
if (message.channel.type === 'dm') and (message.author.id == 214657501193306112):

I think this is clearer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted to message.channel.type.name == "private" and it will reflect on the next commit.

try:
embed = discord.Embed(
title = "📬 You've got mail! This is what Sherp said:",
description = f"{message.content}",
colour = discord.Colour.gold()
)
# I used the ID 1183281507842924645 from the channel "non-cs-nonsense"
ch = self.bot.get_channel(1183281507842924645)
await ch.send(embed = embed)

embed = discord.Embed(
title = f"📫 Outgoing! The following reply was sent:",
description = f"{message.content}",
colour = discord.Colour.green()
)
await message.reply(embed = embed, mention_author = False)
except:
await message.reply(f"❌ An unexpected error has occurred!")

async def setup_sherpMailbox_cog(bot, guilds):
await bot.add_cog(sherpMailbox(bot), guilds=guilds)