Chatbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.4 KiB

2 years ago
import time
import logging
logger = logging.getLogger(__name__)
2 years ago
class Event:
2 years ago
def __init__(self, tick_start, tick_stop, chance, repeat, command):
self.tick_start = tick_start
self.tick_stop = tick_stop
2 years ago
self.chance = chance
2 years ago
self.repeat = repeat
2 years ago
self.command = command
2 years ago
self.executed = 0
def __str__(self):
2 years ago
return str("Event starting at time {}".format(self.tick_start))
def loop(self, bot, tick):
2 years ago
if self.is_active(tick):
if self.is_oneshot():
if self.executed == 0:
self.execute(bot, tick)
else:
2 years ago
self.execute(bot, tick)
2 years ago
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
2 years ago
def execute(self, bot, tick):
logger.info("event executed for " + bot.name + ". current tick: " + str(tick) + " event: " + str(self.command))
2 years ago
if self.command.startswith('printtime'):
2 years ago
print(time.time()//1000)
2 years ago
self.executed += 1