minor code refactoring
This commit is contained in:
parent
36a8795245
commit
169599dff5
6 changed files with 56 additions and 54 deletions
|
|
@ -4,6 +4,7 @@ import discord
|
|||
import riotwatcher
|
||||
|
||||
import APICommands.Command
|
||||
from APICommands.Command import getSummonerNameFromMessage, getChampionsJSON, championIdToName
|
||||
|
||||
|
||||
class ChampionMastery(APICommands.Command.Command, ABC):
|
||||
|
|
@ -15,10 +16,37 @@ class ChampionMastery(APICommands.Command.Command, ABC):
|
|||
super().__init__(pref, api, region, additionalKeywords)
|
||||
|
||||
async def execute(self, message: discord.Message):
|
||||
pass
|
||||
sumname = ""
|
||||
try:
|
||||
sumname = getSummonerNameFromMessage(message, 2)
|
||||
except:
|
||||
await self.usage(message)
|
||||
|
||||
if sumname != "":
|
||||
if not await self.checkSumname(sumname, message):
|
||||
return
|
||||
|
||||
response = self.api.champion_mastery.by_summoner(self.region,
|
||||
self.api.summoner.by_name(self.region,
|
||||
sumname)["id"])
|
||||
|
||||
championsJSON = 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.")
|
||||
|
||||
async def info(self, message: discord.Message):
|
||||
pass
|
||||
|
||||
async def usage(self, message: discord.Message):
|
||||
pass
|
||||
await message.channel.send("Wrong usage of " + self.commandName + "!\nUsage: " + self.pref + "cm [champion] ["
|
||||
"Summoner]")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from abc import abstractmethod, ABCMeta
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -6,6 +7,25 @@ import requests
|
|||
import riotwatcher
|
||||
|
||||
|
||||
def championIdToName(id, championsText):
|
||||
champions = json.loads(championsText)['data']
|
||||
|
||||
for j in dict(champions):
|
||||
if id == int(champions[j]["key"]):
|
||||
return j
|
||||
|
||||
|
||||
def getChampionsJSON():
|
||||
return requests.get("http://ddragon.leagueoflegends.com/cdn/11.19.1/data/en_US/champion.json").text
|
||||
|
||||
|
||||
def intTryParse(value):
|
||||
try:
|
||||
return int(value), True
|
||||
except ValueError:
|
||||
return value, False
|
||||
|
||||
|
||||
def getSummonerNameFromMessage(message: discord.Message, argumentstart=1):
|
||||
ret = ""
|
||||
inp = message.content.split(" ")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import discord
|
|||
import riotwatcher
|
||||
|
||||
import APICommands.Command
|
||||
from iLeague import intTryParse, championIdToName, getChampionsJSON
|
||||
from APICommands.Command import intTryParse, championIdToName, getChampionsJSON, getSummonerNameFromMessage
|
||||
|
||||
|
||||
class HighestMastery(APICommands.Command.Command, ABC):
|
||||
|
|
@ -20,7 +20,7 @@ class HighestMastery(APICommands.Command.Command, ABC):
|
|||
firstIsInt = intTryParse(message.content.split(" ")[1])[1]
|
||||
|
||||
try:
|
||||
sumname = APICommands.Command.getSummonerNameFromMessage(message, 2)
|
||||
sumname = getSummonerNameFromMessage(message, 2)
|
||||
except:
|
||||
await self.usage(message)
|
||||
if sumname != "":
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import discord
|
|||
import riotwatcher
|
||||
|
||||
import APICommands.Command
|
||||
from APICommands.Command import getSummonerNameFromMessage
|
||||
|
||||
|
||||
class SummonerLevel(APICommands.Command.Command, ABC):
|
||||
|
|
@ -17,7 +18,7 @@ class SummonerLevel(APICommands.Command.Command, ABC):
|
|||
async def execute(self, message: discord.Message):
|
||||
sumname = ""
|
||||
try:
|
||||
sumname = APICommands.Command.getSummonerNameFromMessage(message)
|
||||
sumname = getSummonerNameFromMessage(message)
|
||||
except:
|
||||
await self.usage(message)
|
||||
if sumname != "":
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import discord
|
|||
import riotwatcher
|
||||
|
||||
import APICommands.Command
|
||||
from APICommands.Command import getSummonerNameFromMessage
|
||||
|
||||
|
||||
def truncate(f, n):
|
||||
|
|
@ -26,7 +27,7 @@ class SummonerRank(APICommands.Command.Command, ABC):
|
|||
async def execute(self, message: discord.Message):
|
||||
sumname = ""
|
||||
try:
|
||||
sumname = APICommands.Command.getSummonerNameFromMessage(message)
|
||||
sumname = getSummonerNameFromMessage(message)
|
||||
except:
|
||||
await self.usage(message)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue