Skip to content

Commit

Permalink
Merge pull request #110 from paulosgf/testupdate
Browse files Browse the repository at this point in the history
Enhancement #3
  • Loading branch information
paulosgf authored May 27, 2022
2 parents 2cd148c + 0198c7e commit ac3186c
Showing 15 changed files with 102 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/honeybot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .manage import main

main()
main()
4 changes: 2 additions & 2 deletions src/honeybot/api/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import importlib.util
# import os
# import importlib.util


def gen_pluginsinfo():
8 changes: 5 additions & 3 deletions src/honeybot/api/init.py
Original file line number Diff line number Diff line change
@@ -4,12 +4,14 @@

CURRENT_DIR = Path(__file__).parent
MAIN_DIR = CURRENT_DIR.parent
PLUGINS_DIR = os.path.join(MAIN_DIR, 'plugins')
SETTINGS_DIR = os.path.join(MAIN_DIR, 'settings')
PLUGINS_DIR = os.path.join(MAIN_DIR, 'plugins')
SETTINGS_DIR = os.path.join(MAIN_DIR, 'settings')


def init(info):
try:
shutil.copytree(PLUGINS_DIR, os.path.join(info['cwd'], 'plugins'))
shutil.copytree(SETTINGS_DIR, os.path.join(info['cwd'], 'settings'))
except FileExistsError:
pass
print('created!')
print('created!')
25 changes: 16 additions & 9 deletions src/honeybot/api/main.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import sys
import time
import os
from pathlib import Path
# from pathlib import Path

try:
from honeybot.api import commands
@@ -19,7 +19,6 @@
raise e



memory_reader = configparser.ConfigParser()

plugins = []
@@ -35,7 +34,9 @@
class Bot_core(object):
def __init__(self, info, password=""):
connect_config = configparser.ConfigParser()
connect_config.read(os.path.join(info['settings_path'], 'CONNECT.conf'))
connect_config.read(os.path.join(
info['settings_path'],
'CONNECT.conf'))
self.settings_path = info['settings_path']
self.root_path = info['cwd']
self.server_url = connect_config["INFO"]["server_url"]
@@ -44,7 +45,9 @@ def __init__(self, info, password=""):
self.owners = configfile_to_list(info['settings_path'], "OWNERS")
self.password = password
self.friends = configfile_to_list(info['settings_path'], "FRIENDS")
self.autojoin_channels = configfile_to_list(info['settings_path'], "AUTOJOIN_CHANNELS")
self.autojoin_channels = configfile_to_list(
info['settings_path'],
"AUTOJOIN_CHANNELS")
self.required_modules = get_requirements()
self.time = time.time()

@@ -144,7 +147,7 @@ def load_plugins(self):
Examples:
TODO
"""

logger.info("Loading plugins...")

to_load = []
@@ -157,7 +160,8 @@ def load_plugins(self):
print("loading plugin:", folder)
try:
sys.path.append(self.root_path)
module = importlib.import_module("plugins.downloaded.{}.main".format(folder))
module = importlib.import_module(
"plugins.downloaded.{}.main".format(folder))
obj = module
self.plugins.append(obj)
except ModuleNotFoundError as e:
@@ -166,7 +170,8 @@ def load_plugins(self):
for folder in self.core_plugins:
print("loading plugin:", folder)
try:
module = importlib.import_module("plugins.core.{}.main".format(folder))
module = importlib.import_module(
"plugins.core.{}.main".format(folder))
obj = module
self.plugins.append(obj)
except ModuleNotFoundError as e:
@@ -225,7 +230,8 @@ def pull(self):

if len(data) == 0:
try:
logger.critical(f"<must handle reconnection - {len(data)}==0>")
logger.critical(
f"<must handle reconnection - {len(data)}==0>")
sys.exit()
except Exception as e:
logger.info(e)
@@ -238,7 +244,8 @@ def pull(self):

def stay_alive(self, incoming):
if not incoming:
logger.critical("<must handle reconnection - incoming is not True>")
logger.critical(
"<must handle reconnection - incoming is not True>")
sys.exit()
parts = incoming.split(":")
if parts[0].strip().lower() == "ping":
3 changes: 3 additions & 0 deletions src/honeybot/api/memory.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from main import memory_reader


def add_value(memfile, section, key, value):
memory_reader.read("memory/{}.txt".format(memfile))
memory_reader[section][key] = value
6 changes: 3 additions & 3 deletions src/honeybot/api/print.py
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@
import os

ascii_message = """
_ _ _ _
_ __ _ _| || |___ _ _ ___ _ _| |__ ___| |_
_ _ _ _
_ __ _ _| || |___ _ _ ___ _ _| |__ ___| |_
| '_ \ || | __ / _ \ ' \/ -_) || | '_ \/ _ \ _|
| .__/\_, |_||_\___/_||_\___|\_, |_.__/\___/\__|
|_| |__/ |__/
|_| |__/ |__/
github.com/pyhoneybot/honeybot
~ IRC bot with awesome plugins
"""
3 changes: 2 additions & 1 deletion src/honeybot/api/utils.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

_package_name = 'honeybot'


def prevent_none(x):
return x if x else ""

@@ -17,4 +18,4 @@ def configfile_to_list(settings_path, filename):

def get_requirements():
package = pkg_resources.working_set.by_key[_package_name]
return [str(r) for r in package.requires()]
return [str(r) for r in package.requires()]
15 changes: 12 additions & 3 deletions src/honeybot/gui_manager.py
Original file line number Diff line number Diff line change
@@ -84,7 +84,8 @@ def exit_app(self):
"MainLabel",
Label(
window,
text="Select the plugins you wish to load and add them to the config file",
text="Select the plugins you wish to \
load and add them to the config file",
),
]
],
@@ -94,8 +95,16 @@ def exit_app(self):
[["tt", Text(window, width=80)]],
[["label3", Label(window, text="Don't forget to hit save!")]],
[
["saveBtn", Button(window, text="Save File", width=10, command=saveFile)],
["reorderBtn", Button(window, text="Reorder", width=10, command=reorder)],
["saveBtn", Button(
window,
text="Save File",
width=10,
command=saveFile)],
["reorderBtn", Button(
window,
text="Reorder",
width=10,
command=reorder)],
],
[
["runBot", Button(window, text="RUN", width=10, command=run_bot)],
11 changes: 7 additions & 4 deletions src/honeybot/manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python2
import logging
import sys
import argparse
@@ -10,7 +9,7 @@
from honeybot.api.print import print_connect_settings
from honeybot.api.print import print_honeybot_manifesto
from honeybot.api.generate import gen_pluginsinfo
from honeybot.api.init import init
from honeybot.api.init import init
except Exception as e:
print(e)

@@ -21,10 +20,13 @@
datefmt="%Y-%m-%d %H:%M:%S",
)


def main():
parser = argparse.ArgumentParser()

parser.add_argument("botsetting", choices=["run", "gen_pluginsinfo", "init"])
parser.add_argument(
"botsetting",
choices=["run", "gen_pluginsinfo", "init"])

args = parser.parse_args()

@@ -35,7 +37,7 @@ def main():

print_honeybot_manifesto(info)
if args.botsetting == "run":

print_connect_settings(info)
try:
x = Bot_core(info)
@@ -50,5 +52,6 @@ def main():
elif args.botsetting == "init":
init(info)


if __name__ == '__main__':
main()
8 changes: 6 additions & 2 deletions src/honeybot/plugins/core/uptime/main.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,9 @@ def __init__(self):
pass

def __convert_time(start_time):
""""Calculates how long the bot has been running then formats the output"""
"""
Calculates how long the bot has been running then formats the output
"""
current_time = time.time()
uptime = current_time - start_time
hrs = int(uptime / 3600)
@@ -38,6 +40,8 @@ def run(self, incoming, methods, info, bot_info):
try:
if info["command"] == "PRIVMSG" and info["args"][1] == ".uptime":
start_time = bot_info["time"]
methods["send"](info["address"], Plugin.__convert_time(start_time))
methods["send"](
info["address"],
Plugin.__convert_time(start_time))
except Exception as e:
print("Plugin Error: ", e)
6 changes: 3 additions & 3 deletions src/honeybot/settings/PLUGINS.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
help
age
caesar_cipher
greet
book_of_day
cointoss
quote
44 changes: 20 additions & 24 deletions src/honeybot/store.py
Original file line number Diff line number Diff line change
@@ -5,40 +5,36 @@
BASE_DIR = 'plugins/downloaded'
STORE_DIR = '../../honeybot-store'

plugins = {'plugins':[]}
plugins = {'plugins': []}
dirs = [d for d in os.listdir(BASE_DIR) if not d.startswith('__')]


def pinfo(folder, attrib):
try:
mod = importlib.import_module(
"plugins.downloaded.{}.info".format(folder)
)
"plugins.downloaded.{}.info".format(folder))
return getattr(mod, attrib)
except Exception as e:
if attrib == 'ORIGINAL_AUTHORS':
return []
else:
return ''

for d in dirs:
NAME = pinfo(d, 'NAME')
ABOUT = pinfo(d, 'ABOUT')
ORIGINAL_AUTHORS = pinfo(d, 'ORIGINAL_AUTHORS')
COMMANDS = pinfo(d, 'COMMANDS')
WEBSITE = pinfo(d, 'WEBSITE')
plugins['plugins'].append({
'NAME': NAME,
'ABOUT': ABOUT,
'ORIGINAL_AUTHORS': ORIGINAL_AUTHORS,
'COMMANDS': COMMANDS,
'WEBSITE': WEBSITE,
'FOLDER_NAME': d
})


print(plugins)

with open(os.path.join(STORE_DIR, 'plugins.json'), 'w+') as f:
json.dump(plugins, f, indent=4)

for d in dirs:
NAME = pinfo(d, 'NAME')
ABOUT = pinfo(d, 'ABOUT')
ORIGINAL_AUTHORS = pinfo(d, 'ORIGINAL_AUTHORS')
COMMANDS = pinfo(d, 'COMMANDS')
WEBSITE = pinfo(d, 'WEBSITE')
plugins['plugins'].append({
'NAME': NAME,
'ABOUT': ABOUT,
'ORIGINAL_AUTHORS': ORIGINAL_AUTHORS,
'COMMANDS': COMMANDS,
'WEBSITE': WEBSITE,
'FOLDER_NAME': d})

print(plugins)

with open(os.path.join(STORE_DIR, 'plugins.json'), 'w+') as f:
json.dump(plugins, f, indent=4)
8 changes: 6 additions & 2 deletions src/honeybot/test_core.py
Original file line number Diff line number Diff line change
@@ -56,10 +56,14 @@ def test_info_command(self):
self.assertEqual(bot.message_info(incoming)["command"], "PRIVMSG")

def test_info_address(self):
self.assertEqual(bot.message_info(incoming)["address"], "##bottestingmu")
self.assertEqual(
bot.message_info(incoming)["address"],
"##bottestingmu")

def test_info_args(self):
self.assertEqual(bot.message_info(incoming)["args"], ["##bottestingmu", "ef"])
self.assertEqual(
bot.message_info(incoming)["args"],
["##bottestingmu", "ef"])


"""
13 changes: 8 additions & 5 deletions src/honeybot/test_legacy_core.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@
from main import Bot_core as Bot

"""
':appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200 PRIVMSG ##bottestingmu :ef'
':appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200
PRIVMSG ##bottestingmu :ef'
{
'prefix': 'appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200',
'command': 'PRIVMSG',
@@ -15,7 +16,8 @@
config.read("settings/CONNECT.conf")

# incoming
incoming = ":appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200 PRIVMSG ##bottestingmu :ef"
incoming = ":appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200 \
PRIVMSG ##bottestingmu :ef"
bot = Bot()


@@ -40,7 +42,8 @@ def test_port(self):
def test_info_prefix(self):
self.assertEqual(
bot.info(incoming)["prefix"],
"appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/ip.200.200.22.200",
"appinv!c5e342c5@gateway/web/cgi-irc/kiwiirc.com/\
ip.200.200.22.200",
)

def test_info_command(self):
@@ -58,8 +61,8 @@ def test_info_args(self):

def test_set_nick_command(self):
self.assertEqual(
bot.set_nick_command(), "NICK {0}\r\n".format(config["INFO"]["name"])
)
bot.set_nick_command(),
"NICK {0}\r\n".format(config["INFO"]["name"]))

def test_present_command(self):
self.assertEqual(
Loading

0 comments on commit ac3186c

Please sign in to comment.