forked from Thema89/discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mchan.py
285 lines (242 loc) · 12.1 KB
/
mchan.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import discord
import asyncio
import pickle
perm_channels = ['General','English-only','Music','AFK-Club']
admin_ids = ['93043948775305216']
class VoiceChannel:
def __init__(self, owner, cid):
self.owner = owner
self.chanid = cid
def setOwner(self, user):
self.owner = user
with open('voice_channels', 'rb') as f:
try:
voice_channels = pickle.load(f)
except EOFError:
voice_channels = []
def get_voice_channel(cid):
for channel in voice_channels:
if channel.chanid == cid:
return channel
async def cchannel(message, client):
while True:
await client.send_typing(message.channel)
if message.channel.is_private:
await client.send_message(message.channel, 'Please call this command from a server channel.')
break
if '"' in message.content:
parse = message.content.split('"')
for i in range(0, len(parse)):
parse[i] = parse[i].strip()
if 'party ' in parse[2]:
p = parse[2].split()
parse[2] = p[0]
parse.append(p[1])
else:
parse = message.content.split()
try:
game = parse[1]
except IndexError:
await client.send_message(message.channel, 'Please specify a name for the channel (in lowercase.)')
break
try:
lim = parse[2]
except IndexError:
lim = 'null'
if not '"' in message.content:
game = game.title()
if game.lower() == 'current' and str(message.author.game) == 'None':
await client.send_message(message.channel, 'Please launch a game then call the command again. Alternatively, provide a name.')
break
elif game.lower() == 'Current'.lower():
game = str(message.author.game)
if game == 'Counter-Strike: Global Offensive':
game = 'CS:GO'
elif game == 'Grand Theft Auto V':
game = 'GTA V'
exist = sum(c.name.startswith(game) for c in message.server.channels)
num = str(exist + 1)
#pos = sum(c.type == discord.ChannelType.voice for c in message.server.channels)
if exist != 0:
game += ' #%s' % num
if str(lim).isdigit():
limit = int(lim)
else:
limit = 0
chanlim = sum(c.owner == message.author for c in voice_channels)
if chanlim < 4:
pass
else:
await client.send_message(message.channel, 'You can only create up to 4 channels, you can use $dchannel to delete some though.')
break
everyone = discord.PermissionOverwrite(connect=False)
access = discord.PermissionOverwrite(connect=True)
if str(lim) == 'private' or str(lim) == 'party':
channel = await client.create_channel(message.server, game, (message.server.default_role, everyone), (message.author, access), type=discord.ChannelType.voice)
if str(lim) == 'party':
try:
members = parse[3].split(';')
except IndexError:
await client.delete_channel(channel)
await client.send_message(message.channel, 'No party members specified.')
break
for member in members:
person = discord.utils.find(lambda o: o.name.lower() == member.lower() or member.lower() in o.display_name.lower(), message.channel.server.members)
await client.edit_channel_permissions(channel, person, access)
elif str(lim) == 'semipub':
channel = await client.create_channel(message.server, game, (message.server.default_role, everyone), type=discord.ChannelType.voice)
for role in message.server.roles:
if role != message.server.default_role and not role.permissions.administrator:
await client.edit_channel_permissions(channel, role, access)
else:
channel = await client.create_channel(message.server, game, type=discord.ChannelType.voice)
listing = VoiceChannel(owner=message.author, cid=channel.id)
voice_channels.append(listing)
with open('voice_channels', 'wb') as f:
pickle.dump(voice_channels, f)
await client.edit_channel(channel, bitrate=96000, user_limit=limit)
#await client.move_channel(channel, pos)
await client.send_message(message.channel, 'Successfully created the voice channel')
break
async def dchannel(message, client):
while True:
await client.send_typing(message.channel)
if message.channel.is_private:
await client.send_message(message.channel, 'Please call this command from a server channel.')
break
if '"' in message.content:
parse = message.content.split('"')
else:
parse = message.content.split(' ', 1)
try:
name = parse[1]
except IndexError:
name = 'null'
await client.send_message(message.channel, 'No channel specified')
break
if name in perm_channels:
await client.send_message(message.channel, "You don't have permission to delete that channel.")
break
try:
chan = discord.utils.get(message.server.channels, name=name, type=discord.ChannelType.voice)
channel = get_voice_channel(chan.id)
if message.author == channel.owner or message.author.id in admin_ids:
await client.delete_channel(chan)
voice_channels.remove(channel)
with open('voice_channels', 'wb') as f:
f.truncate()
pickle.dump(voice_channels, f)
await client.send_message(message.channel, 'Successfully deleted the voice channel')
break
else:
await client.send_message(message.channel, "You can only delete your channels.")
break
except AttributeError:
await client.send_message(message.channel, 'Channel not found')
break
async def echannel(message, client):
while True:
await client.send_typing(message.channel)
if message.channel.is_private:
await client.send_message(message.channel, 'Please call this command from a server channel.')
break
parse = message.content.split(' ', 1)
try:
name = parse[1]
except IndexError:
await client.send_message(message.channel, 'No channel specified')
break
if name in perm_channels:
await client.send_message(message.channel, "You don't have permission to edit that channel.")
break
try:
chan = discord.utils.get(message.server.channels, name=name, type=discord.ChannelType.voice)
channel = get_voice_channel(chan.id)
if message.author == channel.owner or message.author.id in admin_ids:
await client.send_message(message.channel, "Now, enter an edit command... *(use `$help echannel` for more info)*:")
await client.send_typing(message.channel)
msg = await client.wait_for_message(author=message.author, channel=message.channel)
if '"' in msg.content:
response = msg.content.split('"')
for i in range(0, len(response)):
response[i] = response[i].strip()
else:
response = msg.content.split(' ', 1)
success = 'Successfully edited the {0} to {1}'
everyone = discord.PermissionOverwrite(connect=False)
access = discord.PermissionOverwrite(connect=True)
if response[0] == '#name':
try:
nname = response[1]
await client.edit_channel(chan, name=nname)
await client.send_message(message.channel, success.format('name',nname))
break
except IndexError:
await client.send_message(message.channel, 'No new name specified.')
break
elif response[0] == '#limit':
try:
limit = int(response[1])
await client.edit_channel(chan, user_limit=limit)
await client.send_message(message.channel, success.format('limit',limit))
break
except IndexError:
await client.send_message(message.channel, 'No limit specified.')
break
elif response[0] == '#setowner':
try:
owner = response[1].lower()
nowner = discord.utils.find(lambda o: o.name.lower() == owner.lower() or owner.lower() in o.display_name.lower(), message.channel.server.members)
if str(nowner) == 'None':
await client.send_message(message.channel, 'No user found')
break
channel.setOwner(nowner)
await client.send_message(message.channel, success.format('owner',nowner.mention))
break
except IndexError:
await client.send_message(message.channel, 'No new owner specified.')
break
except AttributeError:
await client.send_message(message.channel, 'No user found')
break
elif response[0] == '#whitelist':
try:
arg = response[1].lower()
person = discord.utils.find(lambda o: o.name.lower() == arg.lower() or arg.lower() in o.display_name.lower(), message.channel.server.members)
await client.edit_channel_permissions(chan, person, access)
await client.send_message(message.channel, 'Successfully added {} to the whitelist'.format(person.display_name))
break
except IndexError:
await client.send_message(message.channel, 'No user to whitelist.')
elif response[0] == '#lock':
await client.edit_channel_permissions(chan, message.server.default_role, everyone)
await client.edit_channel_permissions(chan, message.author, access)
for role in message.server.roles:
if role != message.server.default_role:
await client.delete_channel_permissions(chan, role)
for user in chan.voice_members:
if user != message.author:
await client.edit_channel_permissions(chan, user, access)
await client.send_message(message.channel, 'Successfully converted channel to private')
break
elif response[0] == '#unlock':
await client.delete_channel_permissions(chan, message.author)
for role in message.server.roles:
if role != message.server.default_role:
await client.edit_channel_permissions(chan, role, access)
for user in chan.voice_members:
if user != message.author:
await client.delete_channel_permissions(chan, user)
await client.send_message(message.channel, 'Successfully converted channel to semi-public')
break
elif response[0].startswith('#'):
await client.send_message(message.channel, 'Invalid edit command.')
break
else:
break
else:
await client.send_message(message.channel, "You can only edit your channels.")
break
except AttributeError:
await client.send_message(message.channel, 'Channel not found')
break