-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_client.py
209 lines (159 loc) · 6.48 KB
/
message_client.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from discord.utils import escape_markdown
import commands.about
import commands.admin
import commands.disable
import commands.enable
import commands.help
import commands.iam
import commands.meme
import commands.mention
import commands.prune
import commands.set
import commands.someone
import commands.song
import commands.update
import greetings.farewell
import greetings.welcome
import misc.role_cleanup
import filters.invite
import filters.mass_mention
import filters.profanity
import misc.prefix
import misc.status
import reactions.song
import credentials
from base_client import BaseClient
class MessageClient(BaseClient):
def __init__(self):
BaseClient.__init__(
self, 'Message Client')
self.mention = None
async def on_ready(self):
print("'%s' has connected to Discord!" \
% self.name)
self.mention = '<@!%d>' % self.user.id
await misc.status.load(self)
async def on_message(self, message):
if message.author.bot or not message.guild:
return
if filters.profanity.regex.search(message.content):
await filters.profanity.run(message, self.db)
elif filters.mass_mention.regex.search(message.content):
await filters.mass_mention.run(message, self.db)
elif filters.invite.regex.search(message.content):
await filters.invite.run(message, self.db)
elif commands.someone.regex.match(message.content):
await commands.someone.run(message, self.db)
elif message.content == self.mention:
prefix_ = escape_markdown(
misc.prefix.get(
message.guild.id,
self.db))
await commands.mention.run(prefix_, message)
else:
prefix_ = misc.prefix.get(message.guild.id, self.db)
if message.content.startswith(prefix_):
prefix_ = escape_markdown(prefix_)
if commands.meme.regex.match(message.content):
await commands.meme.run(
prefix_,
message,
self.db,
credentials)
elif commands.song.regex.match(message.content):
await commands.song.run(
prefix_,
message,
self.db,
credentials)
elif commands.set.regex.match(message.content):
await commands.set.run(
prefix_,
message,
self.db)
elif commands.prune.regex.match(message.content):
await commands.prune.run(
prefix_,
message,
self.db)
elif commands.help.regex.match(message.content):
await commands.help.run(
prefix_,
message,
self.db)
elif commands.admin.regex.match(message.content):
await commands.admin.run(
prefix_,
message,
self.db)
elif commands.iam.regex.match(message.content):
await commands.iam.run(
prefix_,
message,
self.db,
self.user.id,
credentials)
elif commands.enable.regex.match(message.content):
await commands.enable.run(
prefix_,
message,
self.db)
elif commands.about.regex.match(message.content):
await commands.about.run(message, credentials)
elif commands.disable.regex.match(message.content):
await commands.disable.run(
prefix_,
message,
self.db)
elif message.author.id == credentials.OWNER_ID:
if message.content.startswith('.update '):
await commands.update.run(message, self)
elif message.content.startswith('.status'):
await misc.status.change(message, self)
elif message.content == '.stop':
print(
'Stop requested through "%s" (%d), stopping.' \
% (
message.guild,
message.guild.id
))
self.db.close()
await self.close()
async def on_raw_reaction_add(self, payload):
if payload.user_id == self.user.id \
or payload.emoji.name not in ('👍', '👎'):
return
message = await self.get_channel(
payload.channel_id).fetch_message(
payload.message_id)
if message.author.id != self.user.id:
return
if message.content.startswith(
'http'):
await reactions.song.add(
message,
payload,
self.db)
async def on_raw_reaction_remove(self, payload):
if payload.user_id == self.user.id \
or payload.emoji.name not in ('👍', '👎'):
return
message = await self.get_channel(
payload.channel_id).fetch_message(
payload.message_id)
if message.author.id != self.user.id:
return
if message.content.startswith(
'http'):
await reactions.song.remove(
message,
payload,
self.db)
async def on_member_join(self, member):
await greetings.welcome.run(member, self.db)
async def on_member_remove(self, member):
await greetings.farewell.run(member, self.db)
await misc.role_cleanup.run(member, self.db)
async def on_member_update(self, before, after):
if len(before.roles) > len(after.roles):
await misc.role_cleanup.run(before, self.db)