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

View File

@@ -28,14 +28,15 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
self.streakname = ""
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):
connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data)
return
self.active = 1
connection.send_channel("Jagd eröffnet")
return
if data['message'].find('.stophunt') != -1:
if messageLower.find('.stophunt') != -1:
if not self._is_idented_mod(data, connection):
connection.send_back("Dir fehlen leider die Rechte zum Stoppen der Jagd, " + data['nick'] + ".",
data)
@@ -44,11 +45,11 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
self.duck_alive = 0
connection.send_channel("Jagd beendet")
return
if data['message'].find('.ducks') != -1:
if messageLower.find('.ducks') != -1:
connection.send_channel(self.build_duck_string(data['nick']))
if data['message'].find('.freunde') != -1:
if messageLower.find('.freunde') != -1:
self.befriend(data, connection)
if data['message'].find('.schiessen') != -1:
if messageLower.find('.schiessen') != -1:
self.shoot(data, connection)
def befriend(self, data, connection):
@@ -121,18 +122,24 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
duckstring = ""
livingDucks = self.getLiving(nick)
deadDucks = self.getDead(nick)
if livingDucks ==0 and deadDucks == 0:
return nick + " hat noch nicht an der Entenjagd teilgenommen"
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:
duckstring = duckstring + nick + " hat schon eine befreundete Ente und "
duckstring = duckstring + nick + " hat schon eine befreundete Ente "
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:
duckstring = duckstring + str(deadDucks) + " getötete Enten"
elif deadDucks == 1:
duckstring = duckstring +"eine getötete Ente"
elif deadDucks == 0:
duckstring = duckstring+"keine getöteten Enten"
duckstring = duckstring+""
return duckstring
def duckAchievments(self, nick, connection):

View File

@@ -29,22 +29,23 @@ class HangmanObserver(PrivMsgObserverPrototype):
self.wrong_guessed = []
self.worder = ''
self.wrongly_guessedWords = []
self.time = time.time()
self.time = 0
self.commands = []
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)
return
if data['message'].startswith('.word '):
if messageLower.startswith('.word '):
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:
self.start_solo_game(data, connection)
if data['message'].startswith('.hanadd'):
if messageLower.startswith('.hanadd'):
self.han_user_add(data, connection)
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:
if messageLower.startswith('.stop') and not messageLower.find('.stophunt') != -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())
self.word = ''
self.guesses = []
@@ -53,19 +54,19 @@ class HangmanObserver(PrivMsgObserverPrototype):
self.worder = ''
self.wrongly_guessedWords = []
self.worder = ''
if data['message'].startswith('.hint'):
if messageLower.startswith('.hint'):
self.hint(data, connection)
if data['message'].startswith('.score'):
if messageLower.startswith('.score'):
self.print_score(data, connection)
if data['message'].startswith('.spielregeln'):
if messageLower.startswith('.spielregeln'):
self.rules(data, connection)
if data['message'].startswith('.look'):
if messageLower.startswith('.look'):
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)
if data['message'] == '.resetscore ' + data['nick'] + ' JA':
if messageLower == '.resetscore ' + data['nick'] + ' JA':
self.reset(data, connection)
if data['message'].startswith('.handelete '):
if messageLower.startswith('.handelete '):
self.delete_HanWord(data, connection)
def delete_HanWord(self,data,connection):
@@ -124,7 +125,7 @@ class HangmanObserver(PrivMsgObserverPrototype):
def start_solo_game(self, data, connection):
if self.word == '':
self.time = time.time()
self.time = 0
self.word = self.getRandomHanWord()
self.guesses = ['-', '/', ' ', '_','.']
self.wrong_guessed = []
@@ -145,6 +146,8 @@ class HangmanObserver(PrivMsgObserverPrototype):
connection.send_channel("Flüstere mir ein neues Wort mit .word WORT")
return
word_unique_chars = len(set(self.word))
if self.time == 0:
self.time = time.time()
if guess == self.word:
score = word_unique_chars * self.count_missing_unique()
self.addToScore(data['nick'], int(score))
@@ -182,7 +185,7 @@ class HangmanObserver(PrivMsgObserverPrototype):
def take_word(self, data, connection):
self.commands = HelpObserver.collect_commands(self, connection)
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:
self.addHanWord(data['message'].split(' ')[1].upper())
log = open('HangmanLog', 'a')