Browse Source

events

master
Hendrik Langer 2 years ago
parent
commit
69763cca25
  1. 25
      matrix_pygmalion_bot/helpers.py

25
matrix_pygmalion_bot/helpers.py

@ -15,11 +15,28 @@ class Event:
def __str__(self): def __str__(self):
return str("Event starting at time {}".format(self.tick_start)) return str("Event starting at time {}".format(self.tick_start))
def loop(self, bot, tick): def loop(self, bot, tick):
if tick >= self.tick_start: if self.is_active(tick):
if tick < self.tick_stop: if self.is_oneshot():
self.execute(bot, tick) if self.executed == 0:
elif (self.tick_stop == 0 or self.tick_stop == self.tick_start) and self.executed == 0: self.execute(bot, tick)
else:
self.execute(bot, tick) 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): def execute(self, bot, tick):
logger.info("event executed for " + bot.name + ". current tick: " + str(tick) + " event: " + str(self.command)) logger.info("event executed for " + bot.name + ". current tick: " + str(tick) + " event: " + str(self.command))
if self.command.startswith('printtime'): if self.command.startswith('printtime'):

Loading…
Cancel
Save