Ejemplo n.º 1
0
    def add_notification(self, user, sender, message, timestamp):
        """
        add_notification(user, sender, message, timestamp) -> None

        Add notification for a certain user or group.
        """

        tp = user[0]
        receiver = user[1:]

        if tp == "@":  #Normal notification
            if receiver == "NotBot":
                return "No. Won't do that for you. Sorry."
            self.create_notification(ut.filter_nick(receiver), user, sender,
                                     message, timestamp)
        elif tp == "*":  #Group notification
            for p in self.groups.get_filtered_users(receiver):
                if p != ut.filter_nick(sender):
                    if p not in self.messages:
                        self.messages[p] = []
                    self.create_notification(p, user, sender, message,
                                             timestamp)
        else:
            return

        return "Message will be delivered to %s." % user
Ejemplo n.º 2
0
    def get_filtered_users(self, group):
        """
        get_filtered_users(group) -> List

        Get the filtered list of users in a certain group.
        """

        return [ut.filter_nick(u) for u in self.get_users(group)]
Ejemplo n.º 3
0
    def get_filtered_users(self, group):
        """
        get_filtered_users(group) -> List

        Get the filtered list of users in a certain group.
        """

        return [ut.filter_nick(u) for u in self.get_users(group)]
Ejemplo n.º 4
0
    def add_to_group(self, user, group):
        """
        add_to_group(user, group) -> None

        Add a user to a group.
        """

        if group not in self.groups:
            self.groups[group] = []

        filtered_group = [ut.filter_nick(u) for u in self.groups[group]]
        if ut.filter_nick(user) in filtered_group:
            #Already in group
            return "%s is already in group %s." % ("@" + user, "*" + group)
        else:
            #Add that person to the group
            self.groups[group].append(user)
            return "Added %s to group %s." % ("@" + user, "*" + group)
Ejemplo n.º 5
0
    def add_to_group(self, user, group):
        """
        add_to_group(user, group) -> None

        Add a user to a group.
        """

        if group not in self.groups:
            self.groups[group] = []

        filtered_group = [ut.filter_nick(u) for u in self.groups[group]]
        if ut.filter_nick(user) in filtered_group:
            #Already in group
            return "%s is already in group %s." % ("@" + user, "*" + group)
        else:
            #Add that person to the group
            self.groups[group].append(user)
            return "Added %s to group %s." % ("@" + user, "*" + group)
Ejemplo n.º 6
0
    def remove_from_group(self, user, group):
        """
        remove_from_group(user, group) -> None

        Remove a user from the group.
        """

        if group not in self.groups:
            self.groups[group] = []

        filtered_group = [ut.filter_nick(u) for u in self.groups[group]]
        if ut.filter_nick(user) not in filtered_group:
            #Person is not in group
            return "%s is not in group %s." % ("@" + user, "*" + group)
        else:
            #Remove from group
            self.groups[group].pop(filtered_group.index(ut.filter_nick(user)))
            if len(self.groups[group]) == 0:
                self.groups.pop(group)

            return "%s has been removed from group %s." % ("@" + user, "*" + group)
Ejemplo n.º 7
0
    def remove_from_group(self, user, group):
        """
        remove_from_group(user, group) -> None

        Remove a user from the group.
        """

        if group not in self.groups:
            self.groups[group] = []

        filtered_group = [ut.filter_nick(u) for u in self.groups[group]]
        if ut.filter_nick(user) not in filtered_group:
            #Person is not in group
            return "%s is not in group %s." % ("@" + user, "*" + group)
        else:
            #Remove from group
            self.groups[group].pop(filtered_group.index(ut.filter_nick(user)))
            if len(self.groups[group]) == 0:
                self.groups.pop(group)

            return "%s has been removed from group %s." % ("@" + user,
                                                           "*" + group)
Ejemplo n.º 8
0
    def add_notification(self, user, sender, message, timestamp):
        """
        add_notification(user, sender, message, timestamp) -> None

        Add notification for a certain user or group.
        """

        tp = user[0]
        receiver = user[1:]

        if tp == "@":  #Normal notification
            if receiver == "NotBot":
                return "No. Won't do that for you. Sorry."
            self.create_notification(ut.filter_nick(receiver), user, sender, message, timestamp)
        elif tp == "*":  #Group notification
            for p in self.groups.get_filtered_users(receiver):
                if p != ut.filter_nick(sender):
                    if p not in self.messages:
                        self.messages[p] = []
                    self.create_notification(p, user, sender, message, timestamp)
        else:
            return

        return "Message will be delivered to %s." % user
Ejemplo n.º 9
0
    def handle_chat(self, info):
        #Handle sending messages if the user speaks
        user = ut.filter_nick(info["sender"]["name"])
        if self.messages.has_notifications(user):
            ms = self.messages.get_notifications(user)
            for m in ms:
                self.send_chat(m, info["id"])

        #Now, begin proccessing the message
        #Split the message into parts and work out the command
        cmd = euphoria.command.Command(info["content"])
        cmd.parse()

        #!notify someone
        if cmd.command == "notify":
            self.parse_notify(info, cmd)

        #Create a group
        elif cmd.command == "group":
            self.parse_group(info, cmds, add=True)

        #Remove someone from a group
        elif cmd.command == "ungroup":
            self.parse_group(info, cmd, add=False)

        #Get a list of all the groups
        elif cmd.command == "grouplist":
            if len(cmd.args) == 0:
                gs = self.groups.get_groups()
                if len(gs) != 0:
                    gs = ["*" + g for g in gs]
                    self.send_chat("\n".join(gs), info["id"])
            elif len(cmd.args) == 1:
                if cmd.args[0][0] == "*":
                    us = self.groups.get_users(cmd.args[0][1:])
                    if len(us) != 0:
                        if "ping" in cmd.flags:
                            us = ['@' + u for u in us]
                        self.send_chat("\n".join(us), info["id"])

        #command to address bot ghosting issues (where bot is present but not shown on nicklist)
        elif cmd.command == "antighost":
            self.change_nick(self.nickname)
Ejemplo n.º 10
0
    def handle_chat(self, info):
        #Handle sending messages if the user speaks
        user = ut.filter_nick(info["sender"]["name"])
        if self.messages.has_notifications(user):
            ms = self.messages.get_notifications(user)
            for m in ms:
                self.send_chat(m, info["id"])

        #Now, begin proccessing the message
        #Split the message into parts and work out the command
        cmd = euphoria.command.Command(info["content"])
        cmd.parse()

        #!notify someone
        if cmd.command == "notify":
            self.parse_notify(info, cmd)

        #Create a group
        elif cmd.command == "group":
            self.parse_group(info, cmds, add=True)

        #Remove someone from a group
        elif cmd.command == "ungroup":
            self.parse_group(info, cmd, add=False)

        #Get a list of all the groups
        elif cmd.command == "grouplist":
            if len(cmd.args) == 0:
                gs = self.groups.get_groups()
                if len(gs) != 0:
                    gs = ["*" + g for g in gs]
                    self.send_chat("\n".join(gs), info["id"])
            elif len(cmd.args) == 1:
                if cmd.args[0][0] == "*":
                    us = self.groups.get_users(cmd.args[0][1:])
                    if len(us) != 0:
                        if "ping" in cmd.flags:
                            us = ['@' + u for u in us]
                        self.send_chat("\n".join(us), info["id"])

        #command to address bot ghosting issues (where bot is present but not shown on nicklist)
        elif cmd.command == "antighost":
            self.change_nick(self.nickname)