mirror of
https://github.com/nichkara/InfinitumBotty.git
synced 2026-06-11 14:41:58 +02:00
@@ -10,11 +10,11 @@ from FaustBot.Model.BlockedUsers import BlockProvider
|
|||||||
class BlockObserver(PrivMsgObserverPrototype):
|
class BlockObserver(PrivMsgObserverPrototype):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cmd():
|
def cmd():
|
||||||
return [""]
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help():
|
def help():
|
||||||
return ""
|
return None
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
def update_on_priv_msg(self, data, connection: Connection):
|
||||||
if not self._is_idented_mod(data, connection):
|
if not self._is_idented_mod(data, connection):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from FaustBot.Communication.Connection import Connection
|
|||||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||||
from FaustBot.Model.ScoreProvider import ScoreProvider
|
from FaustBot.Model.ScoreProvider import ScoreProvider
|
||||||
from FaustBot.Model.HanDatabaseProvider import HanDatabaseProvider
|
from FaustBot.Model.HanDatabaseProvider import HanDatabaseProvider
|
||||||
|
from FaustBot.Modules.HelpObserver import HelpObserver
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
import csv
|
import csv
|
||||||
@@ -13,11 +14,11 @@ import datetime
|
|||||||
class HangmanObserver(PrivMsgObserverPrototype):
|
class HangmanObserver(PrivMsgObserverPrototype):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cmd():
|
def cmd():
|
||||||
return ['.guess', '.word', '.stop', '.hint', '.score', '.spielregeln']
|
return ['.word', '.han', '.guess', '.hint', '.look' '.stop', '.score', '.resetscore', '.spielregeln']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help():
|
def help():
|
||||||
return 'hangman game'
|
return 'Hangman Spiel. Details bitte per PM an den Bot mit .spielregeln abfragen.'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -29,20 +30,21 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
self.worder = ''
|
self.worder = ''
|
||||||
self.wrongly_guessedWords = []
|
self.wrongly_guessedWords = []
|
||||||
self.time = time.time()
|
self.time = time.time()
|
||||||
|
self.commands = []
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
def update_on_priv_msg(self, data, connection: Connection):
|
||||||
if data['message'].find('.guess ') != -1:
|
if data['message'].startswith('.guess '):
|
||||||
self.guess(data, connection)
|
self.guess(data, connection)
|
||||||
return
|
return
|
||||||
if data['message'].find('.word ') != -1:
|
if data['message'].startswith('.word '):
|
||||||
self.take_word(data, connection)
|
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:
|
) != -1:
|
||||||
self.start_solo_game(data, connection)
|
self.start_solo_game(data, connection)
|
||||||
if data['message'].find('hanadd') != -1:
|
if data['message'].startswith('.hanadd'):
|
||||||
self.han_user_add(data, connection)
|
self.han_user_add(data, connection)
|
||||||
if data['message'].find('.stop') != -1 and not data['message'].find('.stophunt') != -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('.stopmath') != -1 and not data['message'].find('.stopslf') != -1:
|
||||||
connection.send_channel("Spiel gestoppt. Das Wort war: " + self.word + " in "+self.timeRelapsedString())
|
connection.send_channel("Spiel gestoppt. Das Wort war: " + self.word + " in "+self.timeRelapsedString())
|
||||||
self.word = ''
|
self.word = ''
|
||||||
self.guesses = []
|
self.guesses = []
|
||||||
@@ -51,17 +53,19 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
self.worder = ''
|
self.worder = ''
|
||||||
self.wrongly_guessedWords = []
|
self.wrongly_guessedWords = []
|
||||||
self.worder = ''
|
self.worder = ''
|
||||||
if data['message'].find('.hint') != -1:
|
if data['message'].startswith('.hint'):
|
||||||
self.hint(data, connection)
|
self.hint(data, connection)
|
||||||
if data['message'].find('.score') != -1:
|
if data['message'].startswith('.score'):
|
||||||
self.print_score(data, connection)
|
self.print_score(data, connection)
|
||||||
if data['message'].find('.spielregeln') != -1:
|
if data['message'].startswith('.spielregeln'):
|
||||||
self.rules(data, connection)
|
self.rules(data, connection)
|
||||||
if data['message'].find('.look') != -1:
|
if data['message'].startswith('.look'):
|
||||||
self.look(data, connection)
|
self.look(data, connection)
|
||||||
if data['message'].find('.resetscore') != -1:
|
if data['message'].startswith('.resetscore') and len(data['message'].split(' ')) < 2:
|
||||||
self.reset(data,connection)
|
self.confirm_reset(data, connection)
|
||||||
if data['message'].find('.handelete') != -1:
|
if data['message'] == '.resetscore ' + data['nick'] + ' JA':
|
||||||
|
self.reset(data, connection)
|
||||||
|
if data['message'].startswith('.handelete '):
|
||||||
self.delete_HanWord(data, connection)
|
self.delete_HanWord(data, connection)
|
||||||
|
|
||||||
def delete_HanWord(self,data,connection):
|
def delete_HanWord(self,data,connection):
|
||||||
@@ -73,10 +77,15 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
self.deleteHanWord(data['message'].split(' ')[1].upper())
|
self.deleteHanWord(data['message'].split(' ')[1].upper())
|
||||||
connection.send_back("Das Wort "+data['message'].split(' ')[1].upper()+" wurde gelöscht, " + data['nick'], data)
|
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 = ScoreProvider()
|
||||||
score_provider.delete_score(data['nick'])
|
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.', data)
|
||||||
|
print(data['message'])
|
||||||
|
|
||||||
def look(self,data, connection):
|
def look(self,data, connection):
|
||||||
if self.worder != '':
|
if self.worder != '':
|
||||||
@@ -171,9 +180,10 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
connection.send_channel(self.prepare_word(data))
|
connection.send_channel(self.prepare_word(data))
|
||||||
|
|
||||||
def take_word(self, data, connection):
|
def take_word(self, data, connection):
|
||||||
|
self.commands = HelpObserver.collect_commands(self, connection)
|
||||||
if self.word == '':
|
if self.word == '':
|
||||||
self.time =time.time()
|
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())
|
self.addHanWord(data['message'].split(' ')[1].upper())
|
||||||
log = open('HangmanLog', 'a')
|
log = open('HangmanLog', 'a')
|
||||||
log.write(data['nick'] + ' ; ' + data['message'].split(' ')[1].upper() + '\n')
|
log.write(data['nick'] + ' ; ' + data['message'].split(' ')[1].upper() + '\n')
|
||||||
@@ -189,10 +199,12 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
connection.send_channel(self.prepare_word(data))
|
connection.send_channel(self.prepare_word(data))
|
||||||
else:
|
else:
|
||||||
connection.send_back("Sorry es läuft bereits ein Wort", data)
|
connection.send_back("Sorry es läuft bereits ein Wort", data)
|
||||||
|
|
||||||
def han_user_add(self, data, connection):
|
def han_user_add(self, data, connection):
|
||||||
if data['message'].split(' ')[1] is not None:
|
if data['message'].split(' ')[1] is not None:
|
||||||
self.addHanWord(data['message'].split(' ')[1].upper())
|
self.addHanWord(data['message'].split(' ')[1].upper())
|
||||||
connection.send_channel("Das Wort "+data['message'].split(' ')[1].upper() +" wurde von "+ data['nick']+ " hinzugefügt")
|
connection.send_channel("Das Wort "+data['message'].split(' ')[1].upper() +" wurde von "+ data['nick']+ " hinzugefügt")
|
||||||
|
|
||||||
def prepare_word(self, data):
|
def prepare_word(self, data):
|
||||||
outWord = ""
|
outWord = ""
|
||||||
failedChars = 0
|
failedChars = 0
|
||||||
@@ -237,6 +249,7 @@ class HangmanObserver(PrivMsgObserverPrototype):
|
|||||||
connection.send_back("Spielregeln bitte im Query abfragen",data)
|
connection.send_back("Spielregeln bitte im Query abfragen",data)
|
||||||
return
|
return
|
||||||
connection.send_back("""Wort starten mit ".word Wort" im Query (Privatchat) mit dem Bot""", data)
|
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("""Raten mit ".guess Buchstabe" im Channel""", data)
|
||||||
connection.send_back("""Geraten werden können einzelne Buchstaben oder das ganze Wort.""", 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)
|
connection.send_back("""Alle dürfen durcheinander raten. Es gibt keine Reihenfolge.""", data)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from types import NoneType
|
||||||
from FaustBot.Communication import Connection
|
from FaustBot.Communication import Connection
|
||||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||||
|
|
||||||
@@ -9,24 +10,52 @@ class HelpObserver(PrivMsgObserverPrototype):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help():
|
def help():
|
||||||
return ".help - zeigt Hilftexte aller Module an"
|
return ".help <Befehl> - zeigt Hilftexte zu <Befehl> an. Für eine Liste aller verfügbaren Befehle: .help all"
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
def update_on_priv_msg(self, data, connection: Connection):
|
||||||
msg = data["message"]
|
msg = data["message"]
|
||||||
|
command = ""
|
||||||
if not msg.startswith(".help"):
|
if not msg.startswith(".help"):
|
||||||
return
|
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)
|
||||||
|
|
||||||
if data["channel"] == connection.details.get_channel():
|
def collect_commands(self, connection):
|
||||||
all_cmd = []
|
all_cmd = []
|
||||||
for observer in connection.priv_msg_observable.get_observer():
|
for observer in connection.priv_msg_observable.get_observer():
|
||||||
cmds = observer.cmd()
|
cmds = observer.cmd()
|
||||||
if cmds is not None:
|
if cmds is not None:
|
||||||
all_cmd.extend(cmds)
|
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 = []
|
||||||
|
all_cmd = self.collect_commands(connection)
|
||||||
msg = ", ".join(all_cmd)
|
msg = ", ".join(all_cmd)
|
||||||
msg = "Bekannte Befehle: " + msg + ". Für Details per Query .help ."
|
msg = "Bekannte Befehle: " + msg
|
||||||
connection.send_back(msg, data)
|
connection.send_back(msg, data)
|
||||||
else:
|
else:
|
||||||
all_help = [m.help() for m in connection.priv_msg_observable.get_observer()]
|
all_help = [m.help() for m in connection.priv_msg_observable.get_observer()]
|
||||||
for help_msg in all_help:
|
for help_msg in all_help:
|
||||||
if help_msg is not None:
|
if help_msg is not None:
|
||||||
connection.send_back(help_msg, data)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ from time import sleep
|
|||||||
class MathRunObserver(PrivMsgObserverPrototype):
|
class MathRunObserver(PrivMsgObserverPrototype):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cmd():
|
def cmd():
|
||||||
return ['.s', '.startMath', '.stopMath']
|
return ['.s', '.startmath', '.stopmath']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help():
|
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):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -21,16 +21,18 @@ class MathRunObserver(PrivMsgObserverPrototype):
|
|||||||
self.oldSolution = 0
|
self.oldSolution = 0
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
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)
|
self.solution(data, connection)
|
||||||
if data['message'].find('.startMath') != -1:
|
if data['message'].startswith('.startmath'):
|
||||||
self.start_math(data, connection)
|
self.start_math(data, connection)
|
||||||
|
if data['message'].startswith('.stopmath'):
|
||||||
|
self.stop_math(data, connection)
|
||||||
|
|
||||||
def solution(self, data, connection):
|
def solution(self, data, connection):
|
||||||
nick = data["nick"]
|
nick = data["nick"]
|
||||||
solutionByPlayer = data['message'].split()[1]
|
solutionByPlayer = data['message'].split()[1]
|
||||||
if solutionByPlayer is None:
|
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
|
return
|
||||||
if solutionByPlayer == str(self.solutionForGame):
|
if solutionByPlayer == str(self.solutionForGame):
|
||||||
connection.send_channel("Korrekte Lösung " + nick)
|
connection.send_channel("Korrekte Lösung " + nick)
|
||||||
@@ -63,9 +65,13 @@ class MathRunObserver(PrivMsgObserverPrototype):
|
|||||||
self.stop_Timer(data, connection)
|
self.stop_Timer(data, connection)
|
||||||
|
|
||||||
def stop_math(self, data, connection):
|
def stop_math(self, data, connection):
|
||||||
|
|
||||||
for player in self.players.keys():
|
for player in self.players.keys():
|
||||||
connection.send_channel(player + " hat\t" + str(self.players[player]) + "\t Punkte")
|
if self.players[player] == 1:
|
||||||
connection.send_channel("Spiel beendet")
|
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.players = {}
|
||||||
self.solutionForGame = 0
|
self.solutionForGame = 0
|
||||||
self.type = 0
|
self.type = 0
|
||||||
@@ -73,4 +79,5 @@ class MathRunObserver(PrivMsgObserverPrototype):
|
|||||||
|
|
||||||
def stop_Timer(self, data, connection):
|
def stop_Timer(self, data, connection):
|
||||||
sleep(120)
|
sleep(120)
|
||||||
|
if self.running:
|
||||||
self.stop_math(data, connection)
|
self.stop_math(data, connection)
|
||||||
@@ -8,11 +8,11 @@ from time import sleep
|
|||||||
class WordRunObserver(PrivMsgObserverPrototype):
|
class WordRunObserver(PrivMsgObserverPrototype):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cmd():
|
def cmd():
|
||||||
return ['.a', '.add', '.begin', '.end']
|
return ['.a', '.add', '.begin', '.end', '.wordrun']
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help():
|
def help():
|
||||||
return 'wordrun game'
|
return 'Wordrun Spiel. Starten mit ".begin <Silbe>" oder ".end <Silbe>". Antwort hinzufügen mit ".a <Antwort>" oder ".add <Antwort>" Mehr Details mit ".wordrun" abfragen.'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -26,12 +26,14 @@ class WordRunObserver(PrivMsgObserverPrototype):
|
|||||||
self.syllable = ""
|
self.syllable = ""
|
||||||
|
|
||||||
def update_on_priv_msg(self, data, connection: Connection):
|
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)
|
self.add(data, connection)
|
||||||
if data['message'].find('.begin ') != -1:
|
if data['message'].startswith('.begin '):
|
||||||
self.begin_word(data, connection)
|
self.begin_word(data, connection)
|
||||||
if data['message'].find('.end ') != -1:
|
if data['message'].startswith('.end '):
|
||||||
self.end_word(data, connection)
|
self.end_word(data, connection)
|
||||||
|
if data['message'].startswith('.wordrun'):
|
||||||
|
self.rules(data, connection)
|
||||||
|
|
||||||
def add(self, data, connection):
|
def add(self, data, connection):
|
||||||
if self.gamestatus == 0:
|
if self.gamestatus == 0:
|
||||||
@@ -95,3 +97,15 @@ class WordRunObserver(PrivMsgObserverPrototype):
|
|||||||
connection.send_channel(s)
|
connection.send_channel(s)
|
||||||
self.gamestatus = 0
|
self.gamestatus = 0
|
||||||
self.player = {}
|
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 <Silbe>", um ein Spiel zu starten, bei dem die Antworten mit <Silbe> anfangen müssen.', data)
|
||||||
|
connection.send_back('Spiel starten mit ".end <Silbe>", um ein Spiel zu starten, bei dem die Antworten mit <Silbe> enden müssen.', data)
|
||||||
|
connection.send_back('Antwort hinzufügen mit ".a <Antwort>" oder ".add <Antwort>"', 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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user