From 193bac751277cd55d07bdd1741c3aef5451b462c Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Sun, 11 Feb 2024 12:34:24 +0100 Subject: [PATCH] DDOS/Spam protection --- FaustBot/Modules/BastelObserver.py | 40 ++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/FaustBot/Modules/BastelObserver.py b/FaustBot/Modules/BastelObserver.py index a6db6f7..58aeebe 100644 --- a/FaustBot/Modules/BastelObserver.py +++ b/FaustBot/Modules/BastelObserver.py @@ -5,6 +5,10 @@ from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype class BastelObserver(PrivMsgObserverPrototype): + def __init__(self): + super().__init__() + self.annoyed: int = 0 + @staticmethod def cmd(): """ @@ -36,12 +40,32 @@ class BastelObserver(PrivMsgObserverPrototype): """ if data['message'].find('.craft') == -1: return - connection.send_back("\001ACTION rennt in die Werkstatt!\001", data) - sleep(5) - connection.send_back("\001ACTION poltert herum!", data) - # Determine, what Botty has built (random wikipedia article) - crafted_object = wikipedia.random(1) - sleep(5) - connection.send_back( - f"\001ACTION kommt zurück und hat {crafted_object} gebastelt.\001", data) + # Start not more than one process with a longer iteration (15 seconds) + if self.annoyed > 0: + if self.annoyed == 1: + connection.send_back("Lass mich in Ruhe arbeiten!", data) + elif self.annoyed == 2: + connection.send_back("Ich muss mich konzentrieren!", data) + elif self.annoyed == 3: + connection.send_back("So kann ich nicht arbeiten!", data) + else: + connection.send_back("\001ACTION wirft mit Werkzeug um sich!\001", data) + + # Bot is getting more annoyed when hit on multiple times + # self.annoyed is again checked against zero, as it's more likely to prevent a deadlock + if self.annoyed > 0: + self.annoyed = self.annoyed + 1 + else: + self.annoyed = 1 + connection.send_back("\001ACTION rennt in die Werkstatt.\001", data) + sleep(10) + connection.send_back("\001ACTION poltert herum.", data) + + # Determine, what Botty has built (random wikipedia article) + wikipedia.set_lang('de') + crafted_object = wikipedia.random(1) + sleep(5) + connection.send_back( + f"\001ACTION kommt zurück und hat {crafted_object} gebastelt.\001", data) + self.annoyed = 0