Skip to content

Commit

Permalink
Split plugin outout on newlines and ensure plugins folder exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Sina Mashek committed Nov 27, 2017
1 parent 6e47d13 commit cf91e90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions pinhook/bot.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,7 +48,10 @@ def set_kwargs(self, **kwargs):
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'):
Expand Down Expand Up @@ -114,8 +120,10 @@ def process_command(self, c, e, text):
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)

5 changes: 4 additions & 1 deletion pinhook/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
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):
Expand Down

0 comments on commit cf91e90

Please sign in to comment.