Merge pull request #5 from SinaCutie/patch-fix-plugin
Split plugin output on newlines and ensure plugins folder exists
This commit is contained in:
		
						commit
						e2187c882f
					
				| @ -1,11 +1,14 @@ | |||||||
| import imp | import imp | ||||||
| import os | import os | ||||||
| import ssl | import ssl | ||||||
|  | import time | ||||||
| 
 | 
 | ||||||
| import irc.bot | import irc.bot | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| irc.client.ServerConnection.buffer_class.errors = 'replace' | irc.client.ServerConnection.buffer_class.errors = 'replace' | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| class Message: | class Message: | ||||||
|     def __init__(self, channel, nick, cmd, arg, botnick, ops): |     def __init__(self, channel, nick, cmd, arg, botnick, ops): | ||||||
|         self.channel = channel |         self.channel = channel | ||||||
| @ -45,6 +48,9 @@ class Bot(irc.bot.SingleServerIRCBot): | |||||||
|                 setattr(self, a, kwarguments[a]) |                 setattr(self, a, kwarguments[a]) | ||||||
| 
 | 
 | ||||||
|     def load_plugins(self): |     def load_plugins(self): | ||||||
|  |         # ensure plugin folder exists | ||||||
|  |         if not os.path.exists(self.plugin_dir): | ||||||
|  |             os.makedirs(self.plugin_dir) | ||||||
|         # load all plugins |         # load all plugins | ||||||
|         plugins = [] |         plugins = [] | ||||||
|         for m in os.listdir(self.plugin_dir): |         for m in os.listdir(self.plugin_dir): | ||||||
| @ -114,8 +120,10 @@ class Bot(irc.bot.SingleServerIRCBot): | |||||||
|                 print(e) |                 print(e) | ||||||
| 
 | 
 | ||||||
|         if output: |         if output: | ||||||
|  |             for msg in output.msg: | ||||||
|                 if output.msg_type == 'message': |                 if output.msg_type == 'message': | ||||||
|                 c.privmsg(chan, output.msg) |                     c.privmsg(chan, msg) | ||||||
|                 elif output.msg_type == 'action': |                 elif output.msg_type == 'action': | ||||||
|                 c.action(chan, output.msg) |                     c.action(chan, msg) | ||||||
|  |                 time.sleep(.5) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,10 @@ cmds = [] | |||||||
| class Output: | class Output: | ||||||
|     def __init__(self, msg_type, msg): |     def __init__(self, msg_type, msg): | ||||||
|         self.msg_type = msg_type |         self.msg_type = msg_type | ||||||
|         self.msg = msg |         self.msg = self.sanitize(msg) | ||||||
|  | 
 | ||||||
|  |     def sanitize(self, msg): | ||||||
|  |         return msg.splitlines() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def action(msg): | def action(msg): | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user