RankCommand done
This commit is contained in:
parent
c6ecd46b24
commit
b34ae6e882
5 changed files with 50 additions and 53 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/requests.log
|
||||||
|
|
@ -6,6 +6,19 @@ import requests
|
||||||
import riotwatcher
|
import riotwatcher
|
||||||
|
|
||||||
|
|
||||||
|
def getSummonerNameFromMessage(message: discord.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
|
||||||
|
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
__metaclass__ = ABCMeta
|
__metaclass__ = ABCMeta
|
||||||
keywords = []
|
keywords = []
|
||||||
|
|
@ -47,18 +60,6 @@ class Command:
|
||||||
with open("requests.log", "a") as f:
|
with open("requests.log", "a") as f:
|
||||||
f.write(logMSG)
|
f.write(logMSG)
|
||||||
|
|
||||||
def getSummonerNameFromMessage(self, message: discord.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
|
|
||||||
|
|
||||||
async def checkSumname(self, sumname, message: discord.Message):
|
async def checkSumname(self, sumname, message: discord.Message):
|
||||||
try:
|
try:
|
||||||
var = self.api.summoner.by_name(self.region, sumname)["id"]
|
var = self.api.summoner.by_name(self.region, sumname)["id"]
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class SummonerLevel(APICommands.Command.Command, ABC):
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
sumname = ""
|
sumname = ""
|
||||||
try:
|
try:
|
||||||
sumname = self.getSummonerNameFromMessage(message)
|
sumname = APICommands.Command.getSummonerNameFromMessage(message)
|
||||||
except:
|
except:
|
||||||
await self.usage(message)
|
await self.usage(message)
|
||||||
if sumname != "":
|
if sumname != "":
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,15 @@ import riotwatcher
|
||||||
import APICommands.Command
|
import APICommands.Command
|
||||||
|
|
||||||
|
|
||||||
|
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]])
|
||||||
|
|
||||||
|
|
||||||
class SummonerRank(APICommands.Command.Command, ABC):
|
class SummonerRank(APICommands.Command.Command, ABC):
|
||||||
keywords = ["rank", "Rank", "RANK"]
|
keywords = ["rank", "Rank", "RANK"]
|
||||||
|
|
||||||
|
|
@ -15,10 +24,27 @@ class SummonerRank(APICommands.Command.Command, ABC):
|
||||||
super().__init__(pref, api, region, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
sumname = ""
|
||||||
|
try:
|
||||||
|
sumname = APICommands.Command.getSummonerNameFromMessage(message)
|
||||||
|
except:
|
||||||
|
await self.usage(message)
|
||||||
|
|
||||||
|
if sumname != "":
|
||||||
|
if not await self.checkSumname(sumname, message):
|
||||||
|
return
|
||||||
|
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))
|
||||||
|
|
||||||
async def info(self, message: discord.Message):
|
async def info(self, message: discord.Message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def usage(self, message: discord.Message):
|
async def usage(self, message: discord.Message):
|
||||||
pass
|
await message.channel.send("Wrong usage of " + self.commandName + ".\n"
|
||||||
|
"Usage: " + self.pref + "rank [Summonername]")
|
||||||
|
|
|
||||||
43
iLeague.py
43
iLeague.py
|
|
@ -6,7 +6,7 @@ import pickle
|
||||||
import requests
|
import requests
|
||||||
from riotwatcher import LolWatcher
|
from riotwatcher import LolWatcher
|
||||||
|
|
||||||
from APICommands import ChampionMasteryCommand, HighestMasteryCommand, SummonerLevelCommand, PrefixCommand
|
from APICommands import ChampionMasteryCommand, HighestMasteryCommand, SummonerLevelCommand, PrefixCommand, SummonerRankCommand
|
||||||
|
|
||||||
|
|
||||||
def championIdToName(id, championsText):
|
def championIdToName(id, championsText):
|
||||||
|
|
@ -34,6 +34,7 @@ class MyClient(discord.Client):
|
||||||
self.commands.append(HighestMasteryCommand.HighestMastery(self.pref, self.api, self.region, []))
|
self.commands.append(HighestMasteryCommand.HighestMastery(self.pref, self.api, self.region, []))
|
||||||
self.commands.append(SummonerLevelCommand.SummonerLevel(self.pref, self.api, self.region, []))
|
self.commands.append(SummonerLevelCommand.SummonerLevel(self.pref, self.api, self.region, []))
|
||||||
self.commands.append(PrefixCommand.Prefix(self.pref, self.api, self.region, []))
|
self.commands.append(PrefixCommand.Prefix(self.pref, self.api, self.region, []))
|
||||||
|
self.commands.append(SummonerRankCommand.SummonerRank(self.pref, self.api, self.region, []))
|
||||||
|
|
||||||
def load(self): # Loads the prefix file if accessable
|
def load(self): # Loads the prefix file if accessable
|
||||||
try:
|
try:
|
||||||
|
|
@ -65,15 +66,14 @@ class MyClient(discord.Client):
|
||||||
|
|
||||||
|
|
||||||
# HUBA
|
# HUBA
|
||||||
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
if message.content == self.pref + "huba":
|
||||||
self.log("Huawa", message)
|
self.log("Huawa", message)
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
"Julian Huber (16) ist ein Kinderschänder, welcher in Wahrheit schwul ist und seine sexuelle "
|
"Julian Huber (17) ist ein Kinderschänder, welcher in Wahrheit schwul ist und seine sexuelle "
|
||||||
"Orientierung hinter einer Beziehung mit einem weiblichen Kind versteckt.")
|
"Orientierung hinter einer Beziehung mit einem weiblichen Kind versteckt.")
|
||||||
|
|
||||||
# LEVEL
|
if True:
|
||||||
elif self.getContentFromMessageWithPrefixCommand(message, ["level", "Level", "lvl"]):
|
return
|
||||||
await self.requestLevel(message)
|
|
||||||
|
|
||||||
# RANK
|
# RANK
|
||||||
elif self.getContentFromMessageWithPrefixCommand(message, ["rank", "Rank", "RANK"]):
|
elif self.getContentFromMessageWithPrefixCommand(message, ["rank", "Rank", "RANK"]):
|
||||||
|
|
@ -106,27 +106,6 @@ class MyClient(discord.Client):
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
"Something went wrong while changing the prefix. To change it use " + self.pref + "prefix [new Prefix]")
|
"Something went wrong while changing the prefix. To change it use " + self.pref + "prefix [new Prefix]")
|
||||||
|
|
||||||
async def requestRank(self, message: discord.Message):
|
|
||||||
sumname = ""
|
|
||||||
try:
|
|
||||||
sumname = self.getSummonerNameFromMessage(message)
|
|
||||||
except:
|
|
||||||
await message.channel.send("Something went wrong.\n"
|
|
||||||
"Usage: " + self.pref + "rank [Summonername]")
|
|
||||||
|
|
||||||
if sumname != "":
|
|
||||||
if not await self.checkSumname(sumname, message):
|
|
||||||
return
|
|
||||||
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))
|
|
||||||
|
|
||||||
async def requestHighestMastery(self, message: discord.Message):
|
async def requestHighestMastery(self, message: discord.Message):
|
||||||
sumname = ""
|
sumname = ""
|
||||||
err = "Something went wrong.\nUsage: " + self.pref + "hm [count] [Summonername]"
|
err = "Something went wrong.\nUsage: " + self.pref + "hm [count] [Summonername]"
|
||||||
|
|
@ -255,16 +234,6 @@ class MyClient(discord.Client):
|
||||||
def getChampionsJSON(self):
|
def getChampionsJSON(self):
|
||||||
return requests.get("http://ddragon.leagueoflegends.com/cdn/11.19.1/data/en_US/champion.json").text
|
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):
|
def intTryParse(value):
|
||||||
try:
|
try:
|
||||||
return int(value), True
|
return int(value), True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue