Exemplo n.º 1
0
def twitch_bot():
    logger.set_logger('twitch_bot.log', sentry_dsn=config['sentry_dsn'])
    from tbot.twitch_bot import bot_main, modlog
    log = logging.getLogger('main')
    log.setLevel('INFO')
    log.info('Twitch bot started')
    loop = asyncio.get_event_loop()
    loop.create_task(bot_main.bot.connect())
    loop.create_task(modlog.Pubsub().run())
    loop.run_forever()
    log.info('Twitch bot stopped')
Exemplo n.º 2
0
def upgrade():
    logger.set_logger('migration.log', sentry_dsn=config['sentry_dsn'])
    from yoyo import read_migrations
    from yoyo import get_backend

    backend = get_backend('mysql://{}:{}@{}:{}/{}'.format(
        config['mysql']['user'],
        config['mysql']['password'],
        config['mysql']['host'],
        config['mysql']['port'],
        config['mysql']['database'],
    ))
    log = logging.getLogger('main')
    log.setLevel('INFO')
    log.info('Upgrade started')
    migrations = read_migrations(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     'migrations'))
    with backend.lock():
        backend.apply_migrations(backend.to_apply(migrations))
    log.info('Upgrade done')
Exemplo n.º 3
0
                     message='I have arrived MrDestructoid')
        elif cmd == 'part':
            bot.send('PART', channel='#' + c['name'])
            del bot.channels[c['channel_id']]
            bot.send("PRIVMSG",
                     target='#' + c['name'],
                     message='I have been asked to leave FeelsBadMan')
        elif cmd == 'unmute':
            if c['channel_id'] in bot.channels:
                bot.channels[c['channel_id']]['muted'] = False
        elif cmd == 'mute':
            if c['channel_id'] in bot.channels:
                bot.channels[c['channel_id']]['muted'] = True
        elif cmd == 'enable_chatlog':
            if c['channel_id'] in bot.channels:
                bot.channels[c['channel_id']]['chatlog_enabled'] = True
        elif cmd == 'disable_chatlog':
            if c['channel_id'] in bot.channels:
                bot.channels[c['channel_id']]['chatlog_enabled'] = False
    except:
        logging.exception('redis_server_command')


if __name__ == '__main__':
    from tbot import config_load, logger
    config_load('../../tbot.yaml')
    logger.set_logger('bot.log')

    loop = asyncio.get_event_loop()
    loop.create_task(bot.connect())
    loop.run_forever()
Exemplo n.º 4
0
                if len(msg) != 2:
                    return
                cmd = msg.pop(0)
                if cmd not in ['join', 'part']:
                    return
                topic = 'chat_moderator_actions.{}.{}'.format(
                    self.current_user_id,
                    msg[0],
                )
                type_ = ''
                if cmd == 'join':
                    type_ = 'LISTEN'
                elif cmd == 'part':
                    type_ = 'UNLISTEN'
                await self.ws.send(json.dumps({
                    'type': type_,
                    'data': {
                        'topics': [topic],
                        'auth_token': self.token,
                    }
                }))
            except:
                logging.exception('receive_server_commands')

if __name__ == '__main__':
    from tbot import config_load, logger
    config_load('../../tbot.yaml')    
    logger.set_logger('modlog.log')
    loop = asyncio.get_event_loop()
    loop.create_task(Pubsub().run())    
    loop.run_forever()
Exemplo n.º 5
0
import logging, aiohttp, aiomysql
from tbot import config, db
from tbot.discord_bot import bot
import tbot.discord_bot.commands
import tbot.discord_bot.tasks
import tbot.discord_bot.functions


@bot.event
async def on_connect():
    if not hasattr(bot, 'ahttp'):
        bot.ahttp = aiohttp.ClientSession()
        bot.db = await db.Db().connect(bot.loop)


def main():
    log = logging.getLogger('main')
    log.setLevel('INFO')
    bot.loop.create_task(tbot.discord_bot.tasks.twitch_sync.twitch_sync())
    log.info('Discord bot started')
    bot.run(config['discord']['token'], bot=config['discord']['bot'])
    log.info('Discord bot stopped')


if __name__ == '__main__':
    from tbot import config_load, logger
    config_load('../../tbot.yaml')
    logger.set_logger('discord.log')

    main()
Exemplo n.º 6
0
def twitch_eventsub_check():
    logger.set_logger('twitch_eventsub_check.log',
                      sentry_dsn=config['sentry_dsn'])
    from tbot.web.handlers.api.twitch.eventsubs.eventsub import task_check_channels
    asyncio.run(task_check_channels())
Exemplo n.º 7
0
def discord():
    logger.set_logger('discord.log', sentry_dsn=config['sentry_dsn'])
    import tbot.discord_bot.bot_main
    tbot.discord_bot.bot_main.main()
Exemplo n.º 8
0
def web():
    logger.set_logger('web.log', sentry_dsn=config['sentry_dsn'])
    import tbot.web.app
    tbot.web.app.main()
Exemplo n.º 9
0
    loop = asyncio.get_event_loop()
    app = App()
    app.loop = loop
    server = app.listen(config['web']['port'])
    loop.create_task(db_connect(app))
    signal.signal(signal.SIGTERM, partial(sig_handler, server, app))
    signal.signal(signal.SIGINT, partial(sig_handler, server, app))

    log = logging.getLogger('main')
    log.setLevel('INFO')
    log.info(f'Web server started on port: {config["web"]["port"]}')
    loop.run_forever()
    log.info('Web server stopped')


async def db_connect(app):
    app.db = await db.Db().connect(None)
    app.redis = await aioredis.create_redis_pool(
        'redis://{}:{}'.format(config['redis']['host'],
                               config['redis']['port']),
        minsize=config['redis']['pool_min_size'],
        maxsize=config['redis']['pool_max_size'],
    )
    app.ahttp = aiohttp.ClientSession()


if __name__ == '__main__':
    from tbot import config_load, logger
    config_load('../../tbot.yaml')
    logger.set_logger('web.log')
    main()