-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAfterLP.py
More file actions
243 lines (189 loc) · 6.86 KB
/
AfterLP.py
File metadata and controls
243 lines (189 loc) · 6.86 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
from riotwatcher import LolWatcher
import discord
import asyncio
from datetime import datetime
#riot api key (expiers every day)
riotkey = ''
#discord api bot key
discordkey = ''
#discord channel to post to
discordchannel =
#set region to NA
region = 'na1'
#number of games tested
gamesTested = 10
#define watcher as the key we use to interact with lol data
watcher = LolWatcher(riotkey)
#define discord client
client = discord.Client()
#test for demations every x seconds(600 for 10 minuets)
seconds = 300
#####
#set fuctions
#####
#fuction for finding rank info and accout id based on summoner name
def findInfo(summonerName):
player = watcher.summoner.by_name(region,summonerName)
stats = watcher.league.by_summoner(region, player['id'])
#find what number is ranked solo
queueType = stats[0]['queueType']
if queueType == "RANKED_SOLO_5x5":
rankedSolo = 0
else:
rankedSolo = 1
#pick the info to find
tier = stats[rankedSolo]['tier']
rank = stats[rankedSolo]['rank']
LP = stats[rankedSolo]['leaguePoints']
#print info
print(summonerName)
if tier == "MASTER" or tier == "GRANDMASTER" or tier == "CHALLENGER":
print(tier)
print(LP)
else:
print(tier)
print(rank)
print(LP)
#return user id
return [summonerName, player['accountId'], tier, rank, LP]
#test every x amount of time if players ranks have changed
async def testplayers():
while True:
await asyncio.sleep(seconds)
for x in range(numberOfPlayers):
testPlayerChange = findInfo(playerNames[x])
if listOfPlayers[x][2] == testPlayerChange[2] and listOfPlayers[x][3] == testPlayerChange[3]:
print('same rank')
print()
else:
print('different rank')
cRankValue = getRankValue(testPlayerChange)
pRankValue = getRankValue(listOfPlayers[x])
#test if rank is up or down
if cRankValue > pRankValue:
lossKDA = findPlayerKDA(listOfPlayers[x][1])
#make variables readable
lossKDAstr = str(str(lossKDA[1][0]) + '/' + str(lossKDA[1][1]) + '/' + str(lossKDA[1][2]))
if testPlayerChange[2] == 'MASTER' or testPlayerChange[2] == 'GRANDMASTER' or testPlayerChange[2] == 'CHALLENGER':
Rank = str(testPlayerChange[2])
else:
Rank = str(str(testPlayerChange[2]) + ' ' + str(testPlayerChange[3]))
#variables used to print
pUser = listOfPlayers[x][0]
pRank = Rank
pLossStreak = lossKDA[0]
pLossKDA = lossKDAstr
#send discord message passing the data
client.loop.create_task(printData(pUser, pRank, pLossStreak, pLossKDA))
else:
print('updated player')
print()
#update 'listOfPlayers'
listOfPlayers[x] = testPlayerChange
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(current_time)
print()
#find the loss streak of a player and thier kda during the streak
def findPlayerKDA(userID):
print()
playerHistory = watcher.match.matchlist_by_account(region, userID, 420, None, None, None, gamesTested)
#put all match history data into 'historyInfo'
historyInfo = []
for x in range(gamesTested):
historyInfo.append(watcher.match.by_id(region, playerHistory['matches'][x]['gameId']))
#get user number in each game
userNumber = []
for x in range (gamesTested):
for y in range(10):
if (historyInfo[x]['participantIdentities'][y]['player']['currentAccountId']) == userID:
userNumber.append(y)
break
#find the loss streak the player is on
lossStreak = 0
for x in range(gamesTested):
if historyInfo[x]['participants'][userNumber[x]]['stats']['win'] == False:
lossStreak = lossStreak + 1
else:
break
#find the kda during loss streak
KDAaverage = []
if lossStreak != 0:
for x in range(lossStreak):
kills = historyInfo[x]['participants'][userNumber[x]]['stats']['kills']
deaths = historyInfo[x]['participants'][userNumber[x]]['stats']['deaths']
assists = historyInfo[x]['participants'][userNumber[x]]['stats']['assists']
KDA = []
KDA.append(kills)
KDA.append(deaths)
KDA.append(assists)
KDAaverage.append(KDA)
#average and round kda
KDAaverage = [sum(x) / len(x) for x in zip(*KDAaverage)]
KDAaverage = [round(xg, 1) for xg in KDAaverage]
return lossStreak, KDAaverage
else:
return 0, [0,0,0]
#get rankValue from 'listOfPlayers' format
def getRankValue(playerRankInfo):
ranks = ['CHALLENGER', 'GRANDMASTER', 'MASTER', 'DIAMOND', 'PLATINUM', 'GOLD', 'SILVER', 'BRONZE', 'IRON']
rating = [10, 20, 30, 40, 50, 60, 70, 80, 90]
divitions = ['I', 'II', 'III', 'IV']
divitionValue = [1, 2, 3, 4]
rankValue = 0
for x in range(len(ranks)):
if playerRankInfo[2] == ranks[x]:
rankValue = rankValue + rating[x]
for x in range(len(divitions)):
if playerRankInfo[3] == divitions[x]:
rankValue = rankValue + divitionValue[x]
return rankValue
#send data to discord
@client.event
async def printData(User, Rank, LossStreak, LossKDA):
channel = client.get_channel(discordchannel)
print('User:' + str(User))
print('Rank:' + str(Rank))
print('Loss Streak:' + str(LossStreak))
print('KDA:' + str(LossKDA))
print()
await channel.send('looks good :tada: {} :tada:\nWelcome to {}\nLossStreak: {}\nRecent KDA: {}'.format(User, Rank, LossStreak, LossKDA))
#ready check
@client.event
async def on_ready():
print('we logged in'.format(client))
print()
#testing fuction
@client.event
async def on_message(message):
if message.content.startswith('#hi'):
print("HI!!!!")
await message.channel.send('HI!')
#####
#Run Start up code
#####
#read "Player.txt"
f = open('Players.txt','r')
playerNames = []
numberOfPlayers = 0
for line in f:
line = line.strip("\n")
line = line.strip()
if line != 'Players:' and line != '':
numberOfPlayers = numberOfPlayers +1
playerNames.append(line)
print()
print('testing ' + str(numberOfPlayers) + ' players')
print(playerNames)
print()
f.close()
#store each player rank in variable 'listOfPlayers'
listOfPlayers = []
for x in range(numberOfPlayers):
listOfPlayers.append(findInfo(playerNames[x]))
print()
#####
#run the bot
#####
client.loop.create_task(testplayers())
client.run(discordkey)