Example #1
0
    def update_server(self, data):
        if data.get('name'):
            self.name = data.get('name')
        if data.get('ip'):
            self.ip = data.get('ip')
        if data.get('port'):
            self.port = data.get('port')
        if data.get('password'):
            self.password = data.get('password')
        if data.get('monitor_chat'):
            self.monitor_chat = data.get('monitor_chat')
        if 'monitor_chat_channel' in data.keys():
            self.monitor_chat_channel = Channel.get_channel_by_id(
                data.get('monitor_chat_channel'))
        if 'alerts_channel' in data.keys():
            self.alerts_channel = Channel.get_channel_by_id(
                data.get('alerts_channel'))
        if 'info_channel' in data.keys():
            self.alerts_channel = Channel.get_channel_by_id(
                data.get('info_channel'))
        if 'info_message' in data.keys():
            self.info_message = Message.get_message_by_id(
                data.get('info_message'))
        if 'settings_message' in data.keys():
            self.settings_message = Message.get_message_by_id(
                data.get('settings_message'))

        self.save()
        return create_success_response(self,
                                       status.HTTP_202_ACCEPTED,
                                       many=False)
Example #2
0
    def add_new_request(cls, guild_id, data):
        author_id = data.get('author')
        message_id = data.get('message')
        channel_id = data.get('channel')
        content = data.get('content')
        if not (guild_id and author_id and message_id and channel_id
                and content):
            return create_error_response(
                "One or more of the required fields are missing.",
                status=status.HTTP_400_BAD_REQUEST)
        guild = Guild.get_guild_by_id(guild_id)
        if not isinstance(guild, Guild):
            return create_error_response('Guild Does Not Exist',
                                         status=status.HTTP_404_NOT_FOUND)
        author = User.get_user_by_id(author_id)
        if not isinstance(author, User):
            return create_error_response('Author Does Not Exist',
                                         status=status.HTTP_404_NOT_FOUND)
        message = Message.get_message_by_id(message_id)
        if not isinstance(message, Message):
            return create_error_response('Message Does Not Exist',
                                         status=status.HTTP_404_NOT_FOUND)
        channel = Channel.get_channel_by_id(guild_id, channel_id)
        if not isinstance(channel, Channel):
            return create_error_response('Channel Does Not Exist',
                                         status=status.HTTP_404_NOT_FOUND)

        print('test')

        request = cls(guild=guild,
                      author=author,
                      message=message,
                      channel=channel,
                      content=content)
        request.save()
        return create_request_success_response(request,
                                               status.HTTP_201_CREATED,
                                               many=False)
Example #3
0
    def add_new_message(cls, data):
        id = data.get('id')
        if id and cls.get_message_by_id(id):
            return create_error_response("Message Already Exists",
                                         status=status.HTTP_409_CONFLICT)
        author_id = data.get('author')
        guild_id = data.get('guild')
        channel_id = data.get('channel')
        created_at = data.get('created_at')
        content = data.get('content')
        tagged_everyone = data.get('tagged_everyone')
        if not (id and author_id and guild_id and channel_id and created_at and
                (tagged_everyone is not None)):
            return create_error_response(
                "One or more required fields are missing.",
                status=status.HTTP_400_BAD_REQUEST)
        author = User.get_user_by_id(author_id)
        if not isinstance(author, User):
            return create_error_response("Author Does Not Exist",
                                         status=status.HTTP_404_NOT_FOUND)
        guild = Guild.get_guild_by_id(guild_id)
        if not isinstance(guild, Guild):
            return create_error_response("Guild Does Not Exist",
                                         status=status.HTTP_404_NOT_FOUND)
        channel = Channel.get_channel_by_id(guild_id, channel_id)
        if not isinstance(channel, Channel):
            return create_error_response("Channel Does Not Exist",
                                         status=status.HTTP_404_NOT_FOUND)
        created_at = datetime.fromtimestamp(created_at, tz=timezone.utc)

        message = cls(id=id,
                      author=author,
                      guild=guild,
                      channel=channel,
                      created_at=created_at,
                      tagged_everyone=tagged_everyone or False,
                      content=content or '',
                      embeds=data.get('embeds') or [])
        message.save()
        if data.get('tagged_users'):
            tagged_users = data.get('tagged_users')
            for user_id in tagged_users:
                user = User.get_user_by_id(user_id)
                if user:
                    message.tagged_users.add(user)
        if data.get('tagged_roles'):
            tagged_roles = data.get('tagged_roles')
            for role_id in tagged_roles:
                role = Role.get_role_by_id(guild_id, role_id)
                if role:
                    message.tagged_roles.add(role)
        if data.get('tagged_channels'):
            tagged_channels = data.get('tagged_channels')
            for channel_id in tagged_channels:
                channel = Channel.get_channel_by_id(guild_id, channel_id)
                if channel:
                    message.tagged_channels.add(channel)

        return create_success_response(message,
                                       status.HTTP_201_CREATED,
                                       many=False)