From a77a985d5d270b8c09fb3bc7a008d6262d29b5a2 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 7 Oct 2018 08:01:54 +0100 Subject: [PATCH] Optionally take a function in IRCBot.trigger, a function to be called on the main thread --- src/IRCBot.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/IRCBot.py b/src/IRCBot.py index 629f021c..b90825a7 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -26,7 +26,11 @@ class Bot(object): self._trigger_server, self._trigger_client = socket.socketpair() self.add_socket(Socket.Socket(self._trigger_server, lambda _, s: None)) - def trigger(self): + self._trigger_functions = [] + + def trigger(self, func=None): + if func: + self._trigger_functions.append(func) self._trigger_client.send(b"TRIGGER") def add_server(self, server_id, connect=True): @@ -143,6 +147,9 @@ class Bot(object): self.timers.call() self.cache.expire() + for func in self._trigger_functions: + func() + for fd, event in events: sock = None irc = False