Commands and listeners work properly.
This commit is contained in:
		
							parent
							
								
									ce2a9cf125
								
							
						
					
					
						commit
						3fbc4e150f
					
				@ -25,6 +25,7 @@ class Message:
 | 
				
			|||||||
        if not (cmd or text):
 | 
					        if not (cmd or text):
 | 
				
			||||||
            print('Please pass Message a command or text!')
 | 
					            print('Please pass Message a command or text!')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Bot(irc.bot.SingleServerIRCBot):
 | 
					class Bot(irc.bot.SingleServerIRCBot):
 | 
				
			||||||
    def __init__(self, channels, nickname, server, **kwargs):
 | 
					    def __init__(self, channels, nickname, server, **kwargs):
 | 
				
			||||||
        self.set_kwargs(**kwargs)
 | 
					        self.set_kwargs(**kwargs)
 | 
				
			||||||
@ -84,37 +85,18 @@ class Bot(irc.bot.SingleServerIRCBot):
 | 
				
			|||||||
            c.join(channel)
 | 
					            c.join(channel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_pubmsg(self, c, e):
 | 
					    def on_pubmsg(self, c, e):
 | 
				
			||||||
        self.process_message(c, e)
 | 
					        self.process_command(c, e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_privmsg(self, c, e):
 | 
					    def on_privmsg(self, c, e):
 | 
				
			||||||
        self.process_message(c, e)
 | 
					        self.process_command(c, e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def process_message(self, c, e):
 | 
					    def process_command(self, c, e):
 | 
				
			||||||
        nick = e.source.nick
 | 
					        nick = e.source.nick
 | 
				
			||||||
 | 
					        text = e.arguments[0]
 | 
				
			||||||
        if e.target == self.bot_nick:
 | 
					        if e.target == self.bot_nick:
 | 
				
			||||||
            chan = nick
 | 
					            chan = nick
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            chan = e.target
 | 
					            chan = e.target
 | 
				
			||||||
        if e.arguments[0] in plugin.pinhook.plugin.cmds:
 | 
					 | 
				
			||||||
            self.process_command(c, e, nick, chan, e.arguments[0])
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            output = None
 | 
					 | 
				
			||||||
            for lstnr in self.lstnrs:
 | 
					 | 
				
			||||||
                try:
 | 
					 | 
				
			||||||
                    output = self.lstnrs[lstnr](Message(
 | 
					 | 
				
			||||||
                        channel=chan,
 | 
					 | 
				
			||||||
                        text=e.arguments[0],
 | 
					 | 
				
			||||||
                        nick_list=list(self.channels[chan].users()),
 | 
					 | 
				
			||||||
                        nick=nick,
 | 
					 | 
				
			||||||
                        botnick=self.bot_nick,
 | 
					 | 
				
			||||||
                        ops=self.ops
 | 
					 | 
				
			||||||
                    ))
 | 
					 | 
				
			||||||
                    if output:
 | 
					 | 
				
			||||||
                        self.process_output(c, chan, output)
 | 
					 | 
				
			||||||
                except Exception as e:
 | 
					 | 
				
			||||||
                    print(e)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def process_command(self, c, e, nick, chan, text):
 | 
					 | 
				
			||||||
        cmd = text.split(' ')[0]
 | 
					        cmd = text.split(' ')[0]
 | 
				
			||||||
        if len(text.split(' ')) > 1:
 | 
					        if len(text.split(' ')) > 1:
 | 
				
			||||||
            arg = ''.join([i + ' ' for i in text.split(' ')[1:]]).strip()
 | 
					            arg = ''.join([i + ' ' for i in text.split(' ')[1:]]).strip()
 | 
				
			||||||
@ -145,11 +127,25 @@ class Bot(irc.bot.SingleServerIRCBot):
 | 
				
			|||||||
                    botnick=self.bot_nick,
 | 
					                    botnick=self.bot_nick,
 | 
				
			||||||
                    ops=self.ops
 | 
					                    ops=self.ops
 | 
				
			||||||
                ))
 | 
					                ))
 | 
				
			||||||
            except Exception as e:
 | 
					 | 
				
			||||||
                print(e)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if output:
 | 
					                if output:
 | 
				
			||||||
                    self.process_output(c, chan, output)
 | 
					                    self.process_output(c, chan, output)
 | 
				
			||||||
 | 
					            except Exception as e:
 | 
				
			||||||
 | 
					                print(e)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            for lstnr in self.lstnrs:
 | 
				
			||||||
 | 
					                try:
 | 
				
			||||||
 | 
					                    output = self.lstnrs[lstnr](Message(
 | 
				
			||||||
 | 
					                        channel=chan,
 | 
				
			||||||
 | 
					                        text=text,
 | 
				
			||||||
 | 
					                        nick_list=list(self.channels[chan].users()),
 | 
				
			||||||
 | 
					                        nick=nick,
 | 
				
			||||||
 | 
					                        botnick=self.bot_nick,
 | 
				
			||||||
 | 
					                        ops=self.ops
 | 
				
			||||||
 | 
					                    ))
 | 
				
			||||||
 | 
					                    if output:
 | 
				
			||||||
 | 
					                        self.process_output(c, chan, output)
 | 
				
			||||||
 | 
					                except Exception as e:
 | 
				
			||||||
 | 
					                    print(e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def process_output(self, c, chan, output):
 | 
					    def process_output(self, c, chan, output):
 | 
				
			||||||
        for msg in output.msg:
 | 
					        for msg in output.msg:
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,10 @@ class Output:
 | 
				
			|||||||
        self.msg = self.sanitize(msg)
 | 
					        self.msg = self.sanitize(msg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def sanitize(self, msg):
 | 
					    def sanitize(self, msg):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            return msg.splitlines()
 | 
					            return msg.splitlines()
 | 
				
			||||||
 | 
					        except AttributeError:
 | 
				
			||||||
 | 
					            return msg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def action(msg):
 | 
					def action(msg):
 | 
				
			||||||
@ -22,9 +25,11 @@ def message(msg):
 | 
				
			|||||||
def add_plugin(command, func):
 | 
					def add_plugin(command, func):
 | 
				
			||||||
    cmds.append({'cmd': command, 'func': func})
 | 
					    cmds.append({'cmd': command, 'func': func})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def clear_plugins():
 | 
					def clear_plugins():
 | 
				
			||||||
    cmds.clear()
 | 
					    cmds.clear()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_listener(name, func):
 | 
					def add_listener(name, func):
 | 
				
			||||||
    lstnrs.append({'lstn': name, 'func': func})
 | 
					    lstnrs.append({'lstn': name, 'func': func})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user