-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuggestion.py
111 lines (88 loc) · 4.14 KB
/
Suggestion.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from discord_slash import SlashContext
import discord
from settings import *
class Suggestion:
@staticmethod
async def create(ctx: SlashContext, channel:discord.channel.TextChannel, text):
if channel.id not in CATEGORIES:
await ctx.send(hidden=True, content='You cannot send a message in this category!')
return False
embed = discord.Embed()
embed.set_author(name=ctx.author_id, icon_url=ctx.author.avatar_url)
embed.description = text
embed.color = discord.Colour.gold()
msg:discord.Message = await channel.send(embed=embed)
embed.set_footer(text='To modify use: /edit channel:#'+channel.name+' suggestion_id:'+str(msg.id)+' text:new content')
await msg.edit(embed=embed)
await msg.add_reaction("👍")
await msg.add_reaction("👎")
await ctx.send(hidden=True, content='Thank you for your suggestion!')
@staticmethod
async def edit(ctx: SlashContext, channel:discord.channel.TextChannel, suggestion_id, text):
try:
msg:discord.Message = await channel.fetch_message(suggestion_id)
except Exception:
await ctx.send(hidden=True, content='Suggestion not found.')
return False
embed:discord.Embed = msg.embeds[0]
if embed.color != discord.Colour.gold() or int(embed.author.name) != ctx.author_id:
await ctx.send(hidden=True, content='You cannot modify this suggestion!')
return False
embed.description = text
await msg.edit(embed=embed)
await ctx.send(hidden=True, content='Suggestion modified!')
@staticmethod
async def approve(ctx: SlashContext, channel:discord.channel.TextChannel, suggestion_id):
if ctx.author_id not in ADMINS:
await ctx.send(hidden=True, content='Nope.')
return False
try:
msg:discord.Message = await channel.fetch_message(suggestion_id)
except Exception:
await ctx.send(hidden=True, content='Suggestion not found.')
return False
embed:discord.Embed = msg.embeds[0]
embed.color = discord.Colour.green()
embed.set_footer(text='Suggestion Approved')
await msg.edit(embed=embed)
await ctx.send(hidden=True, content='Suggestion has been approved')
@staticmethod
async def refuse(ctx: SlashContext, channel:discord.channel.TextChannel, suggestion_id):
if ctx.author_id not in ADMINS:
await ctx.send(hidden=True, content='Nope.')
return False
try:
msg:discord.Message = await channel.fetch_message(suggestion_id)
except Exception:
await ctx.send(hidden=True, content='Suggestion not found.')
return False
embed:discord.Embed = msg.embeds[0]
embed.color = discord.Colour.red()
embed.set_footer(text='Suggestion refused')
await msg.edit(embed=embed)
await ctx.send(hidden=True, content='Suggestion has been refused')
@staticmethod
async def purge_suggestions(ctx: SlashContext, channel:discord.channel.TextChannel, user_id:int):
if ctx.author_id not in ADMINS:
await ctx.send(hidden=True, content='Nope.')
return False
messages = []
history = await channel.history().flatten()
for msg in history:
embed:discord.Embed = msg.embeds[0]
if int(embed.author.name) == int(user_id):
messages.append(msg)
await channel.delete_messages(messages=messages)
await ctx.send(hidden=True, content='Suggestions removed')
@staticmethod
async def purge_messages(ctx: SlashContext, channel:discord.channel.TextChannel, user_id:int):
if ctx.author_id not in ADMINS:
await ctx.send(hidden=True, content='Nope.')
return False
messages = []
history = await channel.history().flatten()
for msg in history:
if msg.author_id == int(user_id):
messages.append(msg)
channel.delete_messages(messages=messages)
await ctx.send(hidden=True, content='Messages removed')