コード例 #1
0
async def giveawayend(config: Config, match: Match[str]) -> Optional[str]:
    if not is_moderator(match) and match['user'] != match['channel']:
        return None

    async with aiosqlite.connect('db.db') as db:
        await ensure_giveaway_tables_exist(db)

        async with db.execute('SELECT active FROM giveaway') as cursor:
            row = await cursor.fetchone()
            if row is None or not row[0]:
                return format_msg(match, 'no current giveaway active!')

        query = 'SELECT user FROM giveaway_users'
        async with db.execute(query) as cursor:
            users = [user for user, in await cursor.fetchall()]

        if users:
            await db.execute('INSERT OR REPLACE INTO giveaway VALUES (0)')
            await db.commit()

        await db.execute('DROP TABLE giveaway_users')
        await db.execute('DROP TABLE giveaway')
        await db.commit()

    if not users:
        return format_msg(match, 'no users entered giveaway!')

    winner = random.choice(users)
    return format_msg(match, f'!giveaway winner is {esc(winner)}')
コード例 #2
0
async def cmd_videoidea(config: Config, match: Match[str]) -> str:
    if not is_moderator(match) and match['user'] != match['channel']:
        return format_msg(match, 'https://youtu.be/RfiQYRn7fBg')
    _, _, rest = match['msg'].partition(' ')

    async def _git(*cmd: str) -> None:
        await _check_call('git', '-C', tmpdir, *cmd)

    with tempfile.TemporaryDirectory() as tmpdir:
        await _git(
            'clone',
            '--depth=1',
            '--quiet',
            '[email protected]:asottile/scratch.wiki',
            '.',
        )
        ideas_file = os.path.join(tmpdir, 'anthony-explains-ideas.md')
        with open(ideas_file, 'rb+') as f:
            f.seek(-1, os.SEEK_END)
            c = f.read()
            if c != b'\n':
                f.write(b'\n')
            f.write(f'- {rest}\n'.encode())
        await _git('add', '.')
        await _git('commit', '-q', '-m', 'idea added by !videoidea')
        await _git('push', '-q', 'origin', 'HEAD')

    return format_msg(
        match,
        'added! https://github.com/asottile/scratch/wiki/anthony-explains-ideas',  # noqa: E501
    )
コード例 #3
0
async def cmd_settoday(config: Config, match: Match[str]) -> str:
    if not is_moderator(match) and match['user'] != match['channel']:
        return format_msg(match, 'https://youtu.be/RfiQYRn7fBg')
    _, _, rest = match['msg'].partition(' ')

    async with aiosqlite.connect('db.db') as db:
        await set_today(db, rest)

    return format_msg(match, 'updated!')
コード例 #4
0
ファイル: vim_timer.py プロジェクト: bejoinka/twitch-chat-bot
async def cmd_disablevim(config: Config, match: Match[str]) -> str:
    if not is_moderator(match) and match['user'] != match['channel']:
        return format_msg(match, 'https://youtu.be/RfiQYRn7fBg')

    async with aiosqlite.connect('db.db') as db:
        await ensure_vim_tables_exist(db)

        await db.execute('INSERT INTO vim_enabled VALUES (0)')
        await db.commit()

    return format_msg(match, 'vim has been disabled')
コード例 #5
0
ファイル: giveaway.py プロジェクト: bejoinka/twitch-chat-bot
async def givewawaystart(config: Config, match: Match[str]) -> str | None:
    if not is_moderator(match) and match['user'] != match['channel']:
        return None

    async with aiosqlite.connect('db.db') as db:
        await ensure_giveaway_tables_exist(db)

        await db.execute('INSERT OR REPLACE INTO giveaway VALUES (1)')
        await db.commit()

    return format_msg(match, 'giveaway started!  use !giveaway to enter')
コード例 #6
0
ファイル: vim_timer.py プロジェクト: bejoinka/twitch-chat-bot
async def cmd_enablevim(config: Config, match: Match[str]) -> str:
    if not is_moderator(match) and match['user'] != match['channel']:
        return format_msg(match, 'https://youtu.be/RfiQYRn7fBg')

    async with aiosqlite.connect('db.db') as db:
        await ensure_vim_tables_exist(db)

        await db.execute('INSERT INTO vim_enabled VALUES (1)')
        move_query = 'INSERT INTO vim_bits SELECT * FROM vim_bits_disabled'
        await db.execute(move_query)
        time_left = await add_time(db, await disabled_seconds(db))
        await db.execute('DELETE FROM vim_bits_disabled')
        await db.commit()

    if time_left == 0:
        return format_msg(match, 'vim has been enabled')
    else:
        await _set_symlink(should_be_vim=True)
        return format_msg(
            match,
            f'vim has been enabled: '
            f'time remaining {seconds_to_readable(time_left)}',
        )