-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheesepicker.py
179 lines (143 loc) · 6.93 KB
/
cheesepicker.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
TOKEN = 'MTAxMzA4MDMxNDQ1MDU1NDg4MA.GLD3SY.fe7Sa7udWyGnZthh8coWU_gK0c-0zpWiHFXBXE'
import discord
import random
import json
from operator import indexOf
import requests
import functools
import asyncio
intents=discord.Intents('GUILD_MESSAGES')
client = discord.Client(intents=discord.Intents.all())
response=requests.get("https://api.opendota.com/api/heroes")
IdResponse = json.loads(response.text)
IdtoName={}
for item in IdResponse:
IdtoName[item['id']]=item['localized_name'].lower()
@client.event
async def on_ready():
print('We ahve logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
username=str(message.author).split('#')[0]
user_message=str(message.content.lower())
channel=str(message.channel.name)
print(f'{username}:{message.content}({channel})')
if message.author==client.user:
return
if message.channel.name=='cheesepick':
if user_message.lower()=='n word':
await message.channel.send('nigtaminja')
return
else:
a=str(user_message).split(',')[0]
b=str(user_message).split(',')[1]
c=str(user_message).split(',')[2]
d=str(user_message).split(',')[3]
#Convert names to id numbers from opendota
id1=[id for id,v in IdtoName.items() if v==a]
id2=[id for id,v in IdtoName.items() if v==b]
id3=[id for id,v in IdtoName.items() if v==c]
id4=[id for id,v in IdtoName.items() if v==d]
#get matchup for individual id numbers and gather winpercents from them
#this is for id1
concatHelper1=str(id1[0])
Matchuplink1="https://api.opendota.com/api/heroes/"+concatHelper1+"/matchups"
response=requests.get(Matchuplink1)
Matchup1=json.loads(response.text)
for item in Matchup1:
winpercent=(int(item['wins'])/int(item['games_played']))*100
item['winpercent1']=winpercent
del item['games_played']
del item['wins']
SortedMatchup1=sorted(Matchup1, key=lambda x: x['hero_id'])
for i in SortedMatchup1:
if i['hero_id']==id4[0]:
SortedMatchup1.remove(i)
if i['hero_id']==id2[0]:
SortedMatchup1.remove(i)
if i['hero_id']==id3[0]:
SortedMatchup1.remove(i)
#this is for id2
concatHelper2=str(id2[0])
Matchuplink2="https://api.opendota.com/api/heroes/"+concatHelper2+"/matchups"
response=requests.get(Matchuplink2)
Matchup2=json.loads(response.text)
for item in Matchup2:
winpercent=(int(item['wins'])/int(item['games_played']))*100
item['winpercent2']=winpercent
del item['games_played']
del item['wins']
SortedMatchup2=sorted(Matchup2, key=lambda x: x['hero_id'])
for i in SortedMatchup2:
if i['hero_id']==id1[0]:
SortedMatchup2.remove(i)
if i['hero_id']==id3[0]:
SortedMatchup2.remove(i)
if i['hero_id']==id4[0]:
SortedMatchup2.remove(i)
#this is for id3
concatHelper3=str(id3[0])
Matchuplink3="https://api.opendota.com/api/heroes/"+concatHelper3+"/matchups"
response=requests.get(Matchuplink3)
Matchup3=json.loads(response.text)
for item in Matchup3:
winpercent=(int(item['wins'])/int(item['games_played']))*100
item['winpercent3']=winpercent
del item['games_played']
del item['wins']
SortedMatchup3=sorted(Matchup3, key=lambda x: x['hero_id'])
for i in SortedMatchup3:
if i['hero_id']==id1[0]:
SortedMatchup3.remove(i)
if i['hero_id']==id2[0]:
SortedMatchup3.remove(i)
if i['hero_id']==id4[0]:
SortedMatchup3.remove(i)
#this is for id4
concatHelper4=str(id4[0])
Matchuplink3="https://api.opendota.com/api/heroes/"+concatHelper4+"/matchups"
response=requests.get(Matchuplink3)
Matchup4=json.loads(response.text)
for item in Matchup4:
winpercent=(int(item['wins'])/int(item['games_played']))*100
item['winpercent4']=winpercent
del item['games_played']
del item['wins']
SortedMatchup4=sorted(Matchup4, key=lambda x: x['hero_id'])
for i in SortedMatchup4:
if i['hero_id']==id1[0]:
SortedMatchup4.remove(i)
if i['hero_id']==id2[0]:
SortedMatchup4.remove(i)
if i['hero_id']==id3[0]:
SortedMatchup4.remove(i)
if len(SortedMatchup1)<119:
SortedMatchup1.insert(118,{'hero_id': 137, 'winpercent1': 50})
if len(SortedMatchup2)<119:
SortedMatchup2.insert(118,{'hero_id': 137, 'winpercent2': 50})
if len(SortedMatchup3)<119:
SortedMatchup3.insert(118,{'hero_id': 137, 'winpercent3': 50})
if len(SortedMatchup4)<119:
SortedMatchup1.insert(118,{'hero_id': 137, 'winpercent4': 50})
#Now we have hero id vs winpercents for all ids
#so we need to put them in a single list
SortedMatchup=SortedMatchup1
for i in SortedMatchup:
i['winpercent2']=SortedMatchup2[SortedMatchup.index(i)]['winpercent2']
i['winpercent3']=SortedMatchup3[SortedMatchup.index(i)]['winpercent3']
i['winpercent4']=SortedMatchup4[SortedMatchup.index(i)]['winpercent4']
#now we can make a product of all winrates to get an idea of overall winrate(not average because multiplicative result gives more accurate result for effectiveness fo a hero)
for i in SortedMatchup:
i['winproduct']=i['winpercent1']*i['winpercent2']*i['winpercent3']*i['winpercent4']
del i['winpercent1']
del i['winpercent2']
del i['winpercent3']
del i['winpercent4']
SortedWinproducts=sorted(SortedMatchup, key=lambda x: x['winproduct'])
#Now we can run a loop that returns hero names for all the ids in this list
AnswerList=[]
for i in SortedWinproducts:
AnswerList.append(IdtoName[i['hero_id']])
await message.channel.send(AnswerList)
return
client.run(TOKEN)