Пример #1
0
    def _get_command_object(self):
        command_object = None
        if issubclass(self.cmd, staticCommands.StaticCommand):
            logging.debug("Static command.")
            command_object = self.cmd(key=self._key)

        elif issubclass(self.cmd, commands.ILevelCommand):
            logging.debug("Level command.")
            command_object = self.cmd(
                user_id=self.event.from_id,
                chat_id=self.event.peer_id,
                target_id=Utils.find_user_id(self._value),
                amount=Utils.get_experience_amount(self._value))

        elif issubclass(self.cmd, commands.ICommandManager):
            logging.debug("Commands managing.")
            if not Utils.has_role(self.event.from_id,
                                  Roles.DONATOR | Roles.ADMIN):
                raise exceptions.AccesDeniesError
            command_object = self.cmd(message=self.event.text,
                                      attachments=self.event.attachments,
                                      author_id=self.event.from_id)

        elif issubclass(self.cmd, commands.IAdminCommand):
            logging.debug("Admin managing.")
            if not Utils.is_creator(self.event.from_id):
                raise exceptions.AccesDeniesError
            user_id = Utils.find_user_id(self.event.text)
            command_object = self.cmd(user_id, self.event.from_id)

        elif issubclass(self.cmd, commands.IDonatorManager):
            logging.debug("Donator managing.")
            if not Utils.is_creator(self.event.from_id):
                raise exceptions.AccesDeniesError
            command_object = self.cmd(self._value, self.event.from_id)

        elif issubclass(self.cmd, commands.IOsuCommand):
            logging.debug("osu! command")
            # Need to get server and username from db
            # server, username, user_id dict
            params = Utils.get_osu_params(self._value, self.event.from_id)
            logging.debug(self.event)
            fwd_message = Utils.get_reply_message_from_event(self.event)
            if fwd_message is not None:
                params["beatmap_id"] = Utils.find_beatmap_id(
                    fwd_message["text"])
            command_object = self.cmd(**params)

        else:
            logging.debug("Other command.")
            command_object = self.cmd(self._value, self.event.from_id)
        return command_object
Пример #2
0
 def execute(self):
     self._user_id = Utils.find_user_id(self._args[0])
     self._role = self._parse_role_name()
     logging.info(f"Editing role: {self._user_id} -> {self._role}")
     glob.c.execute("UPDATE donators SET role = ? WHERE id = ?",
                    (self._role, self._user_id))
     glob.db.commit()
     return self.Message(
         f"Роль {self._user_id} была успешно изменена на {self._role}")