Beispiel #1
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()