From ba934212d2b38b386dbd2c636cad03bdb63c8c62 Mon Sep 17 00:00:00 2001 From: Context 77 <126421199+ctx77@users.noreply.github.com> Date: Sun, 11 Aug 2024 22:32:02 +0200 Subject: [PATCH] f-stringify blockObs and only act on startswith --- FaustBot/Modules/BlockObserver.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/FaustBot/Modules/BlockObserver.py b/FaustBot/Modules/BlockObserver.py index 6c503da..2bf7374 100644 --- a/FaustBot/Modules/BlockObserver.py +++ b/FaustBot/Modules/BlockObserver.py @@ -2,6 +2,7 @@ from FaustBot.Communication.Connection import Connection from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Model.BlockedUsers import BlockProvider + class BlockObserver(PrivMsgObserverPrototype): @staticmethod def cmd(): @@ -14,32 +15,33 @@ class BlockObserver(PrivMsgObserverPrototype): def update_on_priv_msg(self, data, connection: Connection): if not self._is_idented_mod(data, connection): return - if data['message'].find('.block ') != -1: + if data["message"].startswith(".block "): self.block(data, connection) - if data['message'].find ('.unblock')!=-1: + if data["message"].startswith(".unblock"): self.unblock(data, connection) - if data['message'].find('.isblocked') != -1: + if data["message"].startswith(".isblocked"): self.isBlocked(data, connection) - def block(self,data,connection): + def block(self, data, connection): blocklist = BlockProvider() blocklist.block(self.isolateTarget(data)) - connection.send_back("blocked: "+ self.isolateTarget(data), data) + connection.send_back(f"blocked: {self.isolateTarget(data)}", data) - def unblock(self,data,connection): + def unblock(self, data, connection): blocklist = BlockProvider() blocklist.delete_block(self.isolateTarget(data)) - connection.send_back("unblocked: "+ self.isolateTarget(data), data) + connection.send_back(f"unblocked: {self.isolateTarget(data)}", data) - def isBlocked(self,data,connection): - blocklist= BlockProvider() + def isBlocked(self, data, connection): + blocklist = BlockProvider() answ = blocklist.is_blocked(self.isolateTarget(data)) if answ: - connection.send_back(self.isolateTarget(data) + " ist geblocked", data) + connection.send_back(f"{self.isolateTarget(data)} ist geblocked", data) return - connection.send_back(self.isolateTarget(data)+" ist nicht geblocked", data) - def isolateTarget(self,data): - return data['message'].split(' ')[1] + connection.send_back(f"{self.isolateTarget(data)} ist nicht geblocked", data) + + def isolateTarget(self, data): + return data["message"].split(" ")[1] def _is_idented_mod(self, data: dict, connection: Connection): - return data['nick'] in self._config.mods and connection.is_idented(data['nick']) \ No newline at end of file + return data["nick"] in self._config.mods and connection.is_idented(data["nick"])