Adjust Twitch adapter configuration
This commit is contained in:
21
example-config/bot.conf
Normal file
21
example-config/bot.conf
Normal file
@@ -0,0 +1,21 @@
|
||||
[BOT]
|
||||
prefix = ?
|
||||
bot_id =
|
||||
|
||||
ALSO_READ = config/secrets.conf
|
||||
|
||||
[TWTICH]
|
||||
host =
|
||||
port =
|
||||
domain =
|
||||
redirect_path =
|
||||
oauth_path =
|
||||
evenstub_path =
|
||||
|
||||
webhooks =
|
||||
|
||||
[LOGGING]
|
||||
general_log =
|
||||
warning_log =
|
||||
error_log =
|
||||
critical_log =
|
||||
10
example-config/secrets.conf
Normal file
10
example-config/secrets.conf
Normal file
@@ -0,0 +1,10 @@
|
||||
[BOT]
|
||||
client_id =
|
||||
client_secret =
|
||||
|
||||
[TWITCH]
|
||||
eventsub_secret =
|
||||
|
||||
[DATA]
|
||||
args =
|
||||
appid =
|
||||
@@ -2,3 +2,4 @@ websockets
|
||||
twitchio
|
||||
psycopg[pool]
|
||||
cachetools
|
||||
discord.py
|
||||
|
||||
22
src/bot.py
22
src/bot.py
@@ -13,6 +13,10 @@ 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
|
||||
|
||||
@@ -21,18 +25,26 @@ async def main():
|
||||
db = Database(conf.data['args'])
|
||||
|
||||
async with db.open():
|
||||
adapter = ProxyAiohttpAdapter(
|
||||
host=conf.bot.get('wshost', None),
|
||||
port=conf.bot.getint('wsport', None),
|
||||
domain=conf.bot.get('wsdomain', None),
|
||||
eventsub_secret=conf.bot.get('eventsub_secret', None)
|
||||
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')):
|
||||
|
||||
@@ -29,10 +29,7 @@ class Bot(commands.Bot):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Whether we should do eventsub via webhooks or websockets
|
||||
if config.bot.get('eventsub_secret', None):
|
||||
self.using_webhooks = True
|
||||
else:
|
||||
self.using_webhooks = False
|
||||
self.using_webhooks = kwargs.get('using_webhooks', False)
|
||||
|
||||
self.config = config
|
||||
self.dbconn = dbconn
|
||||
|
||||
Reference in New Issue
Block a user