@utils.hook doesn't work outside of modules!
This commit is contained in:
parent
fcedc434f2
commit
fa3fc7e3fb
1 changed files with 8 additions and 5 deletions
|
@ -27,6 +27,7 @@ class Bot(object):
|
||||||
self.add_socket(Socket.Socket(self._trigger_server, lambda _, s: None))
|
self.add_socket(Socket.Socket(self._trigger_server, lambda _, s: None))
|
||||||
|
|
||||||
self._trigger_functions = []
|
self._trigger_functions = []
|
||||||
|
self.events.hook("timer.reconnect", self._timed_reconnect)
|
||||||
|
|
||||||
def trigger(self, func: typing.Callable[[], typing.Any]=None):
|
def trigger(self, func: typing.Callable[[], typing.Any]=None):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
|
@ -127,13 +128,15 @@ class Bot(object):
|
||||||
pass
|
pass
|
||||||
del self.servers[server.fileno()]
|
del self.servers[server.fileno()]
|
||||||
|
|
||||||
@utils.hook("timer.reconnect")
|
def _timed_reconnect(self, event: EventManager.Event):
|
||||||
def reconnect(self, event: EventManager.Event):
|
if not self.reconnect(event["server_id"]):
|
||||||
server = self.add_server(event["server_id"], False)
|
event["timer"].redo()
|
||||||
|
def reconnect(self, server_id: int) -> bool:
|
||||||
|
server = self.add_server(server_id, False)
|
||||||
if self.connect(server):
|
if self.connect(server):
|
||||||
self.servers[server.fileno()] = server
|
self.servers[server.fileno()] = server
|
||||||
else:
|
return True
|
||||||
event["timer"].redo()
|
return False
|
||||||
|
|
||||||
def set_setting(self, setting: str, value: typing.Any):
|
def set_setting(self, setting: str, value: typing.Any):
|
||||||
self.database.bot_settings.set(setting, value)
|
self.database.bot_settings.set(setting, value)
|
||||||
|
|
Loading…
Reference in a new issue