This repository was archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraft.py
More file actions
279 lines (237 loc) · 8.69 KB
/
Copy pathdraft.py
File metadata and controls
279 lines (237 loc) · 8.69 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
import uuid
import enum
import discord
from helper import clear_dm, format_tables
class Captain:
def __init__(self, user: discord.User):
self.id = user.id
self.name = user.name
self.dm_channel = user.dm_channel
self.picks = [None, None, None]
self.bans = [None, None]
def pick(self, pick: str, pick_n: int) -> None:
self.picks[pick_n] = pick
def ban(self, ban: str, ban_n: int) -> None:
self.bans[ban_n] = ban
CHAMP_LIST = [
"alysia", "ashka", "bakko", "blossom", "croak", "destiny", "ezmo", "freya",
"iva", "jade", "jamila", "jumong", "lucie", "oldur", "pearl", "pestilus",
"poloma", "raigon", "rook", "ruh kaan", "shen rao", "shifu", "sirius",
"taya", "thorn", "ulric", "varesh", "zander",
]
CHAMP_ALIAS_DICT = {
"blos": "blossom", "pest": "pestilus", "dio": "pearl",
"ruh": "ruh kaan", "rk": "ruh kaan", "shen": "shen rao",
"luke": "freya", "dest": "destiny", "pol": "poloma",
"lucy": "lucie", "jam": "jamila", "jum": "jumong",
"var": "varesh", "uni": "jumong", "frog": "croak",
"polo": "poloma", "catchy": "thorn", "tomiy": "rook",
"LDK": "bakko", "chisaku": "jade", "peon": "poloma",
"averse": "taya", "arkdn": "rook", "mGalante": "rook"
}
unique_ids = []
class DraftState(enum.Enum):
FIRST_BAN = 0
FIRST_PICK = 1
SECOND_PICK = 2
SECOND_BAN = 3
THIRD_PICK = 4
COMPLETE = 5
class Draft:
def __init__(self, user1: discord.User, user2: discord.User = None) -> None:
# regenerate id until unique
self.id = str(uuid.uuid1())[:6]
while self.id in unique_ids:
self.id = str(uuid.uuid1())[:6]
unique_ids.append(self.id)
self.state = DraftState.FIRST_BAN
self.messages = []
self.ihl = False
self.ihl_channel_id = 710901389232046080
self.banned_champs = []
# init captains
self.captain1 = Captain(user1)
self.captain2 = Captain(user2) if user2 else None
# init table
empty_fields = '----\n----\n----\n\n----\n----'
self.table = discord.Embed(color = 16753152)
self.table.add_field(name = 'Captains', value = 'Picks\n\n\n\nBans')
self.table.add_field(
name = '**' + user1.name + '**',
value = empty_fields
)
if user2:
self.table.add_field(
name = '**' + user2.name + '**',
value = empty_fields
)
def add_captain(self, user: discord.User) -> None:
self.captain2 = Captain(user)
self.table.add_field(
name = '**' + user.name + '**',
value = '----\n----\n----\n\n----\n----'
)
def advance_state(self) -> None:
if self.state == DraftState.FIRST_BAN:
self.state = DraftState.FIRST_PICK
elif self.state == DraftState.FIRST_PICK:
self.state = DraftState.SECOND_PICK
elif self.state == DraftState.SECOND_PICK:
self.state = DraftState.SECOND_BAN
elif self.state == DraftState.SECOND_BAN:
self.state = DraftState.THIRD_PICK
elif self.state == DraftState.THIRD_PICK:
self.state = DraftState.COMPLETE
def update_table(self, captain: Captain, champ: str) -> None:
index = 1 if captain == self.captain1 else 2
name = self.table.fields[index].name
value = self.table.fields[index].value
picks = []
bans = []
for pick in captain.picks:
if pick:
picks.append(pick.capitalize())
else:
picks.append('----')
picks = '\n'.join(picks)
for ban in captain.bans:
if ban:
bans.append(ban.capitalize())
else:
bans.append('----')
bans = '\n'.join(bans)
self.table.set_field_at(
index = index,
name = name,
value = '\n\n'.join([picks, bans])
)
async def pick(self, author: discord.User, champ: str) -> bool:
channel = author.dm_channel
if champ in CHAMP_ALIAS_DICT:
champ = CHAMP_ALIAS_DICT[champ]
if champ not in CHAMP_LIST:
await channel.send(champ + ' is not a valid champ.')
return False
if author.id == self.captain1.id:
captain = self.captain1
enemy_captain = self.captain2
captain_num = 0
else:
captain = self.captain2
enemy_captain = self.captain1
captain_num = 1
# unique IHL champ bans
if self.banned_champs:
if champ in self.banned_champs:
await channel.send(
champ.capitalize() + ' is unpickable by NAIL.'
)
return False
# checks for pickable champ
if champ in enemy_captain.bans:
await channel.send(
champ.capitalize() + ' has been banned by the enemy team.'
)
return False
elif champ in captain.picks:
await channel.send(
champ.capitalize() + ' has already been picked by your team.'
)
return False
both_picked = False
if self.state == DraftState.FIRST_PICK:
if captain.picks[0]:
await channel.send(
'Updated pick to ' + champ.capitalize()
)
captain.pick(champ, 0)
if enemy_captain.picks[0]:
both_picked = True
elif self.state == DraftState.SECOND_PICK:
if captain.picks[1]:
await channel.send(
'Updated pick to ' + champ.capitalize()
)
captain.pick(champ, 1)
if enemy_captain.picks[1]:
both_picked = True
else:
if captain.picks[2]:
await channel.send(
'Updated pick to ' + champ.capitalize()
)
captain.pick(champ, 2)
if enemy_captain.picks[2]:
both_picked = True
champ = champ.capitalize()
if both_picked:
self.update_table(captain, champ)
self.advance_state()
return True
self.update_table(captain, champ)
# await clear_dm(captain.dm_channel)
tables = format_tables(self.table)
await channel.send(embed = tables[captain_num])
await channel.send('Waiting for opposing captain to pick.')
return False
async def ban(self, author: discord.User, champ: str) -> bool:
channel = author.dm_channel
if champ in CHAMP_ALIAS_DICT:
champ = CHAMP_ALIAS_DICT[champ]
if champ not in CHAMP_LIST:
await channel.send(champ + ' is not a valid champ.')
return False
if author.id == self.captain1.id:
captain = self.captain1
enemy_captain = self.captain2
captain_num = 0
else:
captain = self.captain2
enemy_captain = self.captain1
captain_num = 1
# unique IHL champ bans
if self.banned_champs:
if champ in self.banned_champs:
await channel.send(
champ.capitalize() + ' is unpickable by NAIL already.'
)
return False
# checks for banable champ
if champ in enemy_captain.picks:
await channel.send(
champ.capitalize() + ' has already been picked by the enemy team.'
)
return False
elif champ in captain.bans:
await channel.send(
champ.capitalize() + ' has already been banned by your team.'
)
return False
both_banned = False
if self.state == DraftState.FIRST_BAN:
if captain.bans[0]:
await channel.send(
'Updated ban to ' + champ.capitalize()
)
captain.ban(champ, 0)
if enemy_captain.bans[0]:
both_banned = True
else:
if captain.bans[1]:
await channel.send(
'Updated ban to ' + champ.capitalize()
)
captain.ban(champ, 1)
if enemy_captain.bans[1]:
both_banned = True
champ = champ.capitalize()
if both_banned:
self.update_table(captain, champ)
self.advance_state()
return True
self.update_table(captain, champ)
# await clear_dm(captain.dm_channel)
tables = format_tables(self.table)
await channel.send(embed = tables[captain_num])
await channel.send('Waiting for opposing captain to ban.')
return False