HighestMasteryCommand.py refactored

This commit is contained in:
s-prechtl 2022-03-17 14:22:55 +01:00
parent 6b177b7343
commit 06964afae6

View file

@ -19,57 +19,46 @@ class HighestMastery(APICommands.Command.Command, ABC):
sumname = "" sumname = ""
firstIsInt = intTryParse(message.content.split(" ")[1])[1] firstIsInt = intTryParse(message.content.split(" ")[1])[1]
if len(message.content.split(" ")) > 2 and firstIsInt: # If number is given try:
sumname = APICommands.Command.getSummonerNameFromMessage(message, 2)
except:
await self.usage(message)
if sumname != "":
if not await self.checkSumname(sumname, message):
return
listlen = int(message.content.split(" ")[1]) if firstIsInt else 10
try: try:
sumname = APICommands.Command.getSummonerNameFromMessage(message, 2) output = self.getChampionMasteryList(sumname, listlen)
for i in output:
await message.channel.send(i)
except: except:
await self.usage(message) await self.usage(message)
if sumname != "":
if not await self.checkSumname(sumname, message):
return
try:
listlen = int(message.content.split(" ")[1])
output = self.getChampionMasteryList(sumname, listlen)
for i in output:
await message.channel.send(i)
except:
await self.usage(message)
elif not firstIsInt: # no number given
try:
sumname = APICommands.Command.getSummonerNameFromMessage(message, 1)
except:
await self.usage(message)
if sumname != "":
try:
listlen = 10
output = self.getChampionMasteryList(sumname, listlen)
for i in output:
await message.channel.send(i)
except:
await self.usage(message)
async def info(self, message: discord.Message):
pass
async def usage(self, message: discord.Message): async def info(self, message: discord.Message):
await message.channel.send("Wrong usage of" + self.commandName + "!\nUsage: " + self.pref + "hm [count] [" pass
"Summonername]")
def getChampionMasteryList(self, sumname, listlen):
output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str( async def usage(self, message: discord.Message):
listlen) + " Champions\n"] await message.channel.send("Wrong usage of" + self.commandName + "!\nUsage: " + self.pref + "hm [count] ["
count = 0 "Summonername]")
response = self.api.champion_mastery.by_summoner(self.region, self.getEncryptedSummonerID(sumname))[
:listlen]
championsJSON = getChampionsJSON() def getChampionMasteryList(self, sumname, listlen):
for i in response: output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str(
champname = championIdToName(i["championId"], championsJSON) listlen) + " Champions\n"]
mpoints = i["championPoints"] count = 0
mastery = i["championLevel"] response = self.api.champion_mastery.by_summoner(self.region, self.getEncryptedSummonerID(sumname))[
out = "**" + champname + "**" + " Points: " + str(mpoints) + " Level: " + str( :listlen]
mastery) + "\n" championsJSON = getChampionsJSON()
if len(output[count]) + len(out) >= 2000: for i in response:
output.append("") champname = championIdToName(i["championId"], championsJSON)
count += 1 mpoints = i["championPoints"]
output[count] += out mastery = i["championLevel"]
return output 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