Пример #1
0
    def set_react_role_message(self, message_id):
        '''
        Adds/Updates the current ract_role_message_id.
        Args:
            - message_id (int): ID of message from react_role.
        Returns:
            None.
        '''

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                guild_query.ract_role_message_id = str(message_id)
                session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.ract_role_message_id = str(message_id)
                session.add(admin_options)
                session.commit()
Пример #2
0
    def remove_welcome_channel(self):
        '''
        Removes the current home channel msg in the database.

        Args:
            None.

        Returns:
            None.

        '''

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                if guild_query.home_msg_id:
                    guild_query.home_msg_id = "0"
                    session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.home_msg_id = "0"
                session.add(admin_options)
                session.commit()
Пример #3
0
    def set_welcome_channel(self, home_msg_id):
        '''
        Adds/Updates the current home channel msg in the database.

        Args:
            - home_msg_id (int): ID of home channel message.

        Returns:
            None.

        '''

        home_msg_id = str(home_msg_id)

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                guild_query.home_msg_id = home_msg_id
                session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.home_msg_id = home_msg_id
                session.add(admin_options)
                session.commit()
Пример #4
0
    def update_default_role(self, default_role_id):
        '''
        Adds/Updates the current default role in the database.

        Args:
            - default_role_id (int): ID of default role.

        Returns:
            None.

        '''

        str_default_role_id = str(default_role_id)

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                if guild_query.default_role_id:
                    guild_query.default_role_id = str_default_role_id
                    session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.default_role_id = str_default_role_id
                session.add(admin_options)
                session.commit()
Пример #5
0
    def add_react_role(self, react_role_dict):
        '''
        Adds/Updates the current ract_role_dictionary.

        Args:
            - react_role_dict (dict): dictionary in the format:
                {
                    "react_emote": role_id,
                }

        Returns:
            None.

        '''

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                if guild_query.react_role_dict:

                    curr_dict = json.loads(guild_query.react_role_dict)
                    curr_dict.update(react_role_dict)

                    guild_query.react_role_dict = json.dumps(curr_dict)
                    session.commit()
                else:
                    guild_query.react_role_dict = json.dumps(react_role_dict)
                    session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.react_role_dict = json.dumps(react_role_dict)
                session.add(admin_options)
                session.commit()
Пример #6
0
    def add_cursed_words(self, words):
        '''
        Adds/Updates the current list of cursed words.

        Args:
            - words (lst): List of words to add to cursed_words.

        Returns:
            None.

        '''

        with self.session() as session:
            guild_query = session.query(AdminOptions).filter(
                AdminOptions.guild_id == self.guild_id).one_or_none()

            # if there are already entries for this guild, updates them
            if guild_query is not None:
                if guild_query.cursed_words:

                    new_words = set(words +
                                    guild_query.cursed_words.split(','))

                    guild_query.\
                        cursed_words = ','.join(new_words)

                    session.commit()
                else:
                    guild_query.cursed_words = ','.join(set(words))
                    session.commit()

            # if there are no entries for this guild, creates entry
            else:
                admin_options = AdminOptions()
                admin_options.guild_id = self.guild_id
                admin_options.cursed_words = ','.join(set(words))
                session.add(admin_options)
                session.commit()