Initial commit
This commit is contained in:
commit
e387f1802b
6 changed files with 282 additions and 0 deletions
1
API.key
Normal file
1
API.key
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
RGAPI-c843f435-ced0-45e1-9481-912e07e1b065
|
||||||
51
APIGrabber.py
Normal file
51
APIGrabber.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#This tutorial was built by me, Farzain! You can ask me questions or troll me on Twitter (@farzatv)
|
||||||
|
|
||||||
|
#First we need to import requests. Installing this is a bit tricky. I included a step by step process on how to get requests in readme.txt which is included in the file along with this program.
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def requestSummonerData(region, summonerName, APIKey):
|
||||||
|
|
||||||
|
#Here is how I make my URL. There are many ways to create these.
|
||||||
|
|
||||||
|
URL = "https://" + region + ".api.pvp.net/api/lol/" + region + "/v1.4/summoner/by-name/" + summonerName + "?api_key=" + APIKey
|
||||||
|
print URL
|
||||||
|
#requests.get is a function given to us my our import "requests". It basically goes to the URL we made and gives us back a JSON.
|
||||||
|
response = requests.get(URL)
|
||||||
|
#Here I return the JSON we just got.
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def requestRankedData(region, ID, APIKey):
|
||||||
|
URL = "https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.5/league/by-summoner/" + ID + "/entry?api_key=" + APIKey
|
||||||
|
print URL
|
||||||
|
response = requests.get(URL)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print "\nWhat up homie. Enter your region to get started"
|
||||||
|
print "Type in one of the following regions or else the program wont work correctly:\n"
|
||||||
|
print "NA or EUW (Note: You can add more regions by just changing up the URL!\n"
|
||||||
|
|
||||||
|
#I first ask the user for three things, their region, summoner name, and API Key.
|
||||||
|
#These are the only three things I need from them in order to get create my URL and grab their ID.
|
||||||
|
|
||||||
|
region = (str)(raw_input('Type in one of the regions above: '))
|
||||||
|
summonerName = (str)(raw_input('Type your Summoner Name here and DO NOT INCLUDE ANY SPACES: '))
|
||||||
|
APIKey = (str)(raw_input('Copy and paste your API Key here: '))
|
||||||
|
|
||||||
|
#I send these three pieces off to my requestData function which will create the URL and give me back a JSON that has the ID for that specific summoner.
|
||||||
|
#Once again, what requestData returns is a JSON.
|
||||||
|
responseJSON = requestSummonerData(region, summonerName, APIKey)
|
||||||
|
|
||||||
|
ID = responseJSON[summonerName]['id']
|
||||||
|
ID = str(ID)
|
||||||
|
print ID
|
||||||
|
responseJSON2 = requestRankedData(region, ID, APIKey)
|
||||||
|
print responseJSON2[ID][0]['tier']
|
||||||
|
print responseJSON2[ID][0]['entries'][0]['division']
|
||||||
|
print responseJSON2[ID][0]['entries'][0]['leaguePoints']
|
||||||
|
|
||||||
|
#This starts my program!
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
BIN
LeaguePic.jpg
Normal file
BIN
LeaguePic.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 844 KiB |
BIN
deepfried_1621272364348.jpg
Normal file
BIN
deepfried_1621272364348.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
230
iLeague.py
Normal file
230
iLeague.py
Normal file
|
|
@ -0,0 +1,230 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
import discord, pickle
|
||||||
|
import requests
|
||||||
|
from riotwatcher import LolWatcher, ApiError
|
||||||
|
|
||||||
|
|
||||||
|
def championIdToName(id, championsText):
|
||||||
|
champions = json.loads(championsText)['data']
|
||||||
|
|
||||||
|
for j in dict(champions):
|
||||||
|
if id == int(champions[j]["key"]):
|
||||||
|
return j
|
||||||
|
|
||||||
|
|
||||||
|
class MyClient(discord.Client):
|
||||||
|
api: LolWatcher
|
||||||
|
region: str
|
||||||
|
pref = "$"
|
||||||
|
|
||||||
|
def initAPI(self, APIKey, region="EUW1"):
|
||||||
|
self.api = LolWatcher(APIKey)
|
||||||
|
self.region = region
|
||||||
|
|
||||||
|
def load(self): # Loads the prefix file if accesable
|
||||||
|
try:
|
||||||
|
self.pref = pickle.load(open("prefix.data", "rb"))
|
||||||
|
print("Prefix loaded as: " + self.pref)
|
||||||
|
except:
|
||||||
|
print("No File found.")
|
||||||
|
|
||||||
|
async def on_ready(self):
|
||||||
|
print("Beep Boop, suck my cock")
|
||||||
|
|
||||||
|
async def on_message(self, message):
|
||||||
|
if message.author == client.user: # Checks if the User isnt the bot itself
|
||||||
|
return
|
||||||
|
|
||||||
|
# COMMANDS
|
||||||
|
if message.content.startswith(self.pref) and isinstance(message, discord.Message) and isinstance(self.api,
|
||||||
|
LolWatcher):
|
||||||
|
if not (
|
||||||
|
message.channel.id == 843900656108437504 or message.channel.id == 673681791932170240): # Only allows channels bot testing and leaguebot
|
||||||
|
await message.channel.send("Bitte #league-bot verwenden.")
|
||||||
|
return
|
||||||
|
if message.content == (self.pref + "prefix"):
|
||||||
|
await message.channel.send(
|
||||||
|
"Your current prefix is: " + self.pref + ". To change it use " + self.pref + "prefix [new Prefix]")
|
||||||
|
|
||||||
|
elif self.getContentFromMessageWithPrefixCommand(message, ["prefix"]):
|
||||||
|
print("Prefix request sent in Channel " + str(message.channel.name))
|
||||||
|
try:
|
||||||
|
self.pref = message.content.split(" ")[1]
|
||||||
|
await message.channel.send("Prefix successfully changed to " + self.pref)
|
||||||
|
pickle.dump(self.pref, open("prefix.data", "wb"))
|
||||||
|
except:
|
||||||
|
await message.channel.send(
|
||||||
|
"Something went wrong while changing the prefix. To change it use " + self.pref + "prefix [new Prefix]")
|
||||||
|
|
||||||
|
# HUBA
|
||||||
|
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
||||||
|
await message.channel.send(
|
||||||
|
"Julian Huber (16) ist ein Kinderschänder, welcher in Wahrheit schwul ist und seine sexuelle "
|
||||||
|
"Orientierung hinter einer Beziehung mit einem weiblichen Kind versteckt.")
|
||||||
|
|
||||||
|
# LEVEL
|
||||||
|
elif self.getContentFromMessageWithPrefixCommand(message, ["level", "Level", "lvl"]):
|
||||||
|
print("Summonerlevel request sent in Channel " + str(message.channel.name))
|
||||||
|
sumname = ""
|
||||||
|
try:
|
||||||
|
sumname = self.getSummonerNameFromMessage(message)
|
||||||
|
except:
|
||||||
|
await message.channel.send(err)
|
||||||
|
if sumname != "":
|
||||||
|
response = self.api.summoner.by_name(self.region, sumname)
|
||||||
|
level = response["summonerLevel"]
|
||||||
|
await message.channel.send("Der Spieler " + sumname + " hat das Level " + str(level) + ".")
|
||||||
|
|
||||||
|
# RANK
|
||||||
|
elif self.getContentFromMessageWithPrefixCommand(message, ["rank", "Rank", "RANK"]):
|
||||||
|
sumname = ""
|
||||||
|
try:
|
||||||
|
sumname = self.getSummonerNameFromMessage(message)
|
||||||
|
except:
|
||||||
|
await message.channel.send("Something went wrong.\n"
|
||||||
|
"Usage: " + self.pref + "rank [Summonername]")
|
||||||
|
|
||||||
|
if sumname != "":
|
||||||
|
print("Summonerrank request sent in Channel " + str(message.channel.name))
|
||||||
|
response = self.api.league.by_summoner(self.region,
|
||||||
|
self.api.summoner.by_name(self.region, sumname)["id"])
|
||||||
|
for i in response:
|
||||||
|
if i["queueType"] == "RANKED_SOLO_5x5":
|
||||||
|
response = i
|
||||||
|
rank = str(response['tier']) + " " + str(response['rank'])
|
||||||
|
wr = str(truncate((response["wins"] / (response["wins"] + response["losses"]) * 100), 2)) + "%"
|
||||||
|
await message.channel.send(sumname + ": " + str(rank) + " | WR: " + str(wr))
|
||||||
|
|
||||||
|
# HIGHEST MASTERY
|
||||||
|
elif self.getContentFromMessageWithPrefixCommand(message,
|
||||||
|
["highestmastery", "highestMastery", "HM", "hm", "Hm",
|
||||||
|
"HighestMastery"]):
|
||||||
|
sumname = ""
|
||||||
|
err = "Something went wrong.\nUsage: " + self.pref + "hm [count] [Summonername]"
|
||||||
|
firstIsInt = intTryParse(message.content.split(" ")[1])[1]
|
||||||
|
|
||||||
|
if len(message.content.split(" ")) > 2 and firstIsInt: # If number is given
|
||||||
|
try:
|
||||||
|
sumname = self.getSummonerNameFromMessage(message, 2)
|
||||||
|
except Exception as e:
|
||||||
|
await message.channel.send(err)
|
||||||
|
print("Exception in Mastery " + str(e))
|
||||||
|
if sumname != "":
|
||||||
|
try:
|
||||||
|
listlen = int(message.content.split(" ")[1])
|
||||||
|
output = self.getChampionMasteryList(sumname, listlen)
|
||||||
|
for i in output:
|
||||||
|
await message.channel.send(i)
|
||||||
|
except Exception as e:
|
||||||
|
await message.channel.send(err)
|
||||||
|
print("Exception in Mastery " + str(e))
|
||||||
|
elif not firstIsInt: # no number given
|
||||||
|
try:
|
||||||
|
sumname = self.getSummonerNameFromMessage(message, 1)
|
||||||
|
except Exception as e:
|
||||||
|
await message.channel.send(err)
|
||||||
|
print("Exception in Mastery " + str(e))
|
||||||
|
if sumname != "":
|
||||||
|
try:
|
||||||
|
listlen = 10
|
||||||
|
output = self.getChampionMasteryList(sumname, listlen)
|
||||||
|
for i in output:
|
||||||
|
await message.channel.send(i)
|
||||||
|
except Exception as e:
|
||||||
|
await message.channel.send(err)
|
||||||
|
|
||||||
|
elif self.getContentFromMessageWithPrefixCommand(message, ["cm", "CM", "Championmastery",
|
||||||
|
"championmastery"]): # get Mastery from Champion
|
||||||
|
err = "Something went wrong.\nUsage: " + self.pref + "cm [Championname] [Summonername]"
|
||||||
|
sumname = ""
|
||||||
|
try:
|
||||||
|
sumname = self.getSummonerNameFromMessage(message, 2)
|
||||||
|
except Exception as e:
|
||||||
|
await message.channel.send(err)
|
||||||
|
|
||||||
|
if sumname != "":
|
||||||
|
response = self.api.champion_mastery.by_summoner(self.region,
|
||||||
|
self.api.summoner.by_name(self.region,
|
||||||
|
sumname)["id"])
|
||||||
|
|
||||||
|
championsJSON = self.getChampionsJSON()
|
||||||
|
for i in response:
|
||||||
|
champname = championIdToName(i["championId"], championsJSON)
|
||||||
|
if champname == message.content.split(" ")[1]:
|
||||||
|
mpoints = i["championPoints"]
|
||||||
|
mastery = i["championLevel"]
|
||||||
|
out = "**" + sumname + "** --> **" + champname + "**" + " Points: " + str(
|
||||||
|
mpoints) + " Level: " + str(
|
||||||
|
mastery) + "\n"
|
||||||
|
|
||||||
|
await message.channel.send(out)
|
||||||
|
return
|
||||||
|
await message.channel.send("No matching champion was found.")
|
||||||
|
|
||||||
|
def getSummonerNameFromMessage(self, message, argumentstart=1):
|
||||||
|
ret = ""
|
||||||
|
inp = message.content.split(" ")
|
||||||
|
if len(inp) > argumentstart + 1:
|
||||||
|
for i in inp[argumentstart:]:
|
||||||
|
ret += " " + i
|
||||||
|
|
||||||
|
ret = ret[1:]
|
||||||
|
else:
|
||||||
|
ret = inp[argumentstart]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def getContentFromMessageWithPrefixCommand(self, message: discord.Message, command: list):
|
||||||
|
for i in command:
|
||||||
|
if message.content.startswith(self.pref + i):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getChampionMasteryList(self, sumname, listlen):
|
||||||
|
output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str(
|
||||||
|
listlen) + " Champions\n"]
|
||||||
|
count = 0
|
||||||
|
response = self.api.champion_mastery.by_summoner(self.region, self.getEncryptedSummonerID(sumname))[
|
||||||
|
:listlen]
|
||||||
|
championsJSON = self.getChampionsJSON()
|
||||||
|
for i in response:
|
||||||
|
champname = championIdToName(i["championId"], championsJSON)
|
||||||
|
mpoints = i["championPoints"]
|
||||||
|
mastery = i["championLevel"]
|
||||||
|
out = "**" + champname + "**" + " Points: " + str(mpoints) + " Level: " + str(
|
||||||
|
mastery) + "\n"
|
||||||
|
if len(output[count]) + len(out) >= 2000:
|
||||||
|
output.append("")
|
||||||
|
count += 1
|
||||||
|
output[count] += out
|
||||||
|
return output
|
||||||
|
|
||||||
|
def getEncryptedSummonerID(self, name):
|
||||||
|
return self.api.summoner.by_name(self.region, name)["id"]
|
||||||
|
|
||||||
|
def getChampionsJSON(self):
|
||||||
|
return requests.get("http://ddragon.leagueoflegends.com/cdn/11.19.1/data/en_US/champion.json").text
|
||||||
|
|
||||||
|
|
||||||
|
def truncate(f, n):
|
||||||
|
'''Truncates/pads a float f to n decimal places without rounding'''
|
||||||
|
s = '{}'.format(f)
|
||||||
|
if 'e' in s or 'E' in s:
|
||||||
|
return '{0:.{1}f}'.format(f, n)
|
||||||
|
i, p, d = s.partition('.')
|
||||||
|
return '.'.join([i, (d + '0' * n)[:n]])
|
||||||
|
|
||||||
|
|
||||||
|
def intTryParse(value):
|
||||||
|
try:
|
||||||
|
return int(value), True
|
||||||
|
except ValueError:
|
||||||
|
return value, False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
client = MyClient()
|
||||||
|
client.load()
|
||||||
|
with open("API.key", "r") as f:
|
||||||
|
client.initAPI(f.read())
|
||||||
|
client.run("ODQzNDQ4NDg3MzgyNzQ1MDk4.YKEAnQ.qyeogazdj2w4Tt7hEnBZmfcN0Xw")
|
||||||
BIN
prefix.data
Normal file
BIN
prefix.data
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue