Skip to content

Commit 15bddbc

Browse files
Your Nameflashcode
authored andcommitted
twitch.py 1.0: eval client_id and token expressions so that /secure can be used
1 parent f27e2c0 commit 15bddbc

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

python/twitch.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#
3535
# # History:
3636
#
37+
# 2024-06-29, mumixam + stacyharper
38+
# v1.0: eval client_id and token expressions so that /secure can be used
39+
#
3740
# 2020-07-27,
3841
# v0.9: added support for Oauth token to support twitch APIs requirement -mumixam
3942
# fix bug for when api returns null for game_id -mas90
@@ -64,7 +67,7 @@
6467

6568
SCRIPT_NAME = "twitch"
6669
SCRIPT_AUTHOR = "mumixam"
67-
SCRIPT_VERSION = "0.9"
70+
SCRIPT_VERSION = "1.0"
6871
SCRIPT_LICENSE = "GPL3"
6972
SCRIPT_DESC = "twitch.tv Chat Integration"
7073
OPTIONS={
@@ -336,7 +339,7 @@ def twitch_clearchat(data, modifier, modifier_data, string):
336339
user = mp['text']
337340
channel = mp['channel']
338341
try:
339-
tags = dict([s.split('=') for s in mp['tags'].split(';')])
342+
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
340343
except:
341344
tags = ''
342345
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
@@ -377,7 +380,7 @@ def twitch_clearmsg(data, modifier, modifier_data, string):
377380
server = modifier_data
378381
channel = mp['channel']
379382
try:
380-
tags = dict([s.split('=') for s in mp['tags'].split(';')])
383+
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
381384
except:
382385
tags = ''
383386
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
@@ -452,7 +455,7 @@ def twitch_usernotice(data, modifier, server, string):
452455
buffer = weechat.buffer_search(
453456
"irc", "%s.%s" % (server, mp['channel']))
454457
if mp['tags']:
455-
tags = dict([s.split('=') for s in mp['tags'].split(';')])
458+
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
456459
msg = tags['system-msg'].replace('\s',' ')
457460
if mp['text']:
458461
msg += ' [Comment] '+mp['text']
@@ -496,7 +499,7 @@ def twitch_in_privmsg(data, modifier, server_name, string, prefix=''):
496499
if '#' + mp['nick'] == mp['channel']:
497500
return mp['message_without_tags'].replace(mp['nick'], '~' + mp['nick'], 1)
498501

499-
tags = dict([s.split('=') for s in mp['tags'].split(';')])
502+
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
500503
if tags['user-type'] == 'mod':
501504
prefix += '@'
502505
if tags['subscriber'] == '1':
@@ -552,6 +555,8 @@ def config_setup():
552555
hlist = []
553556
cidv = weechat.config_get_plugin(option)
554557
tokv = weechat.config_get_plugin('token')
558+
if tokv[:6] == "${sec.":
559+
tokv = weechat.string_eval_expression(tokv, {}, {}, {})
555560
if cidv:
556561
hlist.append('Client-ID: '+cidv)
557562
if tokv:
@@ -562,6 +567,8 @@ def config_setup():
562567
hlist = []
563568
cidv = weechat.config_get_plugin('client_id')
564569
tokv = weechat.config_get_plugin(option)
570+
if tokv[:6] == "${sec.":
571+
tokv = weechat.string_eval_expression(tokv, {}, {}, {})
565572
if tokv:
566573
hlist.append('Authorization: Bearer '+tokv)
567574
if cidv:
@@ -592,6 +599,8 @@ def config_change(pointer, name, value):
592599
curlopt['httpheader'] = x + '\n' + "Client-ID: " + value
593600
break
594601
if option == 'token':
602+
if value[:6] == "${sec.":
603+
value = weechat.string_eval_expression(value, {}, {}, {})
595604
for x in curlopt['httpheader'].split('\n'):
596605
if x.startswith('Client-ID:'):
597606
curlopt['httpheader'] = x + '\n' + "Authorization: Bearer " + value
@@ -636,7 +645,7 @@ def config_change(pointer, name, value):
636645
" /set plugins.var.python.twitch.ssl_verify off\n"
637646
"\n\n"
638647
" Required server settings:\n"
639-
" /server add twitch irc.twitch.tv\n"
648+
" /server add twitch irc.chat.twitch.tv\n"
640649
" /set irc.server.twitch.capabilities \"twitch.tv/membership,twitch.tv/commands,twitch.tv/tags\"\n"
641650
" /set irc.server.twitch.nicks \"My Twitch Username\"\n"
642651
" /set irc.server.twitch.password \"oauth:My Oauth Key\"\n"

0 commit comments

Comments
 (0)