Summ level command finished
This commit is contained in:
parent
ae22fa98a6
commit
c6ecd46b24
8 changed files with 69 additions and 60 deletions
|
|
@ -9,10 +9,10 @@ import APICommands.Command
|
||||||
class ChampionMastery(APICommands.Command.Command, ABC):
|
class ChampionMastery(APICommands.Command.Command, ABC):
|
||||||
keywords = ["cm", "CM", "Championmastery", "championmastery"]
|
keywords = ["cm", "CM", "Championmastery", "championmastery"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords: list):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from abc import abstractmethod, ABCMeta
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
import requests
|
||||||
import riotwatcher
|
import riotwatcher
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,12 +12,14 @@ class Command:
|
||||||
pref = ""
|
pref = ""
|
||||||
api: riotwatcher.LolWatcher
|
api: riotwatcher.LolWatcher
|
||||||
commandName = ""
|
commandName = ""
|
||||||
|
region = ""
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords: list):
|
||||||
for i in additionalKeywords:
|
for i in additionalKeywords:
|
||||||
self.keywords.append(i)
|
self.keywords.append(i)
|
||||||
self.pref = pref
|
self.pref = pref
|
||||||
self.api = api
|
self.api = api
|
||||||
|
self.region = region
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
|
|
@ -43,3 +46,23 @@ class Command:
|
||||||
print(logMSG)
|
print(logMSG)
|
||||||
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):
|
||||||
|
try:
|
||||||
|
var = self.api.summoner.by_name(self.region, sumname)["id"]
|
||||||
|
return True
|
||||||
|
except requests.exceptions.HTTPError:
|
||||||
|
await message.channel.send("No matching player found with name **" + sumname + "**")
|
||||||
|
return False
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import APICommands.Command
|
||||||
class Free2Play(APICommands.Command.Command, ABC):
|
class Free2Play(APICommands.Command.Command, ABC):
|
||||||
keywords = ["f2p", "rotation", "F2P", "ROTATION"]
|
keywords = ["f2p", "rotation", "F2P", "ROTATION"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords=None):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import APICommands.Command
|
||||||
class HighestMastery(APICommands.Command.Command, ABC):
|
class HighestMastery(APICommands.Command.Command, ABC):
|
||||||
keywords = ["highestmastery", "highestMastery", "HM", "hm", "Hm", "HighestMastery"]
|
keywords = ["highestmastery", "highestMastery", "HM", "hm", "Hm", "HighestMastery"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords: list):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ import APICommands.Command
|
||||||
class Prefix(APICommands.Command.Command, ABC):
|
class Prefix(APICommands.Command.Command, ABC):
|
||||||
keywords = ["prefix"]
|
keywords = ["prefix"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords=None):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
self.commandName = "Prefix change"
|
self.commandName = "Prefix change"
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
|
|
@ -30,7 +30,8 @@ class Prefix(APICommands.Command.Command, ABC):
|
||||||
"Your current prefix is: " + self.pref + ". To change it use " + self.pref + "prefix [new Prefix]")
|
"Your current prefix is: " + self.pref + ". To change it use " + self.pref + "prefix [new Prefix]")
|
||||||
|
|
||||||
async def usage(self, message: discord.Message):
|
async def usage(self, message: discord.Message):
|
||||||
await message.channel.send("Wrong usage of prefix command! Use " + self.pref + "prefix [new Prefix (optional)]")
|
await message.channel.send("Wrong usage of" + self.commandName + "! Use " + self.pref + "prefix [new Prefix ("
|
||||||
|
"optional)]")
|
||||||
|
|
||||||
async def changePrefix(self, message: discord.Message):
|
async def changePrefix(self, message: discord.Message):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,31 @@ import APICommands.Command
|
||||||
class SummonerLevel(APICommands.Command.Command, ABC):
|
class SummonerLevel(APICommands.Command.Command, ABC):
|
||||||
keywords = ["level", "Level", "lvl"]
|
keywords = ["level", "Level", "lvl"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords: list):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, 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 = self.getSummonerNameFromMessage(message)
|
||||||
|
except:
|
||||||
|
await self.usage(message)
|
||||||
|
if sumname != "":
|
||||||
|
level = await self.requestLevel(sumname, message)
|
||||||
|
if level is not None:
|
||||||
|
await message.channel.send("Der Spieler " + sumname + " hat das Level " + str(level) + ".")
|
||||||
|
|
||||||
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 + "! Use " + self.pref + "level [Summoner]")
|
||||||
|
|
||||||
|
async def requestLevel(self, sumname: str, message: discord.Message):
|
||||||
|
if not await self.checkSumname(sumname, message):
|
||||||
|
return
|
||||||
|
response = self.api.summoner.by_name(self.region, sumname)
|
||||||
|
return response["summonerLevel"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import APICommands.Command
|
||||||
class SummonerRank(APICommands.Command.Command, ABC):
|
class SummonerRank(APICommands.Command.Command, ABC):
|
||||||
keywords = ["rank", "Rank", "RANK"]
|
keywords = ["rank", "Rank", "RANK"]
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, region: str, additionalKeywords=None):
|
||||||
if additionalKeywords is None:
|
if additionalKeywords is None:
|
||||||
additionalKeywords = []
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, region, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
58
iLeague.py
58
iLeague.py
|
|
@ -26,13 +26,14 @@ class MyClient(discord.Client):
|
||||||
def initAPI(self, APIKey, region="EUW1"):
|
def initAPI(self, APIKey, region="EUW1"):
|
||||||
self.api = LolWatcher(APIKey)
|
self.api = LolWatcher(APIKey)
|
||||||
self.region = region
|
self.region = region
|
||||||
|
self.initCommands()
|
||||||
|
|
||||||
def initCommands(self):
|
def initCommands(self):
|
||||||
self.commands = []
|
self.commands = []
|
||||||
self.commands.append(ChampionMasteryCommand.ChampionMastery(self.api, self.pref, []))
|
self.commands.append(ChampionMasteryCommand.ChampionMastery(self.pref, self.api, self.region, []))
|
||||||
self.commands.append(HighestMasteryCommand.HighestMastery(self.api, self.pref, []))
|
self.commands.append(HighestMasteryCommand.HighestMastery(self.pref, self.api, self.region, []))
|
||||||
self.commands.append(SummonerLevelCommand.SummonerLevel(self.api, self.pref, []))
|
self.commands.append(SummonerLevelCommand.SummonerLevel(self.pref, self.api, self.region, []))
|
||||||
self.commands.append(PrefixCommand.Prefix(self.api, self.pref, []))
|
self.commands.append(PrefixCommand.Prefix(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:
|
||||||
|
|
@ -55,23 +56,23 @@ class MyClient(discord.Client):
|
||||||
message.channel.id == 843900656108437504 or message.channel.id == 673681791932170240): # Only allows channels bot testing and leaguebot
|
message.channel.id == 843900656108437504 or message.channel.id == 673681791932170240): # Only allows channels bot testing and leaguebot
|
||||||
await message.channel.send("Bitte #league-bot verwenden.")
|
await message.channel.send("Bitte #league-bot verwenden.")
|
||||||
return
|
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"]):
|
|
||||||
self.log("Prefix change", message)
|
|
||||||
await self.changePrefix(message)
|
|
||||||
|
|
||||||
# HUBA
|
for command in self.commands:
|
||||||
|
if command.isCalled(message):
|
||||||
|
command.log(message)
|
||||||
|
await command.execute(message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# HUBA
|
||||||
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
||||||
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 (16) 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
|
# LEVEL
|
||||||
elif self.getContentFromMessageWithPrefixCommand(message, ["level", "Level", "lvl"]):
|
elif self.getContentFromMessageWithPrefixCommand(message, ["level", "Level", "lvl"]):
|
||||||
self.log("Summoner level", message)
|
|
||||||
await self.requestLevel(message)
|
await self.requestLevel(message)
|
||||||
|
|
||||||
# RANK
|
# RANK
|
||||||
|
|
@ -105,19 +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 requestLevel(self, message: discord.Message):
|
|
||||||
sumname = ""
|
|
||||||
try:
|
|
||||||
sumname = self.getSummonerNameFromMessage(message)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if sumname != "":
|
|
||||||
if not await self.checkSumname(sumname, message):
|
|
||||||
return
|
|
||||||
response = self.api.summoner.by_name(self.region, sumname)
|
|
||||||
level = response["summonerLevel"]
|
|
||||||
await message.channel.send("Der Spieler " + sumname + " hat das Level " + str(level) + ".")
|
|
||||||
|
|
||||||
async def requestRank(self, message: discord.Message):
|
async def requestRank(self, message: discord.Message):
|
||||||
sumname = ""
|
sumname = ""
|
||||||
try:
|
try:
|
||||||
|
|
@ -240,17 +228,7 @@ class MyClient(discord.Client):
|
||||||
if len(output.split("\n")) <= 2:
|
if len(output.split("\n")) <= 2:
|
||||||
await message.channel.send("ㅤ\t- **Keine**")
|
await message.channel.send("ㅤ\t- **Keine**")
|
||||||
|
|
||||||
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 getChampionMasteryList(self, sumname, listlen):
|
def getChampionMasteryList(self, sumname, listlen):
|
||||||
output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str(
|
output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str(
|
||||||
|
|
@ -277,14 +255,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
|
||||||
|
|
||||||
async def checkSumname(self, sumname, message: discord.Message):
|
|
||||||
try:
|
|
||||||
self.api.summoner.by_name(self.region, sumname)["id"]
|
|
||||||
return True
|
|
||||||
except requests.exceptions.HTTPError:
|
|
||||||
await message.channel.send("No matching player found with name **" + sumname + "**")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def truncate(f, n):
|
def truncate(f, n):
|
||||||
'''Truncates/pads a float f to n decimal places without rounding'''
|
'''Truncates/pads a float f to n decimal places without rounding'''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue