From 1fdca881c999bbf9858337fd94bdfd059e53667c Mon Sep 17 00:00:00 2001 From: BotoX Date: Mon, 13 Aug 2018 08:19:29 +0200 Subject: [PATCH] update --- Torchlight/AsyncClient.py | 2 +- Torchlight/AudioManager.py | 13 ++++++------ Torchlight/Commands.py | 42 +++++++++++++++++++++++++++++++++----- Torchlight/GameEvents.py | 6 +++++- Torchlight/Torchlight.py | 2 ++ 5 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Torchlight/AsyncClient.py b/Torchlight/AsyncClient.py index ae736e1..7461b18 100644 --- a/Torchlight/AsyncClient.py +++ b/Torchlight/AsyncClient.py @@ -51,7 +51,7 @@ class AsyncClient(): async def Connect(self): while True: - self.Logger.warn("Connecting...") + self.Logger.warn("Reconnecting...") try: _, self.Protocol = await self.Loop.create_connection( lambda: ClientProtocol(self.Loop, self), host = self.Host, port = self.Port) diff --git a/Torchlight/AudioManager.py b/Torchlight/AudioManager.py index 7e182d8..7269c8d 100644 --- a/Torchlight/AudioManager.py +++ b/Torchlight/AudioManager.py @@ -247,12 +247,13 @@ class AudioClip(): self.Player.Storage["Audio"]["LastUseLength"] += Delta if str(self.Level) in self.Torchlight().Config["AudioLimits"]: - if self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"]: - self.Torchlight().SayPrivate(self.Player, "You have used up all of your free time! ({0} seconds)".format( - self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"])) - elif self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]: - self.Torchlight().SayPrivate(self.Player, "Your audio clip exceeded the maximum length! ({0} seconds)".format( - self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"])) + if self.Player: + if self.Player.Storage["Audio"]["TimeUsed"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"]: + self.Torchlight().SayPrivate(self.Player, "You have used up all of your free time! ({0} seconds)".format( + self.Torchlight().Config["AudioLimits"][str(self.Level)]["TotalTime"])) + elif self.Player.Storage["Audio"]["LastUseLength"] >= self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"]: + self.Torchlight().SayPrivate(self.Player, "Your audio clip exceeded the maximum length! ({0} seconds)".format( + self.Torchlight().Config["AudioLimits"][str(self.Level)]["MaxLength"])) del self.AudioPlayer diff --git a/Torchlight/Commands.py b/Torchlight/Commands.py index 4cdc144..f45b0cb 100644 --- a/Torchlight/Commands.py +++ b/Torchlight/Commands.py @@ -115,7 +115,7 @@ class URLFilter(BaseCommand): class Access(BaseCommand): def __init__(self, torchlight): super().__init__(torchlight) - self.Triggers = ["!access", "!who", "!whois"] + self.Triggers = ["!access"] #, "!who", "!whois"] self.Level = 0 def FormatAccess(self, player): @@ -263,6 +263,16 @@ class WolframAlpha(BaseCommand): async def _func(self, message, player): self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message)) + + Level = 0 + if player.Access: + Level = player.Access["level"] + + Disabled = self.Torchlight().Disabled + if Disabled and (Disabled > Level or Disabled == Level and Level < self.Torchlight().Config["AntiSpam"]["ImmunityLevel"]): + self.Torchlight().SayPrivate(player, "Torchlight is currently disabled!") + return 1 + Params = dict({"input": message[1], "appid": self.Torchlight().Config["WolframAPIKey"]}) Ret = await self.Calculate(Params) return Ret @@ -333,6 +343,28 @@ class WUnderground(BaseCommand): return 0 +class VoteDisable(BaseCommand): + def __init__(self, torchlight): + super().__init__(torchlight) + self.Triggers = ["!votedisable", "!disablevote"] + self.Level = 0 + + async def _func(self, message, player): + self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message)) + if self.Torchlight().Disabled: + self.Torchlight().SayPrivate(player, "Torchlight is already disabled for the duration of this map.") + return + + self.Torchlight().DisableVotes.add(player.UniqueID) + + have = len(self.Torchlight().DisableVotes) + needed = len(self.Torchlight().Players) // 5 + if have >= needed: + self.Torchlight().SayChat("Torchlight has been disabled for the duration of this map.") + self.Torchlight().Disabled = 6 + else: + self.Torchlight().SayPrivate(player, "Torchlight needs {0} more disable votes to be disabled.".format(needed - have)) + ### LEVEL 0 COMMANDS ### ### LIMITED LEVEL 0 COMMANDS ### @@ -409,7 +441,7 @@ class YouTube(BaseCommand): def __init__(self, torchlight): super().__init__(torchlight) self.Triggers = ["!yt"] - self.Level = 0 + self.Level = 2 async def _func(self, message, player): self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message)) @@ -446,7 +478,7 @@ class YouTubeSearch(BaseCommand): def __init__(self, torchlight): super().__init__(torchlight) self.Triggers = ["!yts"] - self.Level = 0 + self.Level = 2 async def _func(self, message, player): self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message)) @@ -492,14 +524,14 @@ class YouTubeSearch(BaseCommand): class Say(BaseCommand): import gtts import tempfile - VALID_LANGUAGES = [lang for lang in gtts.gTTS.LANGUAGES.keys()] + VALID_LANGUAGES = [lang for lang in gtts.lang.tts_langs().keys()] def __init__(self, torchlight): super().__init__(torchlight) self.Triggers = [("!say", 4)] self.Level = 0 async def Say(self, player, language, message): - GTTS = self.gtts.gTTS(text = message, lang = language, debug = False) + GTTS = self.gtts.gTTS(text = message, lang = language) TempFile = self.tempfile.NamedTemporaryFile(delete = False) GTTS.write_to_fp(TempFile) diff --git a/Torchlight/GameEvents.py b/Torchlight/GameEvents.py index 699d18c..a0ed56c 100644 --- a/Torchlight/GameEvents.py +++ b/Torchlight/GameEvents.py @@ -137,6 +137,10 @@ class GameEvents(): Callbacks = self.Callbacks[Event["name"]] for Callback in Callbacks: - Callback(**Event["data"]) + try: + Callback(**Event["data"]) + except Exception as e: + self.Logger.error(traceback.format_exc()) + self.Logger.error(Event) return True diff --git a/Torchlight/Torchlight.py b/Torchlight/Torchlight.py index 044e999..114b976 100644 --- a/Torchlight/Torchlight.py +++ b/Torchlight/Torchlight.py @@ -31,6 +31,7 @@ class Torchlight(): self.API = SourceModAPI(self.WeakSelf) self.GameEvents = GameEvents(self.WeakSelf) + self.DisableVotes = set() self.Disabled = 0 self.LastUrl = None @@ -71,6 +72,7 @@ class Torchlight(): self.GameEvents.OnPublish(obj) def Event_ServerSpawn(self, hostname, address, ip, port, game, mapname, maxplayers, os, dedicated, password): + self.DisableVotes = set() self.Disabled = 0 def Event_PlayerSay(self, userid, text):