From 69763cca2594632f109f81834b3da0a72a61c94c Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sun, 2 Apr 2023 22:14:45 +0200 Subject: [PATCH] events --- matrix_pygmalion_bot/helpers.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/matrix_pygmalion_bot/helpers.py b/matrix_pygmalion_bot/helpers.py index cc4aded..8bfdcfc 100644 --- a/matrix_pygmalion_bot/helpers.py +++ b/matrix_pygmalion_bot/helpers.py @@ -15,11 +15,28 @@ class Event: def __str__(self): return str("Event starting at time {}".format(self.tick_start)) def loop(self, bot, tick): - if tick >= self.tick_start: - if tick < self.tick_stop: - self.execute(bot, tick) - elif (self.tick_stop == 0 or self.tick_stop == self.tick_start) and self.executed == 0: + if self.is_active(tick): + if self.is_oneshot(): + if self.executed == 0: + self.execute(bot, tick) + else: self.execute(bot, tick) + + def is_active(self, tick): + if tick >= self.tick_start and tick <= self.tick_stop: + return True + else: + return False + def is_oneshot(self): + if self.tick_stop == 0 or self.tick_stop == self.tick_start: + return True + else: + return False + def is_timespan(self): + if self.tick_stop > self.tick_start: + return True + else: + return False def execute(self, bot, tick): logger.info("event executed for " + bot.name + ". current tick: " + str(tick) + " event: " + str(self.command)) if self.command.startswith('printtime'):