Commands split up into single files and included first methods
This commit is contained in:
parent
5c2ff27656
commit
ef19e6659e
9 changed files with 93 additions and 29 deletions
|
|
@ -10,6 +10,8 @@ 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, additionalKeywords: list):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class Command:
|
||||||
api: riotwatcher.LolWatcher
|
api: riotwatcher.LolWatcher
|
||||||
commandName = ""
|
commandName = ""
|
||||||
|
|
||||||
def __init__(self, pref, api: riotwatcher.LolWatcher, addkeywords: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords: list):
|
||||||
for i in addkeywords:
|
for i in additionalKeywords:
|
||||||
self.keywords.append(i)
|
self.keywords.append(i)
|
||||||
self.pref = pref
|
self.pref = pref
|
||||||
self.api = api
|
self.api = api
|
||||||
|
|
@ -37,7 +37,7 @@ class Command:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def log(self, message: discord.Message):
|
def log(self, message: discord.Message):
|
||||||
logMSG = (self.commandName + " request sent in Channel " + str(message.channel.name) + "\n\t- at: " + str(
|
logMSG = (self.commandName + " request sent:\n\t-in: " + str(message.channel.name) + "\n\t- at: " + str(
|
||||||
datetime.now())[:-7] + "\n\t- by: " + str(message.author) + "\n\t- content: '" + str(
|
datetime.now())[:-7] + "\n\t- by: " + str(message.author) + "\n\t- content: '" + str(
|
||||||
message.content) + "'\n")
|
message.content) + "'\n")
|
||||||
print(logMSG)
|
print(logMSG)
|
||||||
|
|
|
||||||
24
APICommands/F2PCommand.py
Normal file
24
APICommands/F2PCommand.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from abc import ABC
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import riotwatcher
|
||||||
|
|
||||||
|
import APICommands.Command
|
||||||
|
|
||||||
|
|
||||||
|
class Free2Play(APICommands.Command.Command, ABC):
|
||||||
|
keywords = ["f2p", "rotation", "F2P", "ROTATION"]
|
||||||
|
|
||||||
|
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
|
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
|
||||||
|
|
@ -10,6 +10,8 @@ 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, additionalKeywords: list):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import pickle
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
@ -9,14 +10,32 @@ 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: list):
|
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, additionalKeywords)
|
||||||
|
self.commandName = "Prefix change"
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
pass
|
if message.content == (self.pref + "prefix"):
|
||||||
|
await self.info(message)
|
||||||
|
elif message.content.split(" ").length == 2:
|
||||||
|
self.log(message)
|
||||||
|
await self.changePrefix(message)
|
||||||
|
else:
|
||||||
|
await self.usage(message)
|
||||||
|
|
||||||
async def info(self, message: discord.Message):
|
async def info(self, message: discord.Message):
|
||||||
pass
|
await message.channel.send(
|
||||||
|
"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):
|
||||||
pass
|
await message.channel.send("Wrong usage of prefix command! Use " + self.pref + "prefix [new Prefix (optional)]")
|
||||||
|
|
||||||
|
async def changePrefix(self, message: discord.Message):
|
||||||
|
try:
|
||||||
|
self.pref = message.content.split(" ")[1]
|
||||||
|
await message.channel.send("Prefix successfully changed to " + self.pref)
|
||||||
|
pickle.dump(self.pref, open("prefix.data", "wb"))
|
||||||
|
except:
|
||||||
|
await self.usage(message)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ 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, additionalKeywords: list):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
super().__init__(pref, api, additionalKeywords)
|
super().__init__(pref, api, additionalKeywords)
|
||||||
|
|
||||||
async def execute(self, message: discord.Message):
|
async def execute(self, message: discord.Message):
|
||||||
|
|
|
||||||
24
APICommands/SummonerRankCommand.py
Normal file
24
APICommands/SummonerRankCommand.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from abc import ABC
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import riotwatcher
|
||||||
|
|
||||||
|
import APICommands.Command
|
||||||
|
|
||||||
|
|
||||||
|
class SummonerRank(APICommands.Command.Command, ABC):
|
||||||
|
keywords = ["rank", "Rank", "RANK"]
|
||||||
|
|
||||||
|
def __init__(self, pref, api: riotwatcher.LolWatcher, additionalKeywords=None):
|
||||||
|
if additionalKeywords is None:
|
||||||
|
additionalKeywords = []
|
||||||
|
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
|
||||||
31
iLeague.py
31
iLeague.py
|
|
@ -6,7 +6,7 @@ import pickle
|
||||||
import requests
|
import requests
|
||||||
from riotwatcher import LolWatcher
|
from riotwatcher import LolWatcher
|
||||||
|
|
||||||
from APICommands import ChampionMasteryCommand, HighestMasteryCommand, SummonerLevelCommand, PrefixCommand
|
from APICommands import ChampionMasteryCommand, HighestMasteryCommand, SummonerLevelCommand, PrefixCommand, SummonerRankCommand, F2PCommand
|
||||||
|
|
||||||
|
|
||||||
def championIdToName(id, championsText):
|
def championIdToName(id, championsText):
|
||||||
|
|
@ -29,10 +29,12 @@ class MyClient(discord.Client):
|
||||||
|
|
||||||
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.api, self.pref))
|
||||||
self.commands.append(HighestMasteryCommand.HighestMastery(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(SummonerLevelCommand.SummonerLevel(self.api, self.pref))
|
||||||
self.commands.append(PrefixCommand.Prefix(self.api, self.pref, []))
|
self.commands.append(PrefixCommand.Prefix(self.api, self.pref))
|
||||||
|
self.commands.append(SummonerRankCommand.SummonerRank(self.api, self.pref))
|
||||||
|
self.commands.append(F2PCommand.Free2Play(self.api, self.pref))
|
||||||
|
|
||||||
def load(self): # Loads the prefix file if accessable
|
def load(self): # Loads the prefix file if accessable
|
||||||
try:
|
try:
|
||||||
|
|
@ -55,12 +57,10 @@ 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(
|
for command in commands:
|
||||||
"Your current prefix is: " + self.pref + ". To change it use " + self.pref + "prefix [new Prefix]")
|
if command.isCalled(message):
|
||||||
elif self.getContentFromMessageWithPrefixCommand(message, ["prefix"]):
|
command.execute(message);
|
||||||
self.log("Prefix change", message)
|
|
||||||
await self.changePrefix(message)
|
|
||||||
|
|
||||||
# HUBA
|
# HUBA
|
||||||
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
if self.getContentFromMessageWithPrefixCommand(message, ["hubaa"]):
|
||||||
|
|
@ -96,15 +96,6 @@ class MyClient(discord.Client):
|
||||||
self.log("F2P rotation", message)
|
self.log("F2P rotation", message)
|
||||||
await self.requestFreeChampRot(message)
|
await self.requestFreeChampRot(message)
|
||||||
|
|
||||||
async def changePrefix(self, message: discord.Message):
|
|
||||||
try:
|
|
||||||
self.pref = message.content.split(" ")[1]
|
|
||||||
await message.channel.send("Prefix successfully changed to " + self.pref)
|
|
||||||
pickle.dump(self.pref, open("prefix.data", "wb"))
|
|
||||||
except:
|
|
||||||
await message.channel.send(
|
|
||||||
"Something went wrong while changing the prefix. To change it use " + self.pref + "prefix [new Prefix]")
|
|
||||||
|
|
||||||
async def requestLevel(self, message: discord.Message):
|
async def requestLevel(self, message: discord.Message):
|
||||||
sumname = ""
|
sumname = ""
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
For this bot following python packages are needed:
|
For this bot following python packages are needed:
|
||||||
- Discord
|
- Discord
|
||||||
- APIWatcher
|
- RIOTWatcher
|
||||||
|
|
||||||
Installation command for terminal:
|
Installation command for terminal:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue