-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
656 lines (586 loc) · 34.2 KB
/
main.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# imports
import configparser
import platform
import time
import nextcord
import redis
from nextcord import Interaction, Locale
from nextcord.ext import commands
# class for colored console output
class BC:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
RESET = '\033[0m'
sucess = f'{BC.OKGREEN}✓ {BC.RESET}'
# load config & language
config = configparser.ConfigParser()
config.read('config.ini')
fallback_lang = configparser.ConfigParser()
fallback_lang.read('language.ini')
english = configparser.ConfigParser()
english.read('language/en_us.ini')
korean = configparser.ConfigParser()
korean.read('language/ko_kr.ini')
chinese = configparser.ConfigParser()
chinese.read('language/zh_cn.ini')
token = config['CREDENTIALS']['token']
owner_id = str(config['CREDENTIALS']['owner_id'])
status = config['SETTINGS']['status']
status_message = config['SETTINGS']['status_message']
status_type = config['SETTINGS']['status_type']
host = config['REDIS']['host']
port = config['REDIS']['port']
password = config['REDIS']['password']
db = config['REDIS']['db']
# check config
error_count = 0
if status not in ['online', 'idle', 'dnd', 'invisible']:
print(f'{BC.FAIL}Error: Status must be one of online, idle, dnd, or invisible.{BC.RESET}')
error_count += 1
if status_type not in ['playing', 'streaming', 'listening', 'watching']:
print(f'{BC.FAIL}Error: Status type must be one of playing, streaming, listening, or watching.{BC.RESET}')
error_count += 1
if len(status_message) > 128:
print(f'{BC.FAIL}Error: Status message must be less than 128 characters.{BC.RESET}')
error_count += 1
if error_count > 0:
print(f'{BC.FAIL}Please change the config file (config.ini) and try again.\nExiting in 5 seconds...{BC.RESET}')
time.sleep(5)
exit()
print(f'{sucess}Config check.')
# check redis connection
try:
print(f'{sucess}Connecting to Redis. ({BC.OKBLUE}{host}:{port}{BC.RESET} Database: {BC.OKBLUE}{db}{BC.RESET})')
r = redis.Redis(host=host, port=port, password=password, decode_responses=True, db=db)
r.ping()
print(f'{sucess}Redis database connection.')
except:
print(f'''{BC.FAIL}Error: Could not connect to Redis server.
Please change the config file (config.ini) and try again.
Exiting in 5 seconds...''')
time.sleep(5)
exit()
# discord setup
intents = nextcord.Intents.default()
intents.members = True
intents.message_content = True
client = commands.Bot(intents=intents)
def lang_check(locale):
if locale == "en-US":
return english
elif locale == "ko":
return korean
elif locale == "zh-CN":
return chinese
else:
return fallback_lang
# Bot startup
@client.event
async def on_ready():
# set status
if status_type == 'playing':
await client.change_presence(activity=nextcord.Game(name=status_message), status=status)
elif status_type == 'streaming':
await client.change_presence(activity=nextcord.Streaming(name=status_message, url='https://twich.tv'),
status=status)
elif status_type == 'listening':
await client.change_presence(
activity=nextcord.Activity(type=nextcord.ActivityType.listening, name=status_message), status=status)
elif status_type == 'watching':
await client.change_presence(
activity=nextcord.Activity(type=nextcord.ActivityType.watching, name=status_message), status=status)
# print startup message
print(f'{sucess}Authentication to Discord.')
owner_name = await client.fetch_user(owner_id)
print('======================================')
print(f'Logged in as {BC.OKBLUE}{client.user.name}#{client.user.discriminator} {BC.RESET}({client.user.id})')
print(f"Owner: {BC.OKBLUE}{owner_name}{BC.RESET} ({owner_id})")
print(f'Currenly running nextcord {BC.OKBLUE}{nextcord.__version__}{BC.RESET} on python {BC.OKBLUE}{platform.python_version()}{BC.RESET}')
print('======================================')
# create command
@client.slash_command(name=fallback_lang['CREATE']['name'], description=fallback_lang['CREATE']['description'],
dm_permission=False,
default_member_permissions=8)
async def create_intro(interaction: Interaction,
channel: nextcord.VoiceChannel = nextcord.SlashOption(
description=fallback_lang['CREATE']['argument_description'],
required=True,
),
):
lang = lang_check(interaction.locale)
try:
if r.exists(f"auto:{channel.guild.id}:{channel.id}"):
embed = nextcord.Embed(title=fallback_lang['CREATE']['duplicate'],
description=lang['CREATE']['duplicate_description'], color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
r.set(f"auto:{channel.guild.id}:{channel.id}", channel.category.id)
embed = nextcord.Embed(title=lang['CREATE']['success'],
description=lang['CREATE']['success_description'].format(channel.mention),
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['CREATE']['error'], description=lang['CREATE']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
# deactive command
@client.slash_command(name=fallback_lang['DELETE']['name'], description=fallback_lang['DELETE']['description'],
dm_permission=False,
default_member_permissions=8)
async def delete_intro(interaction: Interaction,
channel: nextcord.VoiceChannel = nextcord.SlashOption(
description=fallback_lang['DELETE']['argument_description'],
required=True,
),
):
lang = lang_check(interaction.locale)
try:
if r.exists(f"auto:{channel.guild.id}:{channel.id}"):
r.delete(f"auto:{channel.guild.id}:{channel.id}")
embed = nextcord.Embed(title=lang['DELETE']['success'],
description=lang['DELETE']['success_description'].format(channel.mention),
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['DELETE']['not_found'],
description=lang['DELETE']['not_found_description'], color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['DELETE']['error'], description=lang['DELETE']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
# list command
@client.slash_command(name=fallback_lang['LIST']['name'], description=fallback_lang['LIST']['description'],
dm_permission=False)
async def list_intro(interaction: Interaction):
lang = lang_check(interaction.locale)
try:
keys = r.keys(f"auto:{interaction.guild.id}:*")
temp_keys = r.keys(f"temp:{interaction.guild.id}:*")
if len(keys) + len(temp_keys) == 0:
embed = nextcord.Embed(title=lang['LIST']['empty'],
description=lang['LIST']['empty_description'].format(interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['LIST']['embed_title'],
description=lang['LIST']['embed_description'].format(len(keys),
interaction.guild.name),
color=nextcord.Color.green())
del_count = 0
final_list = []
hub_list = []
for num, key in enumerate(keys):
try:
final_list.append(f"\n\n`{num + 1}.` <#{int(key.split(':')[2])}>")
hub_list.append(int(key.split(":")[2]))
except:
r.delete(key)
del_count += 1
for key in temp_keys:
try:
ch = r.get(key)
if int(ch) in hub_list:
# find the index of the channel in the hub_list
index = hub_list.index(int(ch))
final_list.insert(index + 1, f"\n` └` <#{key.split(':')[2]}>")
hub_list.insert(index + 1, int(ch))
except:
r.delete(key)
del_count += 1
value = ""
for i in range(len(final_list)):
value = value + final_list[i]
embed.add_field(name=lang['LIST']['embed_field_name'], value=value, inline=False)
if del_count > 0:
embed.set_footer(text=lang['LIST']['embed_footer'].format(del_count))
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['LIST']['error'], description=lang['LIST']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
# clear command
@client.slash_command(name=fallback_lang['CLEAR']['name'], description=fallback_lang['CLEAR']['description'],
dm_permission=False, default_member_permissions=8)
async def clear(interaction: Interaction):
lang = lang_check(interaction.locale)
keys = r.keys(f"temp:{interaction.guild.id}:*")
if len(keys) == 0:
embed = nextcord.Embed(title=lang['CLEAR']['empty'],
description=lang['CLEAR']['empty_description'].format(interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['CLEAR']['loading'],
description=lang['CLEAR']['loading_description'].format(len(keys), len(keys)),
color=nextcord.Color.blue())
output = await interaction.response.send_message(embed=embed, ephemeral=True)
error_count = 0
for key in keys:
r.delete(key)
try:
channel = client.get_channel(int(key.split(':')[2]))
await channel.delete()
except:
error_count += 1
if error_count == 0:
embed = nextcord.Embed(title=lang['CLEAR']['success'],
description=lang['CLEAR']['success_description'].format(len(keys)),
color=nextcord.Color.green())
elif error_count == len(keys):
embed = nextcord.Embed(title=lang['CLEAR']['failure'],
description=lang['CLEAR']['failure_description'].format(len(keys)),
color=nextcord.Color.red())
else:
embed = nextcord.Embed(title=lang['CLEAR']['partial'],
description=lang['CLEAR']['partial_description'].format(len(keys), error_count),
color=nextcord.Color.yellow())
await output.edit(embed=embed)
# help command
@client.slash_command(name=fallback_lang['HELP']['name'], description=fallback_lang['HELP']['description'],
dm_permission=True)
async def help(interaction: Interaction,
arg: str = nextcord.SlashOption(
name=fallback_lang['HELP']['argument'],
description=fallback_lang['HELP']['argument_description'],
required=False,
choices=[fallback_lang['CREATE']['name'], fallback_lang['DELETE']['name'],
fallback_lang['LIST']['name'], fallback_lang['CLEAR']['name'],
fallback_lang['HELP']['name'], fallback_lang['INVITE']['name'],
fallback_lang['PING']['name'], fallback_lang['DASHBOARD']['name']]
)):
lang = lang_check(interaction.locale)
if arg == None:
embed = nextcord.Embed(title=lang['HELP']['embed_title'], description=lang['HELP']['embed_description'],
color=nextcord.Color.green())
embed.add_field(name=f"**· /{lang['CREATE']['name']} `{lang['HELP']['voice_channel']}`**",
value=lang['CREATE']['description'], inline=False)
embed.add_field(name=f"**· /{lang['DELETE']['name']} `{lang['HELP']['voice_channel']}`**",
value=lang['DELETE']['description'], inline=False)
embed.add_field(name=f"**· /{lang['LIST']['name']}**", value=lang['LIST']['description'], inline=False)
embed.add_field(name=f"**· /{lang['CLEAR']['name']}**", value=lang['CLEAR']['description'], inline=False)
embed.add_field(name=f"**· /{lang['INVITE']['name']}**", value=lang['INVITE']['description'], inline=False)
embed.add_field(name=f"**· /{lang['PING']['name']}**", value=lang['PING']['description'], inline=False)
embed.add_field(name=f"**· /{lang['HELP']['name']} `{lang['HELP']['command']}` ({lang['HELP']['optional']})**",
value=lang['HELP']['description'], inline=False)
embed.add_field(name=f"**· /{lang['DASHBOARD']['name']}**", value=lang['DASHBOARD']['description'],
inline=False)
embed.set_footer(text=lang['HELP']['footer'].format(f"/{lang['HELP']['name']} <{lang['HELP']['command']}>"))
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
if arg == lang['CREATE']['name']:
embed = nextcord.Embed(title=f"{lang['CREATE']['name']}", description=lang['CREATE']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'],
value=f"/{lang['CREATE']['name']} `{lang['HELP']['voice_channel']}`", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_administrator']}`",
inline=False)
elif arg == lang['DELETE']['name']:
embed = nextcord.Embed(title=f"{lang['DELETE']['name']}", description=lang['DELETE']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'],
value=f"/{lang['DELETE']['name']} `{lang['HELP']['voice_channel']}`", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_administrator']}`",
inline=False)
elif arg == lang['LIST']['name']:
embed = nextcord.Embed(title=f"{lang['LIST']['name']}", description=lang['LIST']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'], value=f"/{lang['LIST']['name']}", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_none']}`", inline=False)
elif arg == lang['CLEAR']['name']:
embed = nextcord.Embed(title=f"{lang['CLEAR']['name']}", description=lang['CLEAR']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'], value=f"/{lang['CLEAR']['name']}", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_administrator']}`",
inline=False)
elif arg == lang['HELP']['name']:
embed = nextcord.Embed(title=f"{lang['HELP']['name']}", description=lang['HELP']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'],
value=f"/{lang['HELP']['name']} `{lang['HELP']['command']}` ({lang['HELP']['optional']})",
inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_none']}`", inline=False)
elif arg == lang['INVITE']['name']:
embed = nextcord.Embed(title=f"{lang['INVITE']['name']}", description=lang['INVITE']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'], value=f"/{lang['INVITE']['name']}", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_none']}`", inline=False)
elif arg == lang['PING']['name']:
embed = nextcord.Embed(title=f"{lang['PING']['name']}", description=lang['PING']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'], value=f"/{lang['PING']['name']}", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_none']}`", inline=False)
elif arg == lang['DASHBOARD']['name']:
embed = nextcord.Embed(title=f"{lang['DASHBOARD']['name']}", description=lang['DASHBOARD']['description'],
color=nextcord.Color.green())
embed.add_field(name=lang['HELP']['usage'], value=f"/{lang['DASHBOARD']['name']}", inline=False)
embed.add_field(name=lang['HELP']['permission'], value=f"`{lang['HELP']['permission_administrator']}`",
inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)
# ping command
@client.slash_command(name=fallback_lang['PING']['name'], description=fallback_lang['PING']['description'],
dm_permission=True)
async def ping(interaction: Interaction):
templang = lang_check(interaction.locale)
embed = nextcord.Embed(title=templang['PING']['embed_title'],
description=templang['PING']['embed_description'].format(round(client.latency * 1000)),
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
# invite command
@client.slash_command(name=fallback_lang['INVITE']['name'], description=fallback_lang['INVITE']['description'],
dm_permission=True)
async def invite(interaction: Interaction):
lang = lang_check(interaction.locale)
embed = nextcord.Embed(title=lang['INVITE']['embed_title'], description=lang['INVITE']['embed_description'],
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
# dashboard command
@client.slash_command(name=fallback_lang['DASHBOARD']['name'], description=fallback_lang['DASHBOARD']['description'],
dm_permission=False, default_member_permissions=8)
async def settings(interaction: Interaction):
lang = lang_check(interaction.locale)
keys = r.keys(f"auto:{interaction.guild.id}:*")
temp_keys = r.keys(f"temp:{interaction.guild.id}:*")
embed = nextcord.Embed(title=lang['DASHBOARD']['embed_title'].format(interaction.guild.name),
description=lang['DASHBOARD']['embed_description'], color=nextcord.Color.green())
# Gets all the voice channels and adds them to the embed field
final = ''
if len(keys) > 0:
for key in keys:
final += f"\n<#{int(key.split(':')[2])}>"
else:
final = lang['DASHBOARD']['none']
embed.add_field(name=lang['DASHBOARD']['auto_channel'].format(len(keys)), value=final, inline=True)
# Gets all the temp voice channels and adds them to the embed field
final = ''
if len(temp_keys) > 0:
for key in temp_keys:
final += f"\n<#{int(key.split(':')[2])}>"
else:
final = lang['DASHBOARD']['none']
embed.add_field(name=lang['DASHBOARD']['temp_channel'].format(len(temp_keys)), value=final, inline=True)
selections = [
nextcord.SelectOption(label=lang['DASHBOARD']['selection_add'], value='add', emoji='➕'),
nextcord.SelectOption(label=lang['DASHBOARD']['selection_remove'], value='remove', emoji='➖'),
nextcord.SelectOption(label=lang['DASHBOARD']['selection_clear'], value='clear', emoji='🧹'),
nextcord.SelectOption(label=lang['DASHBOARD']['selection_list'], value='list', emoji='📜'),
]
view = DropdownMenu(selections)
await interaction.response.send_message(embed=embed, ephemeral=True, view=view)
# on user joining/leaving voice channel
@client.event
async def on_voice_state_update(member, before, after):
# if user leaves a voice channel
if before.channel != None:
if r.get(f"temp:{before.channel.guild.id}:{before.channel.id}") != None:
print(f'{BC.OKBLUE}{member}{BC.RESET} has left temp channel {BC.OKBLUE}{before.channel}{BC.RESET}(ID: {BC.OKBLUE}{before.channel.id}{BC.RESET})')
if len(before.channel.members) == 0:
try:
await before.channel.delete()
r.delete(f"temp:{before.channel.guild.id}:{before.channel.id}")
print(f'{BC.OKBLUE}{before.channel}{BC.RESET}(ID: {BC.OKBLUE}{before.channel.id}{BC.RESET}) has been deleted because it is empty.')
except:
print(f'{BC.WARNING}Failed to delete {BC.OKBLUE}{before.channel}{BC.WARNING}.')
# if user joins / transfers to a voice channel
if after.channel != None:
if r.get(f"auto:{after.channel.guild.id}:{after.channel.id}") != None:
print(f'{BC.OKBLUE}{member}{BC.RESET} has joined auto channel {BC.OKBLUE}{after.channel}{BC.RESET}(ID: {BC.OKBLUE}{after.channel.id}{BC.RESET})')
category = after.channel.category
overwrites = {member: nextcord.PermissionOverwrite(manage_channels=True)}
try:
new_channel = await after.channel.guild.create_voice_channel(name=member.display_name, category=category,
overwrites=overwrites)
r.set(f"temp:{after.channel.guild.id}:{new_channel.id}", after.channel.id)
print(f'Created temp channel {BC.OKBLUE}{new_channel}{BC.RESET}(ID: {BC.OKBLUE}{new_channel.id}{BC.RESET})')
except:
print(f'{BC.WARNING}Failed to create temp channel for {BC.OKBLUE}{member}{BC.WARNING}.')
try:
await member.move_to(new_channel)
print(f'Moved {BC.OKBLUE}{member}{BC.RESET} to temp channel {BC.OKBLUE}{new_channel}{BC.RESET}(ID: {BC.OKBLUE}{new_channel.id}{BC.RESET})')
except:
print(f'{BC.WARNING}Failed to move {BC.OKBLUE}{member}{BC.WARNING} to temp channel {BC.OKBLUE}{new_channel}{BC.RESET}(ID: {BC.OKBLUE}{new_channel.id}{BC.RESET})')
# when voice channel is deleted
@client.event
async def on_guild_channel_delete(channel):
if r.get(f"auto:{channel.guild.id}:{channel.id}") != None:
r.delete(f"auto:{channel.guild.id}:{channel.id}")
# Class to handle the dropdown
class Dropdown(nextcord.ui.Select):
def __init__(self, options):
super().__init__(placeholder=fallback_lang['DROPDOWN']['placeholder'], options=options)
async def callback(self, interaction: Interaction):
lang = lang_check(interaction.locale)
if self.values[0] == 'clear':
keys = r.keys(f"temp:{interaction.guild.id}:*")
if len(keys) == 0:
embed = nextcord.Embed(title=lang['CLEAR']['empty'],
description=lang['CLEAR']['empty_description'].format(interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['CLEAR']['loading'],
description=lang['CLEAR']['loading_description'].format(len(keys), len(keys)),
color=nextcord.Color.blue())
output = await interaction.response.send_message(embed=embed, ephemeral=True)
error_count = 0
for key in keys:
r.delete(key)
try:
channel = client.get_channel(int(key.split(':')[2]))
await channel.delete()
except:
error_count += 1
if error_count == 0:
embed = nextcord.Embed(title=lang['CLEAR']['success'],
description=lang['CLEAR']['success_description'].format(len(keys)),
color=nextcord.Color.green())
elif error_count == len(keys):
embed = nextcord.Embed(title=lang['CLEAR']['failure'],
description=lang['CLEAR']['failure_description'].format(len(keys)),
color=nextcord.Color.red())
else:
embed = nextcord.Embed(title=lang['CLEAR']['partial'],
description=lang['CLEAR']['partial_description'].format(len(keys),
error_count),
color=nextcord.Color.yellow())
await output.edit(embed=embed)
elif self.values[0] == 'add':
selections = []
# get all the voice channels in the server
for channel in interaction.guild.voice_channels:
# check if the channel is already added
if r.get(f"auto:{interaction.guild.id}:{channel.id}") == None:
selections.append(nextcord.SelectOption(label=channel.name, emoji='🔊', description=channel.id,
value=f'addvoice:{channel.id}'))
if len(selections) == 0:
embed = nextcord.Embed(title=lang['DROPDOWN']['add_empty'],
description=lang['DROPDOWN']['add_empty_description'].format(
interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
view = DropdownMenu(selections)
embed = nextcord.Embed(title=lang['DROPDOWN']['add_title'],
description=lang['DROPDOWN']['add_description'], color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True, view=view)
elif self.values[0] == 'remove':
selections = []
# get all the voice channels in the server from redis
keys = r.keys(f"auto:{interaction.guild.id}:*")
if len(keys) == 0:
embed = nextcord.Embed(title=lang['DROPDOWN']['remove_empty'],
description=lang['DROPDOWN']['remove_empty_description'].format(
interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
for key in keys:
channel = client.get_channel(int(key.split(':')[2]))
selections.append(nextcord.SelectOption(label=channel.name, emoji='🔊', description=channel.id,
value=f'removevoice:{channel.id}'))
view = DropdownMenu(selections)
embed = nextcord.Embed(title=lang['DROPDOWN']['remove_title'],
description=lang['DROPDOWN']['remove_description'], color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True, view=view)
elif self.values[0] == 'list':
try:
keys = r.keys(f"auto:{interaction.guild.id}:*")
temp_keys = r.keys(f"temp:{interaction.guild.id}:*")
if len(keys) + len(temp_keys) == 0:
embed = nextcord.Embed(title=lang['LIST']['empty'],
description=lang['LIST']['empty_description'].format(interaction.guild.name),
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['LIST']['embed_title'],
description=lang['LIST']['embed_description'].format(len(keys),
interaction.guild.name),
color=nextcord.Color.green())
del_count = 0
final_list = []
hub_list = []
for num, key in enumerate(keys):
try:
final_list.append(f"\n\n`{num + 1}.` <#{int(key.split(':')[2])}>")
hub_list.append(int(key.split(":")[2]))
except:
r.delete(key)
del_count += 1
for key in temp_keys:
try:
ch = r.get(key)
if int(ch) in hub_list:
# find the index of the channel in the hub_list
index = hub_list.index(int(ch))
final_list.insert(index + 1, f"\n` └` <#{key.split(':')[2]}>")
hub_list.insert(index + 1, int(ch))
except:
r.delete(key)
del_count += 1
value = ""
for i in range(len(final_list)):
value = value + final_list[i]
embed.add_field(name=lang['LIST']['embed_field_name'], value=value, inline=False)
if del_count > 0:
embed.set_footer(text=lang['LIST']['embed_footer'].format(del_count))
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['LIST']['error'], description=lang['LIST']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
elif self.values[0].startswith('addvoice:'):
channel_id = self.values[0].split(':')[1]
category = client.get_channel(int(channel_id)).category
try:
if r.exists(f"auto:{interaction.guild.id}:{channel_id}"):
embed = nextcord.Embed(title=lang['CREATE']['duplicate'],
description=lang['CREATE']['duplicate_description'],
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
r.set(f"auto:{interaction.guild.id}:{channel_id}", category.id)
embed = nextcord.Embed(title=lang['CREATE']['success'],
description=lang['CREATE']['success_description'].format(f'<#{channel_id}>'),
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['CREATE']['error'], description=lang['CREATE']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
elif self.values[0].startswith('removevoice:'):
channel_id = self.values[0].split(':')[1]
try:
if r.exists(f"auto:{interaction.guild.id}:{channel_id}"):
r.delete(f"auto:{interaction.guild.id}:{channel_id}")
embed = nextcord.Embed(title=lang['DELETE']['success'],
description=lang['DELETE']['success_description'].format(f'<#{channel_id}>'),
color=nextcord.Color.green())
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = nextcord.Embed(title=lang['DELETE']['not_found'],
description=lang['DELETE']['not_found_description'],
color=nextcord.Color.yellow())
await interaction.response.send_message(embed=embed, ephemeral=True)
except:
embed = nextcord.Embed(title=lang['DELETE']['error'], description=lang['DELETE']['error_description'],
color=nextcord.Color.red())
await interaction.response.send_message(embed=embed, ephemeral=True)
class DropdownMenu(nextcord.ui.View):
def __init__(self, options):
super().__init__()
self.add_item(Dropdown(options))
try:
client.run(token)
except(nextcord.errors.LoginFailure):
print(f'''{BC.FAIL}Error: Token is invalid.
Please check the token in config file (config.ini) and try again.
Exiting in 5 seconds...{BC.RESET}
''')
time.sleep(5)
exit()