diff --git a/src/honeybot/api/main.py b/src/honeybot/api/main.py index 45e0ab5..323cdbd 100644 --- a/src/honeybot/api/main.py +++ b/src/honeybot/api/main.py @@ -10,11 +10,8 @@ import pkg_resources -try: - from honeybot.api import commands, memory - from honeybot.api.utils import configfile_to_list, get_requirements, prevent_none -except Exception as e: - raise e +from honeybot.api import commands, memory +from honeybot.api.utils import configfile_to_list, get_requirements, prevent_none plugins = [] @@ -27,7 +24,7 @@ """ -class Bot_core: +class BotCore: def __init__(self, info, password=""): self.info = info connect_config = configparser.ConfigParser() @@ -45,7 +42,7 @@ def __init__(self, info, password=""): self.time = time.time() self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.isListenOn = 1 + self.is_listen_on = 1 dom = self.server_url.split(".") self.domain = ".".join(dom[-2:]) self.sp_command = "hbot" @@ -126,7 +123,7 @@ def join(self, channel): """ def is_valid_plug_name(self, name): - if (name.startswith("__")) or (name == ""): + if name.startswith("__") or name == "": return False return True @@ -142,7 +139,6 @@ def print_running_infos(self): print("-" * 3) def load_plugins_from_folder(self, category_folder, from_conf=None, from_dir=None): - if from_dir is not None: to_load = [f for f in os.listdir(from_dir) if self.is_valid_plug_name(f)] elif from_conf is not None: @@ -245,28 +241,31 @@ def greet(self): self.send(commands.join_channel(channel)) def pull(self): - while self.isListenOn: + while self.is_listen_on: try: - data = self.irc.recv(2048) - raw_msg = data.decode("UTF-8") - msg = raw_msg.strip("\n\r") - self.stay_alive(msg) - self.core_commands_parse(msg) - logger.info(msg) - - if len(data) == 0: - try: - logger.critical(f"") - sys.exit() - except Exception as e: - logger.info(e) + data = self.irc.recv(2048).decode("UTF-8", errors="replace") + for line in data.split("\r\n"): + if line != "": + self.core_commands_parse(line) + + except KeyboardInterrupt: + self.is_listen_on = False + self.quit() except Exception as e: - logger.info(e) + logger.error(e) + logger.debug("there was an error") + logger.debug(data) + logger.debug("!!") + logger.debug(line) + logger.debug("-" * 50) + + def quit(self): + self.send(commands.quit()) + self.is_listen_on = False """ ONGOING REQUIREMENT/S """ - def stay_alive(self, incoming): if not incoming: logger.critical("")