diff --git a/APICommands/ChampionMasteryCommand.py b/APICommands/ChampionMasteryCommand.py new file mode 100644 index 0000000..8a35c90 --- /dev/null +++ b/APICommands/ChampionMasteryCommand.py @@ -0,0 +1,22 @@ +from abc import ABC + +import discord +import riotwatcher + +import APICommands.Command + + +class ChampionMastery(APICommands.Command.Command, ABC): + keywords = ["cm", "CM", "Championmastery", "championmastery"] + + def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list): + super().__init__(pref, api, additionalKeywords) + + async def execute(self, message: discord.Message): + pass + + async def info(self, message: discord.Message): + pass + + async def usage(self, message: discord.Message): + pass diff --git a/APICommands/Command.py b/APICommands/Command.py new file mode 100644 index 0000000..f1bc8d8 --- /dev/null +++ b/APICommands/Command.py @@ -0,0 +1,45 @@ +from abc import abstractmethod, ABCMeta +from datetime import datetime + +import discord +import riotwatcher + + +class Command: + __metaclass__ = ABCMeta + keywords = [] + pref = "" + api: riotwatcher.LolWatcher + commandName = "" + + def __init__(self, pref, api: riotwatcher.LolWatcher, addkeywords: list): + for i in addkeywords: + self.keywords.append(i) + self.pref = pref + self.api = api + + @abstractmethod + async def execute(self, message: discord.Message): + pass + + @abstractmethod + async def info(self, message: discord.Message): + pass + + @abstractmethod + async def usage(self, message: discord.Message): + pass + + def isCalled(self, message: discord.Message): + for i in self.keywords: + if message.content.startswith(self.pref + i): + return True + return False + + def log(self, message: discord.Message): + logMSG = (self.commandName + " request sent in Channel " + str(message.channel.name) + "\n\t- at: " + str( + datetime.now())[:-7] + "\n\t- by: " + str(message.author) + "\n\t- content: '" + str( + message.content) + "'\n") + print(logMSG) + with open("requests.log", "a") as f: + f.write(logMSG) \ No newline at end of file diff --git a/APICommands/HighestMasteryCommand.py b/APICommands/HighestMasteryCommand.py new file mode 100644 index 0000000..4467b68 --- /dev/null +++ b/APICommands/HighestMasteryCommand.py @@ -0,0 +1,22 @@ +from abc import ABC + +import discord +import riotwatcher + +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): + super().__init__(pref, api, additionalKeywords) + + async def execute(self, message: discord.Message): + pass + + async def info(self, message: discord.Message): + pass + + async def usage(self, message: discord.Message): + pass diff --git a/APICommands/PrefixCommand.py b/APICommands/PrefixCommand.py new file mode 100644 index 0000000..60beda9 --- /dev/null +++ b/APICommands/PrefixCommand.py @@ -0,0 +1,22 @@ +from abc import ABC + +import discord +import riotwatcher + +import APICommands.Command + + +class Prefix(APICommands.Command.Command, ABC): + keywords = ["prefix"] + + def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list): + super().__init__(pref, api, additionalKeywords) + + async def execute(self, message: discord.Message): + pass + + async def info(self, message: discord.Message): + pass + + async def usage(self, message: discord.Message): + pass diff --git a/APICommands/SummonerLevelCommand.py b/APICommands/SummonerLevelCommand.py new file mode 100644 index 0000000..658303b --- /dev/null +++ b/APICommands/SummonerLevelCommand.py @@ -0,0 +1,22 @@ +from abc import ABC + +import discord +import riotwatcher + +import APICommands.Command + + +class SummonerLevel(APICommands.Command.Command, ABC): + keywords = ["level", "Level", "lvl"] + + def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list): + super().__init__(pref, api, additionalKeywords) + + async def execute(self, message: discord.Message): + pass + + async def info(self, message: discord.Message): + pass + + async def usage(self, message: discord.Message): + pass diff --git a/iLeague.py b/iLeague.py index b934a10..b8e74a3 100644 --- a/iLeague.py +++ b/iLeague.py @@ -1,9 +1,12 @@ import datetime import json -import discord, pickle +import discord +import pickle import requests -from riotwatcher import LolWatcher, ApiError +from riotwatcher import LolWatcher + +from APICommands import ChampionMasteryCommand, HighestMasteryCommand, SummonerLevelCommand, PrefixCommand def championIdToName(id, championsText): @@ -18,12 +21,20 @@ class MyClient(discord.Client): api: LolWatcher region: str pref = "$" + commands = [] def initAPI(self, APIKey, region="EUW1"): self.api = LolWatcher(APIKey) self.region = region - def load(self): # Loads the prefix file if accesable + def initCommands(self): + self.commands = [] + self.commands.append(ChampionMasteryCommand.ChampionMastery(self.api, self.pref, [])) + self.commands.append(HighestMasteryCommand.HighestMastery(self.api, self.pref, [])) + self.commands.append(SummonerLevelCommand.SummonerLevel(self.api, self.pref, [])) + self.commands.append(PrefixCommand.Prefix(self.api, self.pref, [])) + + def load(self): # Loads the prefix file if accessable try: self.pref = pickle.load(open("prefix.data", "rb")) print("Prefix loaded as: " + self.pref) @@ -99,7 +110,7 @@ class MyClient(discord.Client): try: sumname = self.getSummonerNameFromMessage(message) except: - await message.channel.send(err) + pass if sumname != "": if not await self.checkSumname(sumname, message): return @@ -241,12 +252,6 @@ class MyClient(discord.Client): ret = inp[argumentstart] return ret - def getContentFromMessageWithPrefixCommand(self, message: discord.Message, command: list): - for i in command: - if message.content.startswith(self.pref + i): - return True - return False - def getChampionMasteryList(self, sumname, listlen): output = ["Der Spieler " + sumname + " hat den höchsten Mastery auf diesen " + str( listlen) + " Champions\n"] @@ -266,13 +271,6 @@ class MyClient(discord.Client): output[count] += out return output - def log(self, requestType, message: discord.Message): - logMSG =( requestType + " request sent in Channel " + str(message.channel.name) + "\n\t- at: " + str( - datetime.datetime.now())[:-7] + "\n\t- by: " + str(message.author) + "\n\t- content: '" + str(message.content) + "'\n") - print(logMSG) - with open("requests.log", "a") as f: - f.write(logMSG) - def getEncryptedSummonerID(self, name): return self.api.summoner.by_name(self.region, name)["id"]