add rare trigger

This commit is contained in:
Mylloon 2022-08-06 03:27:15 +02:00
parent 58f7990c14
commit 5e87ac7aec
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

22
main.py
View file

@ -121,7 +121,14 @@ class Listener(Stream):
# Check if the last word found is a supported word # Check if the last word found is a supported word
if lastWord in universalBase: if lastWord in universalBase:
answer = None answer = None
# Fetch an adequate response
# Check repetition
repetition = findall(r"di(\S+)", lastWord)
if(len(repetition) > 0):
# We need to repeat something...
answer = repeater(repetition[0])
# Fetch an other adequate (better) response
for mot in base.items(): for mot in base.items():
if lastWord in mot[1]: if lastWord in mot[1]:
# Handle specific case # Handle specific case
@ -132,6 +139,7 @@ class Listener(Stream):
else: else:
answer = answers[mot[0]][1] # soir answer = answers[mot[0]][1] # soir
else: else:
# Normal answer
answer = answers[mot[0]] answer = answers[mot[0]]
if answer == None: if answer == None:
if keys["VERBOSE"]: if keys["VERBOSE"]:
@ -172,6 +180,18 @@ class Listener(Stream):
print("\n") print("\n")
return False return False
def repeater(word: str) -> str:
"""Formating a word who need to be repeated"""
# Remove first letter if the first letter is a "S" or a "T"
# Explanation: Trigger word for the repeater is "di" and sometimes it is
# "dis", sometimes its "dit", that's why we need to remove this 2 letters
# from the final answer
if word[0] == 's' or word[0] == 't':
word = word[1:]
# Random format from the base answer
return createBaseAnswers(word)
def getFriendsID(api: API, users: list[str]) -> list: def getFriendsID(api: API, users: list[str]) -> list:
"""Get all friends of choosen users""" """Get all friends of choosen users"""
liste = [] liste = []