forked from HoloTech/hyperfocus-twitch-bot
Initial commit
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import websockets
|
||||
|
||||
from twitchio.web import AiohttpAdapter
|
||||
|
||||
from meta import Bot, conf, setup_main_logger, args, sockets
|
||||
from data import Database
|
||||
|
||||
from modules import twitch_setup
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProxyAiohttpAdapter(AiohttpAdapter):
|
||||
"""
|
||||
Overrides the computed AiohttpAdapter redirect_url
|
||||
to always use provided domain.
|
||||
"""
|
||||
def _find_redirect(self, request):
|
||||
return self.redirect_url
|
||||
|
||||
|
||||
async def main():
|
||||
db = Database(conf.data['args'])
|
||||
|
||||
async with db.open():
|
||||
adapter_keys = (
|
||||
'host', 'domain', 'port',
|
||||
'redirect_path', 'oauth_path', 'eventsub_path',
|
||||
'eventsub_secret',
|
||||
)
|
||||
adapter_args = {}
|
||||
for key in adapter_keys:
|
||||
value = conf.twitch.get(key, '').strip()
|
||||
if value:
|
||||
if key == 'port':
|
||||
value = int(value)
|
||||
adapter_args[key] = value
|
||||
adapter = ProxyAiohttpAdapter(**adapter_args)
|
||||
|
||||
bot = Bot(
|
||||
config=conf,
|
||||
dbconn=db,
|
||||
adapter=adapter,
|
||||
setup=twitch_setup,
|
||||
using_webhooks=conf.twitch.getboolean('webhooks', False)
|
||||
)
|
||||
|
||||
async with websockets.serve(sockets.root_handler, '', conf.wserver.getint('port')):
|
||||
try:
|
||||
await bot.start()
|
||||
finally:
|
||||
await bot.close()
|
||||
|
||||
|
||||
def _main():
|
||||
setup_main_logger()
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user