Skip to content

Commit

Permalink
twitch.py 1.0: eval client_id and token expressions so that /secure c…
Browse files Browse the repository at this point in the history
…an be used
  • Loading branch information
Your Name committed Jun 29, 2024
1 parent f27e2c0 commit 7c0acfc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions python/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#
# # History:
#
# 2024-06-29,
# v1.0: eval client_id and token expressions so that /secure can be used
#
# 2020-07-27,
# v0.9: added support for Oauth token to support twitch APIs requirement -mumixam
# fix bug for when api returns null for game_id -mas90
Expand Down Expand Up @@ -64,7 +67,7 @@

SCRIPT_NAME = "twitch"
SCRIPT_AUTHOR = "mumixam"
SCRIPT_VERSION = "0.9"
SCRIPT_VERSION = "1.0"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "twitch.tv Chat Integration"
OPTIONS={
Expand Down Expand Up @@ -336,7 +339,7 @@ def twitch_clearchat(data, modifier, modifier_data, string):
user = mp['text']
channel = mp['channel']
try:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
except:
tags = ''
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
Expand Down Expand Up @@ -377,7 +380,7 @@ def twitch_clearmsg(data, modifier, modifier_data, string):
server = modifier_data
channel = mp['channel']
try:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
except:
tags = ''
buffer = weechat.buffer_search("irc", "%s.%s" % (server, channel))
Expand Down Expand Up @@ -452,7 +455,7 @@ def twitch_usernotice(data, modifier, server, string):
buffer = weechat.buffer_search(
"irc", "%s.%s" % (server, mp['channel']))
if mp['tags']:
tags = dict([s.split('=') for s in mp['tags'].split(';')])
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
msg = tags['system-msg'].replace('\s',' ')
if mp['text']:
msg += ' [Comment] '+mp['text']
Expand Down Expand Up @@ -496,7 +499,7 @@ def twitch_in_privmsg(data, modifier, server_name, string, prefix=''):
if '#' + mp['nick'] == mp['channel']:
return mp['message_without_tags'].replace(mp['nick'], '~' + mp['nick'], 1)

tags = dict([s.split('=') for s in mp['tags'].split(';')])
tags = dict([s.split('=',1) for s in mp['tags'].split(';')])
if tags['user-type'] == 'mod':
prefix += '@'
if tags['subscriber'] == '1':
Expand Down Expand Up @@ -552,6 +555,8 @@ def config_setup():
hlist = []
cidv = weechat.config_get_plugin(option)
tokv = weechat.config_get_plugin('token')
if tokv[:6] == "${sec.":
tokv = weechat.string_eval_expression(tokv, {}, {}, {})
if cidv:
hlist.append('Client-ID: '+cidv)
if tokv:
Expand All @@ -562,6 +567,8 @@ def config_setup():
hlist = []
cidv = weechat.config_get_plugin('client_id')
tokv = weechat.config_get_plugin(option)
if tokv[:6] == "${sec.":
tokv = weechat.string_eval_expression(tokv, {}, {}, {})
if tokv:
hlist.append('Authorization: Bearer '+tokv)
if cidv:
Expand Down Expand Up @@ -592,6 +599,8 @@ def config_change(pointer, name, value):
curlopt['httpheader'] = x + '\n' + "Client-ID: " + value
break
if option == 'token':
if value[:6] == "${sec.":
value = weechat.string_eval_expression(value, {}, {}, {})
for x in curlopt['httpheader'].split('\n'):
if x.startswith('Client-ID:'):
curlopt['httpheader'] = x + '\n' + "Authorization: Bearer " + value
Expand Down Expand Up @@ -636,7 +645,7 @@ def config_change(pointer, name, value):
" /set plugins.var.python.twitch.ssl_verify off\n"
"\n\n"
" Required server settings:\n"
" /server add twitch irc.twitch.tv\n"
" /server add twitch irc.chat.twitch.tv\n"
" /set irc.server.twitch.capabilities \"twitch.tv/membership,twitch.tv/commands,twitch.tv/tags\"\n"
" /set irc.server.twitch.nicks \"My Twitch Username\"\n"
" /set irc.server.twitch.password \"oauth:My Oauth Key\"\n"
Expand Down

0 comments on commit 7c0acfc

Please sign in to comment.