Python:
class TrgParrot:
# simulates a parrot chirp trigger mechanism
# as such this trigger is off at night
# in essence this trigger says: I am here, are you here? good.
def __init__(self, limit: int):
super().__init__()
temp_lim: int = 3
if limit > 0:
temp_lim = limit
self._tolerance: TrgTolerance = TrgTolerance(temp_lim)
self._idle_tolerance: TrgTolerance = TrgTolerance(temp_lim)
self._silencer: Responder = Responder("ok", "okay", "stop", "shut up", "quiet")
def trigger(self, standBy: bool, ear: str) -> bool:
"""excited chirp user is here!"""
# if TimeUtils.isNight():
# # is it night? I will be quite
# return False
# you want the bird to shut up?
if self._silencer.responsesContainsStr(ear):
self._tolerance.disable()
return False
# no input or output for a while?
if standBy:
# I will chirp!
self._tolerance.reset()
return True
# we are handshaking?
if not ear == "":
# I will reply chirp till it grows old for me (a set amount of times till reset)
if self._tolerance.trigger():
return True
return False
def idle_trigger(self, standBy: bool, ear: str) -> bool:
"""standby chirp tries to get user's attention"""
# if TimeUtils.isNight():
# # is it night? I will be quite
# return False
if len(ear) > 0:
self._idle_tolerance.disable()
return False
# you want the bird to shut up?
if self._silencer.responsesContainsStr(ear):
self._idle_tolerance.disable()
return False
# no input or output for a while?
if standBy:
# I will chirp!
self._idle_tolerance.reset()
return True
if self._idle_tolerance.trigger():
return True
return False