patch dd182f24b1eb76b357ab4ab84363ca55669f7b97
Author: E. Bosch <presidev@AT@gmail.com>
Date: Thu Jun 22 21:57:16 CEST 2023
* Move parse_command() to a new class, the code will be reused for the future
exclam module
diff -rN -u old-irgramd/service.py new-irgramd/service.py
--- old-irgramd/service.py 2024-11-22 16:27:59.572151673 +0100
+++ new-irgramd/service.py 2024-11-22 16:27:59.572151673 +0100
@@ -6,10 +6,10 @@
# Use of this source code is governed by a MIT style license that
# can be found in the LICENSE file included in this project.
-from utils import compact_date
+from utils import compact_date, command
from telethon import utils as tgutils
-class service:
+class service(command):
def __init__(self, settings, telegram):
self.commands = \
{ # Command Handler Arguments Min Max
@@ -25,23 +25,6 @@
self.irc = telegram.irc
self.tmp_ircnick = None
- async def parse_command(self, line, nick):
-
- words = line.split()
- command = words.pop(0).lower()
- self.tmp_ircnick = nick
- if command in self.commands.keys():
- handler, min_args, max_args = self.commands[command]
- num_words = len(words)
- if num_words < min_args or num_words > max_args:
- reply = ('Wrong number of arguments',)
- else:
- reply = await handler(*words)
- else:
- reply = ('Unknown command',)
-
- return reply
-
async def handle_command_code(self, code=None, help=None):
if not help:
if self.ask_code:
diff -rN -u old-irgramd/utils.py new-irgramd/utils.py
--- old-irgramd/utils.py 2024-11-22 16:27:59.572151673 +0100
+++ new-irgramd/utils.py 2024-11-22 16:27:59.576151666 +0100
@@ -21,6 +21,23 @@
# Utilities
+class command:
+ async def parse_command(self, line, nick):
+ words = line.split()
+ command = words.pop(0).lower()
+ self.tmp_ircnick = nick
+ if command in self.commands.keys():
+ handler, min_args, max_args = self.commands[command]
+ num_words = len(words)
+ if num_words < min_args or num_words > max_args:
+ reply = ('Wrong number of arguments',)
+ else:
+ reply = await handler(*words)
+ else:
+ reply = ('Unknown command',)
+
+ return reply
+
def chunks(iterable, n, fillvalue=None):
''' Return iterable consisting of a sequence of n-length chunks '''
args = [iter(iterable)] * n