Summ level command finished

This commit is contained in:
s-prechtl 2022-03-17 11:25:11 +01:00
parent ae22fa98a6
commit c6ecd46b24
8 changed files with 69 additions and 60 deletions

View file

@ -9,10 +9,10 @@ import APICommands.Command
class ChampionMastery(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
async def execute(self, message: discord.Message):
pass

View file

@ -2,6 +2,7 @@ from abc import abstractmethod, ABCMeta
from datetime import datetime
import discord
import requests
import riotwatcher
@ -11,12 +12,14 @@ class Command:
pref = ""
api: riotwatcher.LolWatcher
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:
self.keywords.append(i)
self.pref = pref
self.api = api
self.region = region
@abstractmethod
async def execute(self, message: discord.Message):
@ -43,3 +46,23 @@ class Command:
print(logMSG)
with open("requests.log", "a") as f:
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

View file

@ -9,10 +9,10 @@ import APICommands.Command
class Free2Play(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
async def execute(self, message: discord.Message):
pass

View file

@ -9,10 +9,10 @@ import APICommands.Command
class HighestMastery(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
async def execute(self, message: discord.Message):
pass

View file

@ -10,10 +10,10 @@ import APICommands.Command
class Prefix(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
self.commandName = "Prefix change"
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]")
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):
try:

View file

@ -9,16 +9,31 @@ import APICommands.Command
class SummonerLevel(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
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):
pass
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"]

View file

@ -9,10 +9,10 @@ import APICommands.Command
class SummonerRank(APICommands.Command.Command, ABC):
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:
additionalKeywords = []
super().__init__(pref, api, additionalKeywords)
super().__init__(pref, api, region, additionalKeywords)
async def execute(self, message: discord.Message):
pass