-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
voice.py
307 lines (287 loc) · 14.8 KB
/
voice.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import discord
import asyncio
from discord.ext import commands
import sqlite3
class voice(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
guildID = member.guild.id
c.execute("SELECT voiceChannelID FROM guild WHERE guildID = ?", (guildID,))
voice=c.fetchone()
if voice is None:
pass
else:
voiceID = voice[0]
try:
if after.channel.id == voiceID:
c.execute("SELECT * FROM voiceChannel WHERE userID = ?", (member.id,))
cooldown=c.fetchone()
if cooldown is None:
pass
else:
await member.send("Creating channels too quickly you've been put on a 15 second cooldown!")
await asyncio.sleep(15)
c.execute("SELECT voiceCategoryID FROM guild WHERE guildID = ?", (guildID,))
voice=c.fetchone()
c.execute("SELECT channelName, channelLimit FROM userSettings WHERE userID = ?", (member.id,))
setting=c.fetchone()
c.execute("SELECT channelLimit FROM guildSettings WHERE guildID = ?", (guildID,))
guildSetting=c.fetchone()
if setting is None:
name = f"{member.name}'s channel"
if guildSetting is None:
limit = 0
else:
limit = guildSetting[0]
else:
if guildSetting is None:
name = setting[0]
limit = setting[1]
elif guildSetting is not None and setting[1] == 0:
name = setting[0]
limit = guildSetting[0]
else:
name = setting[0]
limit = setting[1]
categoryID = voice[0]
id = member.id
category = self.bot.get_channel(categoryID)
channel2 = await member.guild.create_voice_channel(name,category=category)
channelID = channel2.id
await member.move_to(channel2)
await channel2.set_permissions(self.bot.user, connect=True,read_messages=True)
await channel2.set_permissions(member, connect=True,read_messages=True)
await channel2.edit(name= name, user_limit = limit)
c.execute("INSERT INTO voiceChannel VALUES (?, ?)", (id,channelID))
conn.commit()
def check(a,b,c):
return len(channel2.members) == 0
await self.bot.wait_for('voice_state_update', check=check)
await channel2.delete()
await asyncio.sleep(3)
c.execute('DELETE FROM voiceChannel WHERE userID=?', (id,))
except:
pass
conn.commit()
conn.close()
@commands.command()
async def help(self, ctx):
embed = discord.Embed(title="Help", description="",color=0x7289da)
embed.set_author(name=f"{ctx.guild.me.display_name}",url="https://discordbots.org/bot/472911936951156740", icon_url=f"{ctx.guild.me.display_avatar.url}")
embed.add_field(name=f'**Commands**', value=f'**Lock your channel by using the following command:**\n\n`.voice lock`\n\n------------\n\n'
f'**Unlock your channel by using the following command:**\n\n`.voice unlock`\n\n------------\n\n'
f'**Change your channel name by using the following command:**\n\n`.voice name <name>`\n\n**Example:** `.voice name EU 5kd+`\n\n------------\n\n'
f'**Change your channel limit by using the following command:**\n\n`.voice limit number`\n\n**Example:** `.voice limit 2`\n\n------------\n\n'
f'**Give users permission to join by using the following command:**\n\n`.voice permit @person`\n\n**Example:** `.voice permit @Sam#9452`\n\n------------\n\n'
f'**Claim ownership of channel once the owner has left:**\n\n`.voice claim`\n\n**Example:** `.voice claim`\n\n------------\n\n'
f'**Remove permission and the user from your channel using the following command:**\n\n`.voice reject @person`\n\n**Example:** `.voice reject @Sam#9452`\n\n', inline='false')
embed.set_footer(text='Bot developed by Sam#9452')
await ctx.channel.send(embed=embed)
@commands.group()
async def voice(self, ctx):
pass
@voice.command()
async def setup(self, ctx):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
guildID = ctx.guild.id
id = ctx.author.id
if ctx.author.id == ctx.guild.owner_id or ctx.author.id == 151028268856770560:
def check(m):
return m.author.id == ctx.author.id
await ctx.channel.send("**You have 60 seconds to answer each question!**")
await ctx.channel.send(f"**Enter the name of the category you wish to create the channels in:(e.g Voice Channels)**")
try:
category = await self.bot.wait_for('message', check=check, timeout = 60.0)
except asyncio.TimeoutError:
await ctx.channel.send('Took too long to answer!')
else:
new_cat = await ctx.guild.create_category_channel(category.content)
await ctx.channel.send('**Enter the name of the voice channel: (e.g Join To Create)**')
try:
channel = await self.bot.wait_for('message', check=check, timeout = 60.0)
except asyncio.TimeoutError:
await ctx.channel.send('Took too long to answer!')
else:
try:
channel = await ctx.guild.create_voice_channel(channel.content, category=new_cat)
c.execute("SELECT * FROM guild WHERE guildID = ? AND ownerID=?", (guildID, id))
voice=c.fetchone()
if voice is None:
c.execute ("INSERT INTO guild VALUES (?, ?, ?, ?)",(guildID,id,channel.id,new_cat.id))
else:
c.execute ("UPDATE guild SET guildID = ?, ownerID = ?, voiceChannelID = ?, voiceCategoryID = ? WHERE guildID = ?",(guildID,id,channel.id,new_cat.id, guildID))
await ctx.channel.send("**You are all setup and ready to go!**")
except:
await ctx.channel.send("You didn't enter the names properly.\nUse `.voice setup` again!")
else:
await ctx.channel.send(f"{ctx.author.mention} only the owner of the server can setup the bot!")
conn.commit()
conn.close()
@commands.command()
async def setlimit(self, ctx, num):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
if ctx.author.id == ctx.guild.owner.id or ctx.author.id == 151028268856770560:
c.execute("SELECT * FROM guildSettings WHERE guildID = ?", (ctx.guild.id,))
voice=c.fetchone()
if voice is None:
c.execute("INSERT INTO guildSettings VALUES (?, ?, ?)", (ctx.guild.id,f"{ctx.author.name}'s channel",num))
else:
c.execute("UPDATE guildSettings SET channelLimit = ? WHERE guildID = ?", (num, ctx.guild.id))
await ctx.send("You have changed the default channel limit for your server!")
else:
await ctx.channel.send(f"{ctx.author.mention} only the owner of the server can setup the bot!")
conn.commit()
conn.close()
@setup.error
async def info_error(self, ctx, error):
print(error)
@voice.command()
async def lock(self, ctx):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
role = ctx.guild.default_role
channel = self.bot.get_channel(channelID)
await channel.set_permissions(role, connect=False)
await ctx.channel.send(f'{ctx.author.mention} Voice chat locked! 🔒')
conn.commit()
conn.close()
@voice.command()
async def unlock(self, ctx):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
role = ctx.guild.default_role
channel = self.bot.get_channel(channelID)
await channel.set_permissions(role, connect=True)
await ctx.channel.send(f'{ctx.author.mention} Voice chat unlocked! 🔓')
conn.commit()
conn.close()
@voice.command(aliases=["allow"])
async def permit(self, ctx, member : discord.Member):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
channel = self.bot.get_channel(channelID)
await channel.set_permissions(member, connect=True)
await ctx.channel.send(f'{ctx.author.mention} You have permited {member.name} to have access to the channel. ✅')
conn.commit()
conn.close()
@voice.command(aliases=["deny"])
async def reject(self, ctx, member : discord.Member):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
guildID = ctx.guild.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
channel = self.bot.get_channel(channelID)
for members in channel.members:
if members.id == member.id:
c.execute("SELECT voiceChannelID FROM guild WHERE guildID = ?", (guildID,))
voice=c.fetchone()
channel2 = self.bot.get_channel(voice[0])
await member.move_to(channel2)
await channel.set_permissions(member, connect=False,read_messages=True)
await ctx.channel.send(f'{ctx.author.mention} You have rejected {member.name} from accessing the channel. ❌')
conn.commit()
conn.close()
@voice.command()
async def limit(self, ctx, limit):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
channel = self.bot.get_channel(channelID)
await channel.edit(user_limit = limit)
await ctx.channel.send(f'{ctx.author.mention} You have set the channel limit to be '+ '{}!'.format(limit))
c.execute("SELECT channelName FROM userSettings WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
c.execute("INSERT INTO userSettings VALUES (?, ?, ?)", (id,f'{ctx.author.name}',limit))
else:
c.execute("UPDATE userSettings SET channelLimit = ? WHERE userID = ?", (limit, id))
conn.commit()
conn.close()
@voice.command()
async def name(self, ctx,*, name):
conn = sqlite3.connect('voice.db')
c = conn.cursor()
id = ctx.author.id
c.execute("SELECT voiceID FROM voiceChannel WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
else:
channelID = voice[0]
channel = self.bot.get_channel(channelID)
await channel.edit(name = name)
await ctx.channel.send(f'{ctx.author.mention} You have changed the channel name to '+ '{}!'.format(name))
c.execute("SELECT channelName FROM userSettings WHERE userID = ?", (id,))
voice=c.fetchone()
if voice is None:
c.execute("INSERT INTO userSettings VALUES (?, ?, ?)", (id,name,0))
else:
c.execute("UPDATE userSettings SET channelName = ? WHERE userID = ?", (name, id))
conn.commit()
conn.close()
@voice.command()
async def claim(self, ctx):
x = False
conn = sqlite3.connect('voice.db')
c = conn.cursor()
channel = ctx.author.voice.channel
if channel == None:
await ctx.channel.send(f"{ctx.author.mention} you're not in a voice channel.")
else:
id = ctx.author.id
c.execute("SELECT userID FROM voiceChannel WHERE voiceID = ?", (channel.id,))
voice=c.fetchone()
if voice is None:
await ctx.channel.send(f"{ctx.author.mention} You can't own that channel!")
else:
for data in channel.members:
if data.id == voice[0]:
owner = ctx.guild.get_member(voice [0])
await ctx.channel.send(f"{ctx.author.mention} This channel is already owned by {owner.mention}!")
x = True
if x == False:
await ctx.channel.send(f"{ctx.author.mention} You are now the owner of the channel!")
c.execute("UPDATE voiceChannel SET userID = ? WHERE voiceID = ?", (id, channel.id))
conn.commit()
conn.close()
async def setup(bot):
await bot.add_cog(voice(bot))