Skip to content

Commit

Permalink
Merge pull request #198 from pyhoneybot/fix-output
Browse files Browse the repository at this point in the history
chore: improve output messages
  • Loading branch information
Abdur-rahmaanJ authored Jul 3, 2023
2 parents bd48d8c + f8c5e88 commit 35927e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
40 changes: 23 additions & 17 deletions src/honeybot/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from honeybot.api import commands, memory
from honeybot.api.utils import configfile_to_list, get_requirements, prevent_none

from honeybot.api import print as output

plugins = []

Expand Down Expand Up @@ -83,7 +83,8 @@ def message_info(self, s):
"user": prevent_none(user),
}
except Exception as e:
logger.error(e)
# logger.error(e)
pass

def bot_info(self):
return {
Expand Down Expand Up @@ -133,10 +134,10 @@ def is_valid_plug_name(self, name):
"""

def print_running_infos(self):
print("Run infos:")
print(output.status('i')+ " Run infos:")
for key in self.info:
print(key, self.info[key])
print("-" * 3)
print(output.tab()+' '+key, self.info[key])
print(output.line())

def load_plugins_from_folder(self, category_folder, from_conf=None, from_dir=None):
if from_dir is not None:
Expand All @@ -148,9 +149,9 @@ def load_plugins_from_folder(self, category_folder, from_conf=None, from_dir=Non
to_load = f.read().split("\n")
to_load = list(filter(lambda x: x != "", to_load))

print("Loading", category_folder)
print(output.status('i')+ " Loading from", category_folder)
for folder in to_load:
print("loading plugin:", folder)
print(output.tab(), "loading plugin:", folder)
try:
sys.path.append(self.root_path)
module = importlib.import_module(f"plugins.{category_folder}.{folder}.main")
Expand Down Expand Up @@ -178,7 +179,8 @@ def load_plugins_from_folder(self, category_folder, from_conf=None, from_dir=Non
[sys.executable, "-m", "pip", "install", *install_requires]
)
except Exception as e:
logger.debug(e)
# logger.debug(e)
pass

def load_plugins(self):
"""
Expand All @@ -191,15 +193,15 @@ def load_plugins(self):
TODO
"""

logger.info("Loading plugins...")
print(output.status('i')+ " Loading plugins...")

conf_path = os.path.join(self.settings_path, "PLUGINS.conf")
dir_path = os.path.join(self.info["plugins_path"], "core")
self.load_plugins_from_folder("downloaded", from_conf=conf_path)
self.load_plugins_from_folder("core", from_dir=dir_path)

logger.info("Loaded plugins")
print("---")
print(output.status('x')+ " Loaded plugins")
print(output.line())

def run_plugins(self, incoming):
"""
Expand Down Expand Up @@ -239,8 +241,10 @@ def greet(self):
self.send(commands.present(self.name))
for channel in self.autojoin_channels:
self.send(commands.join_channel(channel))
print(output.status('x'), 'Joined channels:', ', '.join(self.autojoin_channels))

def pull(self):
print(output.status('i'), 'Listening to incoming messages')
while self.is_listen_on:
try:
data = self.irc.recv(2048).decode("UTF-8", errors="replace")
Expand All @@ -252,12 +256,14 @@ def pull(self):
self.is_listen_on = False
self.quit()
except Exception as e:
logger.error(e)
logger.debug("there was an error")
logger.debug(data)
logger.debug("!!")
logger.debug(line)
logger.debug("-" * 50)
# logger.error(e)
# print(e)
# logger.debug("there was an error")
# logger.debug(data)
# logger.debug("!!")
# logger.debug(line)
# logger.debug("-" * 50)
pass

def quit(self):
self.send(commands.quit())
Expand Down
28 changes: 23 additions & 5 deletions src/honeybot/api/print.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import configparser
import os
import sys

ascii_message = r"""
_ _ _ _
Expand All @@ -12,20 +13,37 @@
"""


def tab(s=3):
return ' ' * s

def line(n=3):
return '-'*3


def status(symbol_type):
if symbol_type in '!i>x':
return '[' + symbol_type + ']'
else:
raise Exception('Undefined symbol type')

def print_honeybot_manifesto(info):
print(ascii_message)


def print_connect_settings(info):
settings_path = os.path.join(info["settings_path"], "CONNECT.conf")
if not os.path.exists(settings_path):
print('Could not find CONNECT.conf in', info["settings_path"])
print('Make sure you are in the right folder')
sys.exit()
connect_config = configparser.ConfigParser()
connect_config.read(settings_path)
server_url = connect_config["INFO"]["server_url"]
port = connect_config["INFO"]["port"]
name = connect_config["INFO"]["name"]

print("connecting with settings:")
print("server url:", server_url)
print("port:", port)
print("username:", name)
print("-" * 3)
print(status('i')+" connecting with settings:")
print(tab()+" server url:", server_url)
print(tab()+" port:", port)
print(tab()+" username:", name)
print(line())

0 comments on commit 35927e0

Please sign in to comment.