case insensitive and duck string cleaned.

This commit is contained in:
BaerbelBox
2024-02-08 20:31:08 +01:00
parent 9884c1aec2
commit 0c8ff9179b
2 changed files with 35 additions and 25 deletions
+16 -9
View File
@@ -28,14 +28,15 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
self.streakname = "" self.streakname = ""
def update_on_priv_msg(self, data, connection: Connection): def update_on_priv_msg(self, data, connection: Connection):
if data['message'].find('.starthunt') != -1: messageLower=data['message'].lower()
if messageLower.find('.starthunt') != -1:
if not self._is_idented_mod(data, connection): if not self._is_idented_mod(data, connection):
connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data) connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data)
return return
self.active = 1 self.active = 1
connection.send_channel("Jagd eröffnet") connection.send_channel("Jagd eröffnet")
return return
if data['message'].find('.stophunt') != -1: if messageLower.find('.stophunt') != -1:
if not self._is_idented_mod(data, connection): if not self._is_idented_mod(data, connection):
connection.send_back("Dir fehlen leider die Rechte zum Stoppen der Jagd, " + data['nick'] + ".", connection.send_back("Dir fehlen leider die Rechte zum Stoppen der Jagd, " + data['nick'] + ".",
data) data)
@@ -44,11 +45,11 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
self.duck_alive = 0 self.duck_alive = 0
connection.send_channel("Jagd beendet") connection.send_channel("Jagd beendet")
return return
if data['message'].find('.ducks') != -1: if messageLower.find('.ducks') != -1:
connection.send_channel(self.build_duck_string(data['nick'])) connection.send_channel(self.build_duck_string(data['nick']))
if data['message'].find('.freunde') != -1: if messageLower.find('.freunde') != -1:
self.befriend(data, connection) self.befriend(data, connection)
if data['message'].find('.schiessen') != -1: if messageLower.find('.schiessen') != -1:
self.shoot(data, connection) self.shoot(data, connection)
def befriend(self, data, connection): def befriend(self, data, connection):
@@ -121,18 +122,24 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
duckstring = "" duckstring = ""
livingDucks = self.getLiving(nick) livingDucks = self.getLiving(nick)
deadDucks = self.getDead(nick) deadDucks = self.getDead(nick)
if livingDucks ==0 and deadDucks == 0:
return nick + " hat noch nicht an der Entenjagd teilgenommen"
if livingDucks > 1: if livingDucks > 1:
duckstring = duckstring + nick + " hat schon " +str(livingDucks)+ " befreundete Enten und " duckstring = duckstring + nick + " hat schon " +str(livingDucks)+ " befreundete Enten "
elif livingDucks == 1: elif livingDucks == 1:
duckstring = duckstring + nick + " hat schon eine befreundete Ente und " duckstring = duckstring + nick + " hat schon eine befreundete Ente "
elif livingDucks == 0: elif livingDucks == 0:
duckstring = duckstring + nick + " hat noch keine befreundeten Enten und " duckstring = duckstring +nick +" "
if deadDucks > 0 and livingDucks > 0:
duckstring = duckstring +"und "
if deadDucks > 0 and livingDucks == 0:
duckstring = duckstring +"hat "
if deadDucks > 1: if deadDucks > 1:
duckstring = duckstring + str(deadDucks) + " getötete Enten" duckstring = duckstring + str(deadDucks) + " getötete Enten"
elif deadDucks == 1: elif deadDucks == 1:
duckstring = duckstring +"eine getötete Ente" duckstring = duckstring +"eine getötete Ente"
elif deadDucks == 0: elif deadDucks == 0:
duckstring = duckstring+"keine getöteten Enten" duckstring = duckstring+""
return duckstring return duckstring
def duckAchievments(self, nick, connection): def duckAchievments(self, nick, connection):
+19 -16
View File
@@ -29,22 +29,23 @@ class HangmanObserver(PrivMsgObserverPrototype):
self.wrong_guessed = [] self.wrong_guessed = []
self.worder = '' self.worder = ''
self.wrongly_guessedWords = [] self.wrongly_guessedWords = []
self.time = time.time() self.time = 0
self.commands = [] self.commands = []
def update_on_priv_msg(self, data, connection: Connection): def update_on_priv_msg(self, data, connection: Connection):
if data['message'].startswith('.guess '): messageLower = data['message'].lower()
if messageLower.startswith('.guess '):
self.guess(data, connection) self.guess(data, connection)
return return
if data['message'].startswith('.word '): if messageLower.startswith('.word '):
self.take_word(data, connection) self.take_word(data, connection)
if data['message'].startswith('.han') and not data['message'].find('.handelete')!= -1 and not data['message'].find('hanadd' if messageLower.startswith('.han') and not messageLower.find('.handelete')!= -1 and not messageLower.find('hanadd'
) != -1: ) != -1:
self.start_solo_game(data, connection) self.start_solo_game(data, connection)
if data['message'].startswith('.hanadd'): if messageLower.startswith('.hanadd'):
self.han_user_add(data, connection) self.han_user_add(data, connection)
if data['message'].startswith('.stop') and not data['message'].find('.stophunt') != -1 \ if messageLower.startswith('.stop') and not messageLower.find('.stophunt') != -1 \
and not data['message'].find('.stopmath') != -1 and not data['message'].find('.stopslf') != -1: and not messageLower.find('.stopmath') != -1 and not messageLower.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 = []
@@ -53,19 +54,19 @@ class HangmanObserver(PrivMsgObserverPrototype):
self.worder = '' self.worder = ''
self.wrongly_guessedWords = [] self.wrongly_guessedWords = []
self.worder = '' self.worder = ''
if data['message'].startswith('.hint'): if messageLower.startswith('.hint'):
self.hint(data, connection) self.hint(data, connection)
if data['message'].startswith('.score'): if messageLower.startswith('.score'):
self.print_score(data, connection) self.print_score(data, connection)
if data['message'].startswith('.spielregeln'): if messageLower.startswith('.spielregeln'):
self.rules(data, connection) self.rules(data, connection)
if data['message'].startswith('.look'): if messageLower.startswith('.look'):
self.look(data, connection) self.look(data, connection)
if data['message'].startswith('.resetscore') and len(data['message'].split(' ')) < 2: if messageLower.startswith('.resetscore') and len(data['message'].split(' ')) < 2:
self.confirm_reset(data, connection) self.confirm_reset(data, connection)
if data['message'] == '.resetscore ' + data['nick'] + ' JA': if messageLower == '.resetscore ' + data['nick'] + ' JA':
self.reset(data, connection) self.reset(data, connection)
if data['message'].startswith('.handelete '): if messageLower.startswith('.handelete '):
self.delete_HanWord(data, connection) self.delete_HanWord(data, connection)
def delete_HanWord(self,data,connection): def delete_HanWord(self,data,connection):
@@ -124,7 +125,7 @@ class HangmanObserver(PrivMsgObserverPrototype):
def start_solo_game(self, data, connection): def start_solo_game(self, data, connection):
if self.word == '': if self.word == '':
self.time = time.time() self.time = 0
self.word = self.getRandomHanWord() self.word = self.getRandomHanWord()
self.guesses = ['-', '/', ' ', '_','.'] self.guesses = ['-', '/', ' ', '_','.']
self.wrong_guessed = [] self.wrong_guessed = []
@@ -145,6 +146,8 @@ class HangmanObserver(PrivMsgObserverPrototype):
connection.send_channel("Flüstere mir ein neues Wort mit .word WORT") connection.send_channel("Flüstere mir ein neues Wort mit .word WORT")
return return
word_unique_chars = len(set(self.word)) word_unique_chars = len(set(self.word))
if self.time == 0:
self.time = time.time()
if guess == self.word: if guess == self.word:
score = word_unique_chars * self.count_missing_unique() score = word_unique_chars * self.count_missing_unique()
self.addToScore(data['nick'], int(score)) self.addToScore(data['nick'], int(score))
@@ -182,7 +185,7 @@ class HangmanObserver(PrivMsgObserverPrototype):
def take_word(self, data, connection): def take_word(self, data, connection):
self.commands = HelpObserver.collect_commands(self, connection) self.commands = HelpObserver.collect_commands(self, connection)
if self.word == '': if self.word == '':
self.time =time.time() self.time = 0
if data['message'].split(' ')[1] is not None and data['message'].split(' ')[1] not in self.commands: 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')