コード例 #1
0
    async def ignore_add(self, msg: Message, pattern: str):

        # Check if the regex is valid, return error if not.
        try:
            re.compile(pattern)
        except re.error:
            await msg.reply(f"{bot.msg_prefix}Invalid regex pattern.")
            return

        # Will not support a space in the pattern, but that doesn't matter because usernames can't have spaces
        query = session.query(IgnoreList).filter(
            IgnoreList.pattern == pattern).one_or_none()
        if query is None:
            # Pattern didn't exist, so add it.
            insert = IgnoreList(pattern=pattern)
            session.add(insert)
            session.commit()
            session.refresh(insert)
            await msg.reply(
                f"{bot.msg_prefix}I will now ignore links from {pattern}")
            bot.ignore_list_patterns[insert.id] = pattern

        else:
            await msg.reply(
                f"{bot.msg_prefix}That pattern is already in the database.")
コード例 #2
0
ファイル: wigs.py プロジェクト: geekbozu/Twitch_Bot
    async def wig_add(self, msg: Message, *args):
        """Adds a new wig to the database"""
        wig_name = " ".join(map(str, args))

        new_wig = Wigs(wig_name=wig_name, enabled=1)
        session.add(new_wig)
        session.commit()

        session.refresh(new_wig)
        await msg.reply(f"{bot.msg_prefix}New wig added as id {new_wig.id}.")
コード例 #3
0
    async def announce_category_add(self, msg, *args):
        """Add a category"""

        cat_name = " ".join(map(str, args))
        exists = session.query(AnnouncementCategories).filter(AnnouncementCategories.name == cat_name).count()
        if exists:
            await msg.reply(f"{bot.msg_prefix}Duplicate category name")
            return

        # Insert the new category into the database
        new_announcement = AnnouncementCategories(name=cat_name)
        session.add(new_announcement)
        session.commit()

        # Refresh to pull the ID inserted as
        session.refresh(new_announcement)
        await msg.reply(f"{bot.msg_prefix}{new_announcement.name} added as id {new_announcement.id}")
コード例 #4
0
    async def announce_add(self, msg, *args):

        message = ""

        # Build the message
        for arg in args:
            message += f"{arg} "

        print(f"Adding to announce: {message}", end="")

        announcement_object = Announcements(text=message)

        session.add(announcement_object)
        session.commit()
        session.refresh(announcement_object)
        id = announcement_object.id

        print(f"...done, {id=}")

        await msg.reply(f"{bot.msg_prefix}Added announce {id=}")