Repository navigation
Expand file tree
/
Copy pathdraft.py
More file actions
196 lines (181 loc) · 6.73 KB
/
Copy pathdraft.py
File metadata and controls
196 lines (181 loc) · 6.73 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
from aliases import *
from printFunctions import *
from maps import *
from emojis import emoji
import asyncio
import discord
banEmojis={'Ana':'🍌',
'Samuro':'<:banned:557364849940758528>',
'Tassadar':'<:bannedLogan:673197798786596864>',
'Valeera':'<:bannedVal:679014495447678998>'}
banEmojis={}
def simplifyName(hero):#Turn underscores into spaces
hero=hero.replace('_',' ')
return hero
async def getWhiteSpaceLength(draftList,teamNameA):
order='mABABabbaaBAbbaab'
bansA=[]
for i in [1,3,11]:
try: bansA.append(draftList[i])
except:pass
return max(25,3+len(', '.join(bansA)),12+len(teamNameA))
async def addCompleteReactions(completeDraft,message):
if completeDraft:
await message.add_reaction('🇦')
await message.add_reaction('🇧')
async def printDraft(drafts,channel,draftList,lastDraftMessageDict,draftNames):#Print state, and the next action to be done
if channel.id not in drafts:
await channel.send(channel.id+' does not currently have an active draft.')
return
if not draftList:
await channel.send('Pick a map')
return
#Order and map have been picked now
order='mABABabbaaBAbbaab'#map, order. AB bans, ab picks
bansA=[]
bansB=[]
picks=''
#whitespaceAmount=32
try:
whitespaceAmount=await getWhiteSpaceLength(draftList,draftNames[channel.id][0])
except:
whitespaceAmount=await getWhiteSpaceLength(draftList,'')
teamA='Team A'
teamB='Team B'
try:
teamA+=' ('+draftNames[channel.id][0]+')'
teamB+=' ('+draftNames[channel.id][1]+')'
except:pass
for i in range(1,len(draftList)):
if order[i]=='A':
bansA.append(draftList[i])
elif order[i]=='B':
bansB.append(draftList[i])
elif order[i]=='a':
picks+=draftList[i]+'\n'
elif order[i]=='b':
picks+=' '*whitespaceAmount+draftList[i]+'\n'
output='```Map: '+draftList[0]+'\n\n'
output+=teamA+' '*(whitespaceAmount-len(teamA))+teamB+'\n'
output+='Bans: '+' '*(whitespaceAmount-6)+'Bans: \n'
output+=', '.join(bansA)+' '*(whitespaceAmount-len(', '.join(bansA)))+', '.join(bansB)+'\n'+'-'*(whitespaceAmount+15)+'\n'
output+='Picks:'+' '*(whitespaceAmount-6)+'Picks:\n'+picks+'\n'
completeDraft=0
if len(draftList)==17:
output+='Draft complete'
completeDraft=1
else:
nextAction=order[len(draftList)]
nextTurnIsTeamB=1
if nextAction.lower()=='a':
output+='<---------- '
nextTurnIsTeamB=0
if nextAction==nextAction.upper():
nextAction='BAN for team '+nextAction
else:
nextAction='Pick for team '+nextAction.upper()
output+='Next action: '+nextAction
try:
output+=' ('+draftNames[channel.id][nextTurnIsTeamB]+')'
except:
pass
if nextTurnIsTeamB:
output+=' ---------->'
if len(draftList)>1:
hero=aliases(draftList[-1]).replace('_',' ').replace('The Butcher','Butcher').capitalize()
fileName=''
fileExtension='.PNG' if hero=='Maiev' else '.png'
if len(draftList) in [2,3,4,5,11,12]:#Numbers are the bans
if hero in banEmojis.keys():
output=banEmojis[hero]+'\n'+output
else:
if channel in lastDraftMessageDict:
try:await lastDraftMessageDict[channel].delete()
except:pass
lastDraftMessageDict[channel]=await channel.send(output+'```',file=discord.File('Emojis/'+hero+' sad'+fileExtension))
return
else:
if channel in lastDraftMessageDict:
try:await lastDraftMessageDict[channel].delete()
except:pass
lastDraftMessageDict[channel]=await channel.send(output+'```',file=discord.File('Emojis/'+hero+' happy'+fileExtension))
await addCompleteReactions(completeDraft,lastDraftMessageDict[channel])
return
if channel in lastDraftMessageDict:
try:await lastDraftMessageDict[channel].delete()
except:pass
lastDraftMessageDict[channel]=await channel.send(output+'```')
await addCompleteReactions(completeDraft,lastDraftMessageDict[channel])
async def draft(drafts,channel,member,text,lastDraftMessageDict,draftNames,printDraftBool=True):
try:
draftList=drafts[channel.id]
except:
drafts[channel.id]=[]
draftList=drafts[channel.id]
if len(text)==2:
if text[1] in ['help','info']:
output='''MOCK DRAFTING GUIDE
[Draft] will show the current state of the draft.
[Flip] will toss a coin that can be used to randomly select who will go for first pick or Map choice after writing your head or tail preference in chat.
[Draft/<Map>] will set the Map at the beginning of the draft.
[Draft/<Hero>] will pick or ban a Hero based on the in-game drafting order.
[Draft/<Command>] will let you use a Command listed below.
Commands:
- "Help" will show this guide.
- "Reset" will reset the draft.
- "Undo" will revert the previous input.'''
await channel.send(output)
return
if await mapAliases(text[1]) in await getMaps() and len(draftList) in [0,17]:
drafts[channel.id]=[]
draftList=drafts[channel.id]
if channel in lastDraftMessageDict:del lastDraftMessageDict[channel]
battleground=await mapAliases(text[1])
draftList.append(await mapString(battleground))
await channel.send('New draft started!')
await mapImage(channel,battleground)
draftNames[channel.id]=[]
if printDraftBool:await printDraft(drafts,channel,draftList,lastDraftMessageDict,draftNames)
return
if len(text)==1: #[draft] with no second part. To call status
await printDraft(drafts,channel,draftList,lastDraftMessageDict,draftNames)
return
text=text[1]
if text.count(','):
for i in text.split(','):
await draft(drafts,channel,member,['d',i],lastDraftMessageDict,draftNames,False)
await channel.send('Draft filled! Type [d] to view')
return
if text in ['new','start','n','s','reset','r']:
drafts[channel.id]=[]
if channel in lastDraftMessageDict:del lastDraftMessageDict[channel]
await channel.send('New draft started! Choose map')
draftNames[channel.id]=[]
return
if text in ['undo','u']:
await channel.send('Undid '+draftList.pop())
elif len(draftList)<17:
if len(draftList)==1:
draftNames[channel.id]=[member.nick or member.name]
elif len(draftList)==2:
draftNames[channel.id].append(member.nick or member.name)
if simplifyName(aliases(text)) in draftList:
await channel.send(simplifyName(aliases(text))+' has already been picked/banned. Choose another!')
return
else:
if len(draftList)==0:#Map name doesn't need check
try:
battleground=await mapAliases(text)
except:
await channel.send('`Unrecognized battleground!`')
return
draftList.append(await mapString(battleground))
await mapImage(channel,battleground)
else:
hero=aliases(text)
if hero in getHeroes():
draftList.append(simplifyName(hero))
else:
await channel.send('Invalid hero!')
return
if printDraftBool:await printDraft(drafts,channel,draftList,lastDraftMessageDict,draftNames)