def switch_to(self, stat_tuple, force=True): new_stat, new_msg = stat_tuple if new_stat not in STAT_TABLE: return if self.status == new_stat: if force and self.status in (STAT_ON, STAT_AFK): engine.notify_status_all(is_afk=(self.status == STAT_AFK)) return if new_stat != STAT_OFF: self.turn_on() if new_stat == STAT_AFK: if self.status == STAT_ON: engine.notify_status_all(is_afk=True) else: engine.helloall(is_afk=True) elif new_stat == STAT_ON: if self.status == STAT_AFK: engine.notify_status_all(is_afk=False) else: engine.helloall() elif new_stat == STAT_INVISIBLE: if self.status != STAT_OFF: engine.bye() else: engine.helloall(is_secret=True) engine.bye() elif new_stat == STAT_OFF: self.turn_off() self.status, self.msg = new_stat, new_msg
def turn_off(self): if self.status == STAT_OFF: return if self.status != STAT_INVISIBLE: try: engine.bye() except: pass self.status = STAT_OFF engine.stop_server() upload_manager.stop_daemon()