From 539bebafea572a74f286bd406556c1ef39781714 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 6 Jun 2019 20:26:05 +0100 Subject: [PATCH 1/6] select.epoll -> select.poll --- src/IRCBot.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/IRCBot.py b/src/IRCBot.py index f5407e59..9c563f71 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -26,7 +26,7 @@ class Bot(object): self.start_time = time.time() self.lock = threading.Lock() self.running = True - self.poll = select.epoll() + self.poll = select.poll() self.servers = {} self.other_sockets = {} @@ -97,7 +97,7 @@ class Bot(object): def add_socket(self, sock: socket.socket): self.other_sockets[sock.fileno()] = sock - self.poll.register(sock.fileno(), select.EPOLLIN) + self.poll.register(sock.fileno(), select.POLLIN) def remove_socket(self, sock: socket.socket): del self.other_sockets[sock.fileno()] @@ -123,7 +123,7 @@ class Bot(object): [str(server), str(e)]) return False self.servers[server.fileno()] = server - self.poll.register(server.fileno(), select.EPOLLOUT) + self.poll.register(server.fileno(), select.POLLOUT) return True def next_send(self) -> typing.Optional[float]: @@ -163,12 +163,12 @@ class Bot(object): return min([timeout for timeout in timeouts if not timeout == None]) def register_read(self, server: IRCServer.Server): - self.poll.modify(server.fileno(), select.EPOLLIN) + self.poll.modify(server.fileno(), select.POLLIN) def register_write(self, server: IRCServer.Server): - self.poll.modify(server.fileno(), select.EPOLLOUT) + self.poll.modify(server.fileno(), select.POLLOUT) def register_both(self, server: IRCServer.Server): self.poll.modify(server.fileno(), - select.EPOLLIN|select.EPOLLOUT) + select.POLLIN|select.POLLOUT) def disconnect(self, server: IRCServer.Server): try: @@ -238,7 +238,7 @@ class Bot(object): sock = self.other_sockets[fd] if sock: - if event & select.EPOLLIN: + if event & select.POLLIN: data = sock.read() if data == None: sock.disconnect() @@ -246,7 +246,7 @@ class Bot(object): for piece in data: sock.parse_data(piece) - elif event & select.EPOLLOUT: + elif event & select.POLLOUT: try: sock._send() except: @@ -256,8 +256,8 @@ class Bot(object): if sock.fileno() in self.servers: self.register_read(sock) - elif event & select.EPULLHUP: - self.log.warn("Recieved EPOLLHUP for %s", [str(sock)]) + elif event & select.POLLHUP: + self.log.warn("Recieved POLLHUP for %s", [str(sock)]) sock.disconnect() for server in list(self.servers.values()): From c89bd74a4807626f238405a90fff19a2bffec0e9 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 6 Jun 2019 23:45:33 +0100 Subject: [PATCH 2/6] select.poll, as opposed to select.epoll, uses milliseconds not seconds for timeout --- src/IRCBot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IRCBot.py b/src/IRCBot.py index 9c563f71..9d47b33e 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -160,7 +160,8 @@ class Bot(object): timeouts.append(self.next_ping()) timeouts.append(self.next_read_timeout()) timeouts.append(self.cache.next_expiration()) - return min([timeout for timeout in timeouts if not timeout == None]) + min_secs = min([timeout for timeout in timeouts if not timeout == None]) + return min_secs*1000 # return milliseconds def register_read(self, server: IRCServer.Server): self.poll.modify(server.fileno(), select.POLLIN) From 219906962911d4cb525f8dec420f346d503ea1be Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 7 Jun 2019 11:29:11 +0100 Subject: [PATCH 3/6] Better formating for pull_request ready_for_review event --- modules/github/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/github/__init__.py b/modules/github/__init__.py index d76762d3..b38c652c 100644 --- a/modules/github/__init__.py +++ b/modules/github/__init__.py @@ -584,6 +584,8 @@ class Module(ModuleManager.BaseModule): else: action_desc = "%s %s" % ( utils.irc.color("closed", COLOR_NEGATIVE), number) + elif action == "ready_for_review": + action_desc = "marked %s ready for review" % number elif action == "synchronize": action_desc = "committed to %s" % number From bc4a6debb59034ab3d9a64cddda87f5f7ab434e5 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 7 Jun 2019 13:31:51 +0100 Subject: [PATCH 4/6] Use a deque for temp chathistory storage (src/IRCBuffer.py) --- src/IRCBuffer.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/IRCBuffer.py b/src/IRCBuffer.py index 1415fd48..dbfc9541 100644 --- a/src/IRCBuffer.py +++ b/src/IRCBuffer.py @@ -1,6 +1,8 @@ -import re, typing +import collections, re, typing from src import IRCBot, IRCServer, utils +MAX_LINES = 64 + class BufferLine(object): def __init__(self, sender: str, message: str, action: bool, tags: dict, from_self: bool, method: str): @@ -15,17 +17,14 @@ class Buffer(object): def __init__(self, bot: "IRCBot.Bot", server: "IRCServer.Server"): self.bot = bot self.server = server - self.lines = [] # type: typing.List[BufferLine] - self.max_lines = 64 + self._lines = collections.deque(maxlen=MAX_LINES) self._skip_next = False def _add_message(self, sender: str, message: str, action: bool, tags: dict, from_self: bool, method: str): if not self._skip_next: line = BufferLine(sender, message, action, tags, from_self, method) - self.lines.insert(0, line) - if len(self.lines) > self.max_lines: - self.lines.pop() + self._lines.appendleft(line) self._skip_next = False def add_message(self, sender: str, message: str, action: bool, tags: dict, from_self: bool=False): @@ -36,7 +35,7 @@ class Buffer(object): def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]: from_self = kwargs.get("from_self", True) - for line in self.lines: + for line in self._lines: if line.from_self and not from_self: continue return line @@ -47,7 +46,7 @@ class Buffer(object): for_user = kwargs.get("for_user", "") for_user = self.server.irc_lower(for_user) if for_user else None not_pattern = kwargs.get("not_pattern", None) - for line in self.lines: + for line in self._lines: if line.from_self and not from_self: continue elif re.search(pattern, line.message): @@ -61,7 +60,7 @@ class Buffer(object): def find_from(self, nickname: str) -> typing.Optional[BufferLine]: nickname_lower = self.server.irc_lower(nickname) - for line in self.lines: + for line in self._lines: if (not line.from_self and self.server.irc_lower(line.sender) == nickname_lower): return line From ea924df88367f7b5bda1ed4696da23b00a4258a3 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 7 Jun 2019 13:34:30 +0100 Subject: [PATCH 5/6] typehint for IRCBuffer._lines --- src/IRCBuffer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IRCBuffer.py b/src/IRCBuffer.py index dbfc9541..3dccb07b 100644 --- a/src/IRCBuffer.py +++ b/src/IRCBuffer.py @@ -17,7 +17,8 @@ class Buffer(object): def __init__(self, bot: "IRCBot.Bot", server: "IRCServer.Server"): self.bot = bot self.server = server - self._lines = collections.deque(maxlen=MAX_LINES) + self._lines = collections.deque(maxlen=MAX_LINES + ) # type: typing.Deque[BufferLine] self._skip_next = False def _add_message(self, sender: str, message: str, action: bool, tags: dict, From accd7a89417214889855f187b2a0da53ac70ed7d Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 7 Jun 2019 13:35:20 +0100 Subject: [PATCH 6/6] Logging._log()'s `params` arg should be typing.Optiona[] --- src/Logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Logging.py b/src/Logging.py index 5c3d873c..bb7a4dbe 100644 --- a/src/Logging.py +++ b/src/Logging.py @@ -61,5 +61,6 @@ class Log(object): self._log(message, params, logging.ERROR, kwargs) def critical(self, message: str, params: typing.List=None, **kwargs): self._log(message, params, logging.CRITICAL, kwargs) - def _log(self, message: str, params: typing.List, level: int, kwargs: dict): + def _log(self, message: str, params: typing.Optional[typing.List], + level: int, kwargs: dict): self.logger.log(level, message, *(params or []), **kwargs)