-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_mail_handler.py
76 lines (58 loc) · 3.25 KB
/
mod_mail_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# The handler for mod mail
import discord
from hash_maps import HashTable
class ModMail:
hash_tables = HashTable(2000) # Hash table for mod-mail
client = None
color = None
debug = False # Debug mode
modmail_log_channel = None
def __init__(self, color, client, modmail_log_channel):
"""Initializes the mod mail handler instance."""
self.color = color
self.client = client
self.modmail_log_channel = modmail_log_channel
# Handle a private msg
async def handle_private_msg(self, message):
if self.hash_tables.get_val(message.author.name) != 'No record found':
staffChannel = self.hash_tables.get_val(message.author.name)
embed=discord.Embed(title='Message from ' + message.author.name + ':', description=message.content, color=self.color)
embed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
DMChannel = message.channel
userEmbed=discord.Embed(title='Your Message:', description=message.content, color=self.color)
userEmbed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
await staffChannel.send(embed=embed)
await DMChannel.send(embed=userEmbed)
return
if self.debug:
channel=self.client.get_channel(self.modmail_log_channel)
await channel.send('A new message was received from **' + message.author.name + '**.')
modMailChannel = await channel.guild.create_text_channel(name=message.author.name +'-mod-mail', category=channel.category)
self.hash_tables.set_val(message.author.name, modMailChannel)
self.hash_tables.set_val(modMailChannel, message.author)
channel = self.hash_tables.get_val(message.author.name)
staffEmbed=discord.Embed(title='Message from ' + message.author.name + ':', description=message.content, color=self.color)
staffEmbed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
userEmbed=discord.Embed(title='Your Message:', description=message.content, color=self.color)
userEmbed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
await channel.send(embed=staffEmbed)
await message.author.send(embed=userEmbed)
await message.channel.send('**Your message has been sent to mod-mail!**')
# Handle a staff mod mail message
async def handle_mod_mail_channel_msg(self, message):
userEmbed=discord.Embed(title='Message from ' + message.author.name, description=message.content, color=self.color)
member = self.hash_tables.get_val(message.channel)
userEmbed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
staffEmbed=discord.Embed(title='Message sent by ' + message.author.name, description=message.content, color=self.color)
staffEmbed.set_footer(text=message.author.name, icon_url=message.author.avatar_url)
await member.send(embed=userEmbed)
await message.delete()
await message.channel.send(embed=staffEmbed)
# Handle a mod mail channel close
async def handle_close_mod_mail(self, message):
if message.channel.name.endswith('-mod-mail'):
self.hash_tables.delete_val(self.hash_tables.get_val(message.channel.name))
self.hash_tables.delete_val(message.channel)
if self.debug:
print('[LOGS] A mod mail channel was deleted')
await message.channel.delete()