From cf91e904519e6eab2f17b5551290680069599521 Mon Sep 17 00:00:00 2001 From: Sina Mashek Date: Mon, 27 Nov 2017 07:10:40 +0200 Subject: [PATCH] Split plugin outout on newlines and ensure plugins folder exists --- pinhook/bot.py | 18 +++++++++++++----- pinhook/plugin.py | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pinhook/bot.py b/pinhook/bot.py index 12a1157..618a9a2 100644 --- a/pinhook/bot.py +++ b/pinhook/bot.py @@ -1,11 +1,14 @@ import imp import os import ssl +import time import irc.bot + irc.client.ServerConnection.buffer_class.errors = 'replace' + class Message: def __init__(self, channel, nick, cmd, arg, botnick, ops): self.channel = channel @@ -45,7 +48,10 @@ class Bot(irc.bot.SingleServerIRCBot): setattr(self, a, kwarguments[a]) def load_plugins(self): - # load all plugins + # ensure plugin folder exists + if not os.path.exists(self.plugin_dir): + os.makedirs(self.plugin_dir) + # load all plugins plugins = [] for m in os.listdir(self.plugin_dir): if m.endswith('.py'): @@ -114,8 +120,10 @@ class Bot(irc.bot.SingleServerIRCBot): print(e) if output: - if output.msg_type == 'message': - c.privmsg(chan, output.msg) - elif output.msg_type == 'action': - c.action(chan, output.msg) + for msg in output.msg: + if output.msg_type == 'message': + c.privmsg(chan, msg) + elif output.msg_type == 'action': + c.action(chan, msg) + time.sleep(.5) diff --git a/pinhook/plugin.py b/pinhook/plugin.py index d7fb356..d8be1ce 100644 --- a/pinhook/plugin.py +++ b/pinhook/plugin.py @@ -3,7 +3,10 @@ cmds = [] class Output: def __init__(self, msg_type, msg): self.msg_type = msg_type - self.msg = msg + self.msg = self.sanitize(msg) + + def sanitize(self, msg): + return msg.splitlines() def action(msg):