-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
365 lines (288 loc) · 12.8 KB
/
main.py
File metadata and controls
365 lines (288 loc) · 12.8 KB
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
import discord
import os
import random
from discord.ext import commands, tasks
from discord.ext.commands import check
intents = discord.Intents.default() # Discord policy
intents.members = True # Discord policy
lol_squad = [] # Leageu of legends teams container
voice_channel_list = [] # Fetch all channels from server
voiceChannel_1, voiceChannel_2 = None, None # Index of voice channel
team1, team2 = 0, 0 # Points
globalPlayers = []
#sanetro
bot = commands.Bot(intents=intents, command_prefix='$', help_command=None) # Client object app name - bot, command always start with '$' before
TOKEN = ""
class Player:
def __init__(self, name, point=0):
self.point = point
self.name = name
def add(self):
self.point = self.point + 1
def update(self, nameImport, pointImport):
self.point = pointImport
self.name = nameImport
def id(self):
print(self.name, self.point)
def giveName(self):
return self.name
# -------- TEAMS BOARD -------- #
def justify_lead_board(lol_squad):
border = "-"*34
tabs = "\t"*3
tmp2 = f">>> {border}{border}\n {tabs}Team 1{tabs}{tabs}{tabs}Team 2{tabs}\t\n {border}{border}\n"
result = tmp2
for i in range(len(lol_squad)//2):
result += tabs + lol_squad[i] + tabs*3 + lol_squad[i+5] + "\n"
return result
# -------- SCORES BOARD -------- #
def justify_score_board(team1,team2):
tmp = f'```diff\n\n+\t\tTeam 1\t\tTeam 2\n-\t\t {team1}\t\t:\t {team2}\n\n```'
tmp = f'''
>>> Score
-------------------------
Team 1 : **{team1}**
Team 2 : **{team2}**
-------------------------
'''
return tmp
# -------- PLAYERS LIST -------- #
def returnListOfSqad_lol(lol_squad):
tmp = ">>> \n**Here is your players list**:\n\n"
for i in range(len(lol_squad)): tmp += f"{i+1}\t" + str(lol_squad[i].name) + "\n"
return tmp
# -------- RANDOMIZE ALL PLAYERS -------- #
# Description : shuffle and draws teams
@bot.command(name="rand", description="Shuffle and draws teams ")
async def rand(ctx):
teamINFO = ""
random.shuffle(lol_squad)
teamINFO += "\n╔═════╬**Team 1**╬═════\n║\n"
for i in range(0, len(lol_squad), 2): teamINFO += f" ╠ **{lol_squad[i].name}**\n"
teamINFO += "\n\n╔═════╬**Team 2**╬═════\n║\n"
for i in range(1, len(lol_squad), 2): teamINFO += f" ╠ **{lol_squad[i].name}**\n"
teamINFO += "\n\nGood luck! dont't forget to ban Jhin."
mbed = discord.Embed(title='Lol Team Custom Randomize', description=teamINFO, colour = discord.Colour.default())
await ctx.send(embed=mbed)
# -------- SET PLAYERS -------- #
# Description
# Input users after 'at' (@) symbol. For example: $players @sanetro @someone @etc ...
@bot.command(name="players", description="Add to list a player to draw for one of the team")
async def players(ctx, *members : discord.Member):
global lol_squad
for user in members:
if not user in lol_squad:
lol_squad.append(user)
globalPlayers.append({"name" : user.name, "points" : 0})
else:
await ctx.send(f"The **{user.name}** is already on the list.")
await ctx.send(returnListOfSqad_lol(lol_squad))
#for member in lol_squad: objectsOfPlayers.append(Player(member.name))
# -------- REMOVE PLAYERS -------- #
# Description
# Same function as players() but it removes player from list
@bot.command(name="remove", description="Remove player from list")
async def remove(ctx, *members : discord.Member):
global lol_squad
for user in members:
if user in lol_squad:
lol_squad.remove(user)
else:
await ctx.send(f"The **{user.name}** isn't on the list.")
# -------- CLEAR PLAYERS -------- #
@bot.command(name="clear", description="Clear list of squad")
async def clear(ctx):
global lol_squad; lol_squad = []; await ctx.send(f"List is empty.")
# -------- MOVE ALL USERS -------- #
# Description
# Most important. This sends members to particular channels ('Team_1'; 'Team_2')
# It sends a embed (something like message, but with better border)
@bot.command(name="start", description="It moves teams to channels. (Start of the game)")
async def start(ctx):
global lol_squad
vc1 = voice_channel_list[voiceChannel_1]
vc2 = voice_channel_list[voiceChannel_2]
for i in range(len(lol_squad)):
try:
if(i % 2 == 0):
await lol_squad[i].move_to(vc1)
mbed = discord.Embed(title='{} moved to {}.'.format(lol_squad[i].name, vc1),
description="start by {}".format(ctx.message.author.name),
colour = discord.Colour.orange())
else:
await lol_squad[i].move_to(vc2)
mbed = discord.Embed(title='{} moved to {}.'.format(lol_squad[i].name, vc2),
description="start by {}".format(ctx.message.author.name),
colour = discord.Colour.purple())
except:
mbed = discord.Embed(title='Player problem',
description="{} isn't in voice channel.".format(lol_squad[i].name),
colour = discord.Colour.red())
await ctx.send(embed=mbed)
# -------- SHOW - list of squad -------- #
@bot.command(name="show", description="Simple list of players in squad")
async def show(ctx):
await ctx.send(returnListOfSqad_lol(lol_squad))
# -------- RESET -------- #
@bot.command(name="reset", description="reset score")
async def reset(ctx):
team1, team2 = 0, 0; await ctx.send(justify_score_board(team1,team2))
# -------- SCORE -------- #
@bot.command(name="score", description="Shows score of team one and team two")
async def score(ctx):
await ctx.send(justify_score_board(team1,team2))
# -------- TOP -------- #
@bot.command(name="top", description="Shows top list")
async def top(ctx):
objectsOfPlayers = []
with open("Toplist.txt", "r") as file:
for index, line in enumerate(file):
record = line.split()
objectsOfPlayers.append(Player(record[0], int(record[1]))) # 0 - name; 1 - points
file.close()
playersList = "\n\n"
sortedList = sorted(objectsOfPlayers, key=lambda x: x.point, reverse=True)
for index in range(len(sortedList)-1):
if index == 0:
playersList += f"\n{index+1} ✨👑 **{sortedList[index].name}** 👑✨ ({sortedList[index].point})\n\n"
elif index == 1:
playersList += f"{index+1} ✨ **{sortedList[index].name}** ✨ ({sortedList[index].point})\n\n"
elif index == 2:
playersList += f"{index+1} 🔥 **{sortedList[index].name}** 🔥 ({sortedList[index].point})\n\n"
playersList += "════════════════════════════\n"
else:
playersList += f"{index+1} **{sortedList[index].name}** ({sortedList[index].point})\n"
mbed = discord.Embed(title='═════LIST OF BEST PLAYERS═════',
description=playersList,
colour = discord.Colour.gold())
await ctx.send(embed=mbed)
# -------- addpoint - team 1 - team 2 -------- #
@bot.command(name="addpoint", description="Give one point to team. $team 1 - gives one point to first team. $team 2 - gives one point to second team")
async def addpoint(ctx, index):
global team1, team2
fileList = []
with open("Toplist.txt", "r") as f:
for data in f:
row = data.split()
fileList.append({"name" : row[0], "points" : int(row[1])})
f.close()
for innerUser in globalPlayers:
print("For: ", innerUser["name"])
for user in fileList:
print("\t", user["name"], user["points"])
if user["name"] == innerUser["name"]:
break
else:
fileList.append(innerUser)
print("\t", innerUser["name"], "added to the list.")
if index == "1":
team1 += 1
for innerUser in globalPlayers:
for i in range(0, len(fileList), 2):
if innerUser["name"] == fileList[i]["name"]:
fileList[i]["points"] = int(fileList[i]["points"]) =+ 1
elif index == "2":
team2 += 1
for innerUser in globalPlayers:
for i in range(1, len(fileList), 2):
if innerUser["name"] == fileList[i]["name"]:
fileList[i]["points"] = int(fileList[i]["points"]) =+ 1
else:
await ctx.send("Please choose between 1 and 2. Thanks.", index)
with open("Toplist.txt", "w") as file:
for user in fileList:
tmp = f"{user['name']} {user['points']}\n"
file.write(tmp)
file.close()
if index == "1" or index == "2": await ctx.send(justify_score_board(team1, team2))
@bot.command(name="about", description="All you need to know about me and bot.")
async def about(ctx):
await ctx.message.author.send(voice_channel_list[voiceChannel_1])
# -------- QUICK INFORMATION - when mention bot -------- #
@bot.event
async def on_message(message):
welcomeText = f'''>>> Hello everyone,
I am a **{bot.user.name}**
Installation:
1. You should give admin permisions to this bot
2. $setup - it creates 3 channels important for this bot
3. $help - commands list
'''
mention = f'<@!{bot.user.id}>'
if mention in message.content:
await message.channel.send(welcomeText)
else:
await bot.process_commands(message)
# -------- FIND CHANNELS -------- #
def fetchVoiceChannels():
global voiceChannel_1, voiceChannel_2
global voice_channel_list
for guild in bot.guilds:
for channel in guild.voice_channels:
voice_channel_list.append(channel)
print("Voice channels list:")
[print(i, info) for i, info in enumerate(voice_channel_list)]
for index, vc in enumerate(voice_channel_list):
if vc.name == "Team_1":
voiceChannel_1 = index; print("Team_1 found")
if vc.name == "Team_2":
voiceChannel_2 = index; print("Team_2 found")
# -------- CREATE CHANNELS -------- #
@bot.command(name="setenv", description="Create environment for bot to set up your homies in voice channels. (TYPE THIS COMMAND FIRST)")
async def setenv(ctx):
guild = ctx.guild
mbed = discord.Embed(title='Bad permission', description='Can not create a channels.')
if ctx.author.guild_permissions.manage_channels:
await guild.create_voice_channel(name='Team_1')
await guild.create_voice_channel(name='Team_2')
await guild.create_voice_channel(name='Lobby')
mbed = discord.Embed(title='Success', description='Voice channels Team 1, Team 2 and Lobby has been created.')
await ctx.send(embed=mbed)
fetchVoiceChannels()
else:
await ctx.send("No permissions")
# -------- DELETE CHANNELS OF ENV -------- #
@bot.command(name="delete_env", description="Show the all list of members in this server")
async def delete_env(ctx):
existing_channel1 = discord.utils.get(ctx.guild.channels, name="Team_1")
existing_channel2 = discord.utils.get(ctx.guild.channels, name="Team_2")
existing_channel3 = discord.utils.get(ctx.guild.channels, name="Lobby")
if existing_channel1 is not None and existing_channel2 is not None and existing_channel3 is not None:
await existing_channel1.delete()
await existing_channel2.delete()
await existing_channel3.delete()
else:
await ctx.send(f'No channel was found')
@bot.command()
async def help(ctx):
helpMessage = """>>> \n**List of commands**\n
**delete_env** Show the all list of members in this server
**setenv** Create environment for bot to set up your
homies in voice channels. (TYPE THIS FIRST)
**addpoint** Give one point to team:
$addpoint 1 - gives one point to first team
$addpoint 2 - gives one point to second team
**about** All you need to know about me and bot
**score** Shows score of team one and team two
**start** It moves teams to channels. (Start of the game)
**clear** Clear list of squad
**remove** Remove player from list
**players** Add to list a player to draw for one of the team
**rand** Shuffle and draws teams
**reset** Reset score
**show** Show score
**top** Show list of players who got many wins (TOP of)
"""
await ctx.send(helpMessage)
# -------- WAKE UP BOT - we have a world to burn -------- #
@bot.event
async def on_ready():
msg = f'''
BOT NAME {bot.user.name}
BOT ID {bot.user.id}
DIRECTORY {os.path.abspath(os.getcwd())}
'''
print(msg)
fetchVoiceChannels()
await bot.change_presence(activity=discord.Game(name="$help or mention"))
bot.run(TOKEN)