Пример #1
0
    def cmd_commands(self, data):
        """List the available commands."""

        admin_cmds = []
        admin_or_moderator_cmds = []
        moderator_cmds = []
        no_priv_cmds = []

        for command, func in self.commands.items():
            if func.func_dict.get("admin_required"):
                admin_cmds.append(command)
            elif func.func_dict.get("admin_or_moderator_required"):
                admin_or_moderator_cmds.append(command)
            elif func.func_dict.get("moderator_required"):
                moderator_cmds.append(command)
            else:
                no_priv_cmds.append(command)
        reply = "Available commands: "
        reply += ", ".join(sorted(no_priv_cmds))
        self.reply(reply, data)

        user_id = get_sender_id(data)
        if moderator_cmds and self.is_moderator(user_id):
            reply = "Moderator commands: "
            reply += ", ".join(sorted(moderator_cmds))
            self.api.pm(reply, user_id)
        if admin_or_moderator_cmds and (self.is_moderator(user_id) or self.is_admin(user_id)):
            reply = "Priviliged commands: "
            reply += ", ".join(sorted(admin_or_moderator_cmds))
            self.api.pm(reply, user_id)
        if admin_cmds and self.is_admin(user_id):
            reply = "Admin commands: "
            reply += ", ".join(sorted(admin_cmds))
            self.api.pm(reply, user_id)
Пример #2
0
 def callback(cb_data):
     user_id = get_sender_id(data)
     if cb_data['success']:
         # Schedule an event to possibly rejoin after 1 minute
         self.schedule(60, self._connect, self.config['room_id'], False)
         self.api.pm('I have left the room. If I remain roomless after '
                     '~1 minute, I will rejoin the default room.',
                     user_id)
     else:
         self.api.pm('Leaving the room failed.', user_id)
Пример #3
0
 def callback(cb_data):
     user_id = get_sender_id(data)
     if cb_data["success"]:
         # Schedule an event to possibly rejoin after 1 minute
         self.schedule(60, self._connect, self.config["room_id"], False)
         self.api.pm(
             "I have left the room. If I remain roomless after " "~1 minute, I will rejoin the default room.",
             user_id,
         )
     else:
         self.api.pm("Leaving the room failed.", user_id)
Пример #4
0
    def cmd_commands(self, data):
        """List the available commands."""

        admin_cmds = []
        admin_or_moderator_cmds = []
        moderator_cmds = []
        no_priv_cmds = []

        for command, func in self.commands.items():
            if func.func_dict.get('dynamic_permissions'):
                # TODO: Handle this case
                pass
            elif func.func_dict.get('admin_required'):
                admin_cmds.append(command)
            elif func.func_dict.get('admin_or_moderator_required'):
                admin_or_moderator_cmds.append(command)
            elif func.func_dict.get('moderator_required'):
                moderator_cmds.append(command)
            else:
                no_priv_cmds.append(command)
        reply = 'Available commands: '
        reply += ', '.join(sorted(no_priv_cmds))
        self.reply(reply, data)

        user_id = get_sender_id(data)
        if moderator_cmds and self.is_moderator(user_id):
            reply = 'Moderator commands: '
            reply += ', '.join(sorted(moderator_cmds))
            self.api.pm(reply, user_id)
        if admin_or_moderator_cmds and (self.is_moderator(user_id)
                                        or self.is_admin(user_id)):
            reply = 'Priviliged commands: '
            reply += ', '.join(sorted(admin_or_moderator_cmds))
            self.api.pm(reply, user_id)
        if admin_cmds and self.is_admin(user_id):
            reply = 'Admin commands: '
            reply += ', '.join(sorted(admin_cmds))
            self.api.pm(reply, user_id)
Пример #5
0
 def is_moderator(self, item):
     """item can be either the user_id, or a dictionary from a message."""
     if isinstance(item, dict):
         item = get_sender_id(item)
     return item in self.moderator_ids
Пример #6
0
 def is_admin(self, item):
     """item can be either the user_id, or a dictionary from a message."""
     if isinstance(item, dict):
         item = get_sender_id(item)
     return item in self.config["admin_ids"]