def online(self, data): if self.state == self.STATE_OFFLINE: if self.state_last_changed and tools.tz_now() - self.state_last_changed < self.restart_threshold: #self.bot.send_message("Continuing") self.log.info("Detected online transition, continuing") else: #self.bot.send_message("New stream") self.started = dateutil.parser.parse(data['stream']['created_at']) self.log.info("Detected online transition, starting new") self.state = self.STATE_ONLINE self.state_last_changed = tools.tz_now()
def handle_message(self, data, user, msg): msg = tools.strip_name(msg) args = msg.split() if args[0] == "!uptime": if self.state == self.STATE_ONLINE: uptime = tools.tz_now() - self.started msg = "Up for: " else: uptime = self.state_last_changed - self.started msg = "Was up for: " total_seconds = uptime.total_seconds() total_minutes = floor(total_seconds / 60) hours = floor(total_minutes / 60) minutes = total_minutes - 60*hours self.bot.send_message(msg + str(hours) + " h, " + str(minutes) + " min")
def offline(self, data): if self.state == self.STATE_ONLINE: #self.bot.send_message("Stream ended") self.state = self.STATE_OFFLINE self.state_last_changed = tools.tz_now() self.log.info("Detected offline transition")