From aeb54acecfff78e27b6b1c66a6e6753fcc09631e Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Thu, 28 Apr 2022 09:34:29 +0200 Subject: [PATCH 1/7] Update HangmanObserver.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Befehle werden nur angenommen, wenn sie an der ersten Stelle in der Nachricht stehen Bestätigung für .resetscore hinzugefügt Fehlende Befehle zur Liste hinzugefügt Hilfetexte angepasst stopMath > stopmath (muss in mathrun noch geändert werden) --- FaustBot/Modules/HangmanObserver.py | 41 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/FaustBot/Modules/HangmanObserver.py b/FaustBot/Modules/HangmanObserver.py index 114dfb4..1fa5f62 100644 --- a/FaustBot/Modules/HangmanObserver.py +++ b/FaustBot/Modules/HangmanObserver.py @@ -13,11 +13,11 @@ import datetime class HangmanObserver(PrivMsgObserverPrototype): @staticmethod def cmd(): - return ['.guess', '.word', '.stop', '.hint', '.score', '.spielregeln'] + return ['.word', '.han', '.guess', '.hint', '.look' '.stop', '.score', '.resetscore', '.spielregeln'] @staticmethod def help(): - return 'hangman game' + return 'Hangman Spiel. Details bitte per PM an den Bot mit .spielregeln abfragen.' def __init__(self): super().__init__() @@ -31,18 +31,18 @@ class HangmanObserver(PrivMsgObserverPrototype): self.time = time.time() def update_on_priv_msg(self, data, connection: Connection): - if data['message'].find('.guess ') != -1: + if data['message'].startswith('.guess '): self.guess(data, connection) return - if data['message'].find('.word ') != -1: + if data['message'].startswith('.word '): self.take_word(data, connection) - if data['message'].find('.han') != -1 and not data['message'].find('.handelete')!= -1 and not data['message'].find('hanadd' + if data['message'].startswith('.han') and not data['message'].find('.handelete')!= -1 and not data['message'].find('hanadd' ) != -1: self.start_solo_game(data, connection) - if data['message'].find('hanadd') != -1: + if data['message'].startswith('.hanadd'): self.han_user_add(data, connection) - if data['message'].find('.stop') != -1 and not data['message'].find('.stophunt') != -1 \ - and not data['message'].find('.stopMath') != -1: + if data['message'].startswith('.stop') and not data['message'].find('.stophunt') != -1 \ + and not data['message'].find('.stopmath') != -1 and not data['message'].find('.stopslf') != -1: connection.send_channel("Spiel gestoppt. Das Wort war: " + self.word + " in "+self.timeRelapsedString()) self.word = '' self.guesses = [] @@ -51,17 +51,19 @@ class HangmanObserver(PrivMsgObserverPrototype): self.worder = '' self.wrongly_guessedWords = [] self.worder = '' - if data['message'].find('.hint') != -1: + if data['message'].startswith('.hint'): self.hint(data, connection) - if data['message'].find('.score') != -1: + if data['message'].startswith('.score'): self.print_score(data, connection) - if data['message'].find('.spielregeln') != -1: + if data['message'].startswith('.spielregeln'): self.rules(data, connection) - if data['message'].find('.look') != -1: + if data['message'].startswith('.look'): self.look(data, connection) - if data['message'].find('.resetscore') != -1: - self.reset(data,connection) - if data['message'].find('.handelete') != -1: + if data['message'].startswith('.resetscore'): + self.confirm_reset(data,connection) + if data['message'] == '.resetscore ' + data['nick'] + ' JA': + self.reset(data, data['nick'], connection) + if data['message'].startswith('.handelete '): self.delete_HanWord(data, connection) def delete_HanWord(self,data,connection): @@ -73,11 +75,15 @@ class HangmanObserver(PrivMsgObserverPrototype): self.deleteHanWord(data['message'].split(' ')[1].upper()) connection.send_back("Das Wort "+data['message'].split(' ')[1].upper()+" wurde gelöscht, " + data['nick'], data) - def reset(self,data,connection): + def reset(self, data, connection): score_provider = ScoreProvider() score_provider.delete_score(data['nick']) connection.send_back("Dein Score wurde gelöscht "+data['nick'], data) + def confirm_reset(self, data, connection): + connection.send_back('Möchtest du deinen Hangman Punktestand wirklich löschen, ' + data['nick'] + '? ' + + 'Wenn ja, antworte bitte mit ".resetscore deinnick JA". Wenn nein, musst du nichts tun.') + def look(self,data, connection): if self.worder != '': connection.send_channel("Das Wort kommt von: "+self.worder ) @@ -189,10 +195,12 @@ class HangmanObserver(PrivMsgObserverPrototype): connection.send_channel(self.prepare_word(data)) else: connection.send_back("Sorry es läuft bereits ein Wort", data) + def han_user_add(self, data, connection): if data['message'].split(' ')[1] is not None: self.addHanWord(data['message'].split(' ')[1].upper()) connection.send_channel("Das Wort "+data['message'].split(' ')[1].upper() +" wurde von "+ data['nick']+ " hinzugefügt") + def prepare_word(self, data): outWord = "" failedChars = 0 @@ -237,6 +245,7 @@ class HangmanObserver(PrivMsgObserverPrototype): connection.send_back("Spielregeln bitte im Query abfragen",data) return connection.send_back("""Wort starten mit ".word Wort" im Query (Privatchat) mit dem Bot""", data) + connection.send_back("""Solospiel starten mit ".han" - Botty sucht dann das Wort aus""", data) connection.send_back("""Raten mit ".guess Buchstabe" im Channel""", data) connection.send_back("""Geraten werden können einzelne Buchstaben oder das ganze Wort.""", data) connection.send_back("""Alle dürfen durcheinander raten. Es gibt keine Reihenfolge.""", data) From 439a2c41044352d9de91a18d505912856db1c929 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Thu, 28 Apr 2022 11:01:32 +0200 Subject: [PATCH 2/7] Hangman fix reset & commands Fixed mistakes in resetscore Excluded all available commands from words to play with --- FaustBot/Modules/HangmanObserver.py | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/FaustBot/Modules/HangmanObserver.py b/FaustBot/Modules/HangmanObserver.py index 1fa5f62..0e5b7b7 100644 --- a/FaustBot/Modules/HangmanObserver.py +++ b/FaustBot/Modules/HangmanObserver.py @@ -3,6 +3,7 @@ from FaustBot.Communication.Connection import Connection from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Model.ScoreProvider import ScoreProvider from FaustBot.Model.HanDatabaseProvider import HanDatabaseProvider +from FaustBot.Modules.HelpObserver import HelpObserver from collections import defaultdict from threading import Lock import csv @@ -29,6 +30,7 @@ class HangmanObserver(PrivMsgObserverPrototype): self.worder = '' self.wrongly_guessedWords = [] self.time = time.time() + self.commands = [] def update_on_priv_msg(self, data, connection: Connection): if data['message'].startswith('.guess '): @@ -59,10 +61,10 @@ class HangmanObserver(PrivMsgObserverPrototype): self.rules(data, connection) if data['message'].startswith('.look'): self.look(data, connection) - if data['message'].startswith('.resetscore'): - self.confirm_reset(data,connection) + if data['message'].startswith('.resetscore') and len(data['message'].split(' ')) < 2: + self.confirm_reset(data, connection) if data['message'] == '.resetscore ' + data['nick'] + ' JA': - self.reset(data, data['nick'], connection) + self.reset(data, connection) if data['message'].startswith('.handelete '): self.delete_HanWord(data, connection) @@ -78,11 +80,12 @@ class HangmanObserver(PrivMsgObserverPrototype): def reset(self, data, connection): score_provider = ScoreProvider() score_provider.delete_score(data['nick']) - connection.send_back("Dein Score wurde gelöscht "+data['nick'], data) + connection.send_back("Dein Score wurde gelöscht, "+data['nick'], data) def confirm_reset(self, data, connection): connection.send_back('Möchtest du deinen Hangman Punktestand wirklich löschen, ' + data['nick'] + '? ' + - 'Wenn ja, antworte bitte mit ".resetscore deinnick JA". Wenn nein, musst du nichts tun.') + 'Wenn ja, antworte bitte mit ".resetscore deinnick JA". Wenn nein, musst du nichts tun.', data) + print(data['message']) def look(self,data, connection): if self.worder != '': @@ -177,22 +180,23 @@ class HangmanObserver(PrivMsgObserverPrototype): connection.send_channel(self.prepare_word(data)) def take_word(self, data, connection): + self.commands = HelpObserver.collect_commands(self, connection) if self.word == '': self.time =time.time() - if data['message'].split(' ')[1] is not None: + if data['message'].split(' ')[1] is not None and data['message'].split(' ')[1] not in self.commands: self.addHanWord(data['message'].split(' ')[1].upper()) - log = open('HangmanLog', 'a') - log.write(data['nick'] + ' ; ' + data['message'].split(' ')[1].upper() + '\n') - log.close() - self.word = data['message'].split(' ')[1].upper() - self.guesses = ['-', '/', ' ', '_','.'] - self.wrong_guessed = [] - self.tries_left = 11 - self.wrongly_guessedWords = [] - connection.send_back("Danke für das Wort, es ist nun im Spiel!", data) - connection.send_channel("Das Wort ist von: "+data['nick']) - self.worder = data['nick'] - connection.send_channel(self.prepare_word(data)) + log = open('HangmanLog', 'a') + log.write(data['nick'] + ' ; ' + data['message'].split(' ')[1].upper() + '\n') + log.close() + self.word = data['message'].split(' ')[1].upper() + self.guesses = ['-', '/', ' ', '_','.'] + self.wrong_guessed = [] + self.tries_left = 11 + self.wrongly_guessedWords = [] + connection.send_back("Danke für das Wort, es ist nun im Spiel!", data) + connection.send_channel("Das Wort ist von: "+data['nick']) + self.worder = data['nick'] + connection.send_channel(self.prepare_word(data)) else: connection.send_back("Sorry es läuft bereits ein Wort", data) From 833a8a9167464eb4bb442880a574b6fe265dddc7 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Thu, 28 Apr 2022 11:35:28 +0200 Subject: [PATCH 3/7] Update MathRunObserver.py Commands should be all lower case Extended help message --- FaustBot/Modules/MathRunObserver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FaustBot/Modules/MathRunObserver.py b/FaustBot/Modules/MathRunObserver.py index 6020851..ce63d54 100644 --- a/FaustBot/Modules/MathRunObserver.py +++ b/FaustBot/Modules/MathRunObserver.py @@ -6,11 +6,11 @@ from time import sleep class MathRunObserver(PrivMsgObserverPrototype): @staticmethod def cmd(): - return ['.s', '.startMath', '.stopMath'] + return ['.s', '.startmath', '.stopmath'] @staticmethod def help(): - return 'startMath startet eine Reihe von Aufgaben. StopMath beendet sie.' + return '.startmath startet eine Reihe von Aufgaben. .stopmath beendet sie. Lösungen mit ".s Lösung" eingeben.' def __init__(self): super().__init__() @@ -23,7 +23,7 @@ class MathRunObserver(PrivMsgObserverPrototype): def update_on_priv_msg(self, data, connection: Connection): if data['message'].find('.s ') != -1 : self.solution(data, connection) - if data['message'].find('.startMath') != -1: + if data['message'].find('.startmath') != -1: self.start_math(data, connection) def solution(self, data, connection): From 71d55e737a5b71a8808beaf810338c0a84cdb1a1 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Thu, 28 Apr 2022 11:37:21 +0200 Subject: [PATCH 4/7] Update HelpObserver.py Updated help message .help shows help message for specified command Command can be written with or without leading '.' --- FaustBot/Modules/HelpObserver.py | 41 +++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/FaustBot/Modules/HelpObserver.py b/FaustBot/Modules/HelpObserver.py index 6fe9837..a5a5470 100644 --- a/FaustBot/Modules/HelpObserver.py +++ b/FaustBot/Modules/HelpObserver.py @@ -1,3 +1,4 @@ +from types import NoneType from FaustBot.Communication import Connection from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype @@ -9,24 +10,52 @@ class HelpObserver(PrivMsgObserverPrototype): @staticmethod def help(): - return ".help - zeigt Hilftexte aller Module an" + return ".help - zeigt Hilftexte zu an. Für eine Liste aller verfügbaren Befehle: .help all" def update_on_priv_msg(self, data, connection: Connection): msg = data["message"] + command = "" if not msg.startswith(".help"): return + if len(msg.split(' ')) > 1: + command = msg.split(' ')[1] + if command == 'all': + self.show_available_commands(data, connection) + else: + if not command.startswith("."): + command = '.' + command + self.show_help_for_command(command, data, connection) + else: + connection.send_back(self.help(), data) + def collect_commands(self, connection): + all_cmd = [] + for observer in connection.priv_msg_observable.get_observer(): + cmds = observer.cmd() + if cmds is not None: + all_cmd.extend(cmds) + print(all_cmd) + return all_cmd + + def show_available_commands(self, data, connection): if data["channel"] == connection.details.get_channel(): all_cmd = [] - for observer in connection.priv_msg_observable.get_observer(): - cmds = observer.cmd() - if cmds is not None: - all_cmd.extend(cmds) + all_cmd = self.collect_commands(connection) msg = ", ".join(all_cmd) - msg = "Bekannte Befehle: " + msg + ". Für Details per Query .help ." + msg = "Bekannte Befehle: " + msg connection.send_back(msg, data) else: all_help = [m.help() for m in connection.priv_msg_observable.get_observer()] for help_msg in all_help: if help_msg is not None: connection.send_back(help_msg, data) + + def show_help_for_command(self, command, data, connection): + for observer in connection.priv_msg_observable.get_observer(): + if observer.cmd() is not None: + if command in observer.cmd(): + print(observer.help()) + connection.send_back(observer.help(), data) + + + From 8033e50b67c05ab2d90f183eb7001080e5d23344 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Thu, 28 Apr 2022 16:32:14 +0200 Subject: [PATCH 5/7] Update MathRunObserver.py Changed command to lowercase Command must be first word in message Implemented stopmath Minor fix in score message to send (removed apology. it's not botty's fault) --- FaustBot/Modules/MathRunObserver.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/FaustBot/Modules/MathRunObserver.py b/FaustBot/Modules/MathRunObserver.py index ce63d54..bb87d90 100644 --- a/FaustBot/Modules/MathRunObserver.py +++ b/FaustBot/Modules/MathRunObserver.py @@ -10,7 +10,7 @@ class MathRunObserver(PrivMsgObserverPrototype): @staticmethod def help(): - return '.startmath startet eine Reihe von Aufgaben. .stopmath beendet sie. Lösungen mit ".s Lösung" eingeben.' + return '".startmath" startet eine Reihe von Aufgaben. ".stopmath" beendet sie. Lösungen mit ".s Lösung" eingeben.' def __init__(self): super().__init__() @@ -21,16 +21,18 @@ class MathRunObserver(PrivMsgObserverPrototype): self.oldSolution = 0 def update_on_priv_msg(self, data, connection: Connection): - if data['message'].find('.s ') != -1 : + if data['message'].startswith('.s ') and not data['message'].startswith('.startmath') and not data['message'].startswith('.stopmath'): self.solution(data, connection) - if data['message'].find('.startmath') != -1: + if data['message'].startswith('.startmath'): self.start_math(data, connection) + if data['message'].startswith('.stopmath'): + self.stop_math(data, connection) def solution(self, data, connection): nick = data["nick"] solutionByPlayer = data['message'].split()[1] if solutionByPlayer is None: - connection.send_back("Sorry du hast keine Lösung angegeben " + nick, data) + connection.send_back("Du hast keine Lösung angegeben " + nick, data) return if solutionByPlayer == str(self.solutionForGame): connection.send_channel("Korrekte Lösung " + nick) @@ -63,9 +65,13 @@ class MathRunObserver(PrivMsgObserverPrototype): self.stop_Timer(data, connection) def stop_math(self, data, connection): + for player in self.players.keys(): - connection.send_channel(player + " hat\t" + str(self.players[player]) + "\t Punkte") - connection.send_channel("Spiel beendet") + if self.players[player] == 1: + connection.send_channel(player + " hat\t" + str(self.players[player]) + "\tPunkt") + else: + connection.send_channel(player + " hat\t" + str(self.players[player]) + "\tPunkte") + connection.send_channel("Mathrun beendet") self.players = {} self.solutionForGame = 0 self.type = 0 @@ -73,4 +79,5 @@ class MathRunObserver(PrivMsgObserverPrototype): def stop_Timer(self, data, connection): sleep(120) - self.stop_math(data, connection) \ No newline at end of file + if self.running: + self.stop_math(data, connection) \ No newline at end of file From c5cd1bac9cae5d96a3995249af84ef475122b598 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Fri, 29 Apr 2022 09:49:43 +0200 Subject: [PATCH 6/7] Update BlockObserver.py Removed empty command --- FaustBot/Modules/BlockObserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FaustBot/Modules/BlockObserver.py b/FaustBot/Modules/BlockObserver.py index 631d910..163b61c 100644 --- a/FaustBot/Modules/BlockObserver.py +++ b/FaustBot/Modules/BlockObserver.py @@ -10,11 +10,11 @@ from FaustBot.Model.BlockedUsers import BlockProvider class BlockObserver(PrivMsgObserverPrototype): @staticmethod def cmd(): - return [""] + return None @staticmethod def help(): - return "" + return None def update_on_priv_msg(self, data, connection: Connection): if not self._is_idented_mod(data, connection): From d1adb77a33c991ad1d9ef7fa54023c7c2e5ec5c8 Mon Sep 17 00:00:00 2001 From: ThomasWeis Date: Fri, 29 Apr 2022 09:51:49 +0200 Subject: [PATCH 7/7] Update WordRunObserver.py Added command to show rules Command must be first word in message Updataed help text --- FaustBot/Modules/WordRunObserver.py | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/FaustBot/Modules/WordRunObserver.py b/FaustBot/Modules/WordRunObserver.py index aff4fc2..25fe502 100644 --- a/FaustBot/Modules/WordRunObserver.py +++ b/FaustBot/Modules/WordRunObserver.py @@ -8,11 +8,11 @@ from time import sleep class WordRunObserver(PrivMsgObserverPrototype): @staticmethod def cmd(): - return ['.a', '.add', '.begin', '.end'] + return ['.a', '.add', '.begin', '.end', '.wordrun'] @staticmethod def help(): - return 'wordrun game' + return 'Wordrun Spiel. Starten mit ".begin " oder ".end ". Antwort hinzufügen mit ".a " oder ".add " Mehr Details mit ".wordrun" abfragen.' def __init__(self): super().__init__() @@ -26,13 +26,15 @@ class WordRunObserver(PrivMsgObserverPrototype): self.syllable = "" def update_on_priv_msg(self, data, connection: Connection): - if data['message'].find('.a ') != -1 or data['message'].find('.add ') != -1: + if data['message'].startswith('.a ') or data['message'].startswith('.add '): self.add(data, connection) - if data['message'].find('.begin ') != -1: - self.begin_word(data, connection) - if data['message'].find('.end ') != -1: - self.end_word(data, connection) - + if data['message'].startswith('.begin '): + self.begin_word(data, connection) + if data['message'].startswith('.end '): + self.end_word(data, connection) + if data['message'].startswith('.wordrun'): + self.rules(data, connection) + def add(self, data, connection): if self.gamestatus == 0: connection.send_channel("Es läuft derzeit kein Wordrun, bitte einen neuen mit .begin oder .end erstellen!") @@ -94,4 +96,16 @@ class WordRunObserver(PrivMsgObserverPrototype): s = s + p + ": "+str(player_score[p])+ "; " connection.send_channel(s) self.gamestatus = 0 - self.player = {} \ No newline at end of file + self.player = {} + + def rules(self, data, connection): + if data['channel'] == connection.details.get_channel(): + connection.send_back("Spielregeln bitte im Query (Privatchat) mit dem Bot abfragen", data) + return + connection.send_back('Wordrun Spiel: So viele Wörter wie möglich finden, die mit der vorgegebenen Silbe anfangen oder aufhören.', data) + connection.send_back('Spiel starten mit ".begin ", um ein Spiel zu starten, bei dem die Antworten mit anfangen müssen.', data) + connection.send_back('Spiel starten mit ".end ", um ein Spiel zu starten, bei dem die Antworten mit enden müssen.', data) + connection.send_back('Antwort hinzufügen mit ".a " oder ".add "', data) + connection.send_back('Es können auch mehrere Antworten in einer Zeile angegeben werden', data) + connection.send_back('Das Spiel dauert 3 Minuten. Für jede gültige Antwort gibt es 1 Punkt.', data) +