Beispiel #1
0
 def __init__(self,
              server,
              nick,
              port,
              ident,
              realname,
              channel,
              debug=False):
     super().__init__(server, nick, port, ident, realname, debug=debug)
     self.silent = False
     self.chan = channel
     self.msg_formats = IRCFormats()
     self.wstbot = WstBot(self, debug=True)
Beispiel #2
0
class WstBotXMPP(WstXMPP):

    def __init__(self, *args):
        super().__init__(*args)

        self.msg_formats = XMPPFormats()
        self.wstbot = WstBot(self, debug=True)

    def muc_message(self, msg):
        # ignore messages from self
        if msg["mucnick"] == self.nick:
            return

        if "!users" in msg["body"]: # handle xmpp-specific commands
            self.send_user_list()
        else: # handle bot commands
            try:
                self.wstbot.handle_message(msg["from"].resource, msg["body"])
            except Exception as e:
                self.send_room_message("An error occurred during message handling. Exception: " + str(e))

    def muc_online(self, presence):
        room_name = self.room_local_name(presence["muc"]["room"])
        if presence["muc"]["nick"] == self.nick:
            self.wstbot.on_me_join(room_name)
        else:
            #self.wstbot.on_join(presence["muc"]["nick"])
            pass

    def send_user_list(self):
        users = self.plugin["xep_0045"].getRoster(self.room)
        user_list = ""
        for user in users:
            user_list += user + ", "
        if user_list[-2:] == ", ":
            user_list = user_list[:-2]
        self.send_room_message(user_list)

    def room_local_name(self, room_name):
        return room_name[:room_name.find("@")]
Beispiel #3
0
class WstBotIRC(wirc.wIRC):
    def __init__(self,
                 server,
                 nick,
                 port,
                 ident,
                 realname,
                 channel,
                 debug=False):
        super().__init__(server, nick, port, ident, realname, debug=debug)
        self.silent = False
        self.chan = channel
        self.msg_formats = IRCFormats()
        self.wstbot = WstBot(self, debug=True)

    # Send a formatted message
    def formatted_msg(self, chan, msg, addcolor=True):
        def sendline(line):
            if line != "":  # ignore empty lines
                if addcolor:
                    self.msg(chan, self.msg_formats.default_color(line))
                else:
                    self.msg(chan, line)

        if msg:
            lines = msg.split("\n")
            apply_seq(sendline, lines)

    # Send a message to the current channel
    def chanmsg(self, msg, addcolor=True):
        self.formatted_msg(self.chan, msg, addcolor)

    def send_room_message(self, message, formatted=True):
        # there is no real difference between formatted and unformatted messages in irc
        self.chanmsg(message)

    # Handle privmsg
    def on_privmsg(self, nick, ident, server, target, msg):
        self.wstbot.handle_message(nick, msg)

    # Joining a channel
    def on_me_join(self, channel):
        self.wstbot.on_me_join(channel)

    # Someone else joins a channel
    def on_join(self, nick, ident, server):
        self.wstbot.on_join(nick)

    # Handle all received data
    def on_receive(self, line):
        # This could be quakenet specific
        if "End of" in line and "376" in line:
            self.join(self.chan)

    def cli_options(self):
        print("Commands: msg, join")
        try:
            command = input()
            sp = command.find(" ")
            c = command[:sp]
            argstr = command[sp + 1:]

            if c == "msg":
                self.chanmsg(argstr)
            elif c == "join":
                self.part(self.chan)
                self.join(argstr)
                self.chan = argstr
        except KeyboardInterrupt:
            return None
Beispiel #4
0
 def __init__(self, server, nick, port, ident, realname, channel, debug=False):
     super().__init__(server, nick, port, ident, realname, debug=debug)
     self.silent = False
     self.chan = channel
     self.msg_formats = IRCFormats()
     self.wstbot = WstBot(self, debug=True)
Beispiel #5
0
class WstBotIRC(wirc.wIRC):

    def __init__(self, server, nick, port, ident, realname, channel, debug=False):
        super().__init__(server, nick, port, ident, realname, debug=debug)
        self.silent = False
        self.chan = channel
        self.msg_formats = IRCFormats()
        self.wstbot = WstBot(self, debug=True)

    # Send a formatted message
    def formatted_msg(self, chan, msg, addcolor=True):
        def sendline(line):
            if line != "": # ignore empty lines
                if addcolor:
                    self.msg(chan, self.msg_formats.default_color(line))
                else:
                    self.msg(chan, line)
                
        if msg:
            lines = msg.split("\n")
            apply_seq(sendline, lines)
                    
    # Send a message to the current channel
    def chanmsg(self, msg, addcolor=True):
        self.formatted_msg(self.chan, msg, addcolor)

    def send_room_message(self, message, formatted=True):
        # there is no real difference between formatted and unformatted messages in irc
        self.chanmsg(message)
    
    # Handle privmsg
    def on_privmsg(self, nick, ident, server, target, msg):    
        self.wstbot.handle_message(nick, msg)

    # Joining a channel
    def on_me_join(self, channel):
        self.wstbot.on_me_join(channel)
        
    # Someone else joins a channel
    def on_join(self, nick, ident, server):
        self.wstbot.on_join(nick)
        
    # Handle all received data
    def on_receive(self, line):
        # This could be quakenet specific
        if "End of" in line and "376" in line:
            self.join(self.chan)

    def cli_options(self):
        print("Commands: msg, join")
        try:
            command = input()
            sp = command.find(" ")
            c = command[:sp]
            argstr = command[sp + 1:]

            if c == "msg":
                self.chanmsg(argstr)
            elif c == "join":
                self.part(self.chan)
                self.join(argstr)
                self.chan = argstr
        except KeyboardInterrupt:
            return None
Beispiel #6
0
    def __init__(self, *args):
        super().__init__(*args)

        self.msg_formats = XMPPFormats()
        self.wstbot = WstBot(self, debug=True)