Commit eddb7685 authored by mumixam's avatar mumixam Committed by Sébastien Helleu

twitch.py 0.8: changed input modifier hooks to use irc_in2_* instead

               added setting 'plugins.var.python.twitch.notice_notify_block'
               added setting 'plugins.var.python.twitch.client_id'
parent 183d51e4
......@@ -28,13 +28,17 @@
# plugins.var.python.twitch.prefix_nicks (default: 1)
# plugins.var.python.twitch.debug (default: 0)
# plugins.var.python.twitch.ssl_verify (default: 1)
# plugins.var.python.twitch.notice_notify_block (default: 1)
# plugins.var.python.twitch.client_id (default: awtv6n371jb7uayyc4jaljochyjbfxs)
#
# # History:
#
#
# 2019-10-13, mumixam
# v0.8: changed input modifier hooks to use irc_in2_* instead
# added setting 'plugins.var.python.twitch.notice_notify_block'
# added setting 'plugins.var.python.twitch.client_id'
# 2019-09-25, mumixam
# v0.7: updated script to use current api
#
# 2019-03-03,
# v0.6: added support for CLEARMSG -MentalFS
# fixed issue with /whois -mumixam
......@@ -54,14 +58,16 @@
SCRIPT_NAME = "twitch"
SCRIPT_AUTHOR = "mumixam"
SCRIPT_VERSION = "0.7"
SCRIPT_VERSION = "0.8"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "twitch.tv Chat Integration"
OPTIONS={
'servers': ('twitch','Name of server(s) which script will be active on, space seperated'),
'prefix_nicks': ('1','Prefix nicks based on ircv3 tags for mods/subs, This can be cpu intensive on very active chats [1 for enabled, 0 for disabled]'),
'debug': ('0','Debug mode'),
'ssl_verify': ('1', 'Verify SSL/TLS certs')
'ssl_verify': ('1', 'Verify SSL/TLS certs'),
'notice_notify_block': ('1', 'Changes notify level of NOTICEs to low'),
'client_id': ('awtv6n371jb7uayyc4jaljochyjbfxs', 'Twitch API Token')
}
......@@ -74,7 +80,7 @@ import string
import ast
curlopt = {
"httpheader": "Client-ID: awtv6n371jb7uayyc4jaljochyjbfxs",
"httpheader": "Client-ID: "+OPTIONS['client_id'][0],
"timeout": "5",
"verbose": "0",
"ssl_verifypeer": "1",
......@@ -260,7 +266,7 @@ def channel_api(data, command, rc, stdout, stderr):
rul = weechat.color("-underline")
pformat = weechat.config_string(
weechat.config_get("weechat.look.prefix_network"))
if 'total' in jsonDict:
uid = command.split('=')[-1]
name = 'WHOIS'
......@@ -498,6 +504,12 @@ def twitch_whois(data, modifier, server_name, string):
"url:" + url+params, curlopt, 7 * 1000, "channel_api", currentbuf)
return ""
def twitch_notice(data, line):
if not OPTIONS['notice_notify_block']: return string
return {"notify_level": "0"}
def config_setup():
for option,value in OPTIONS.items():
weechat.config_set_desc_plugin(option, '%s' % value[1])
......@@ -505,40 +517,45 @@ def config_setup():
weechat.config_set_plugin(option, value[0])
OPTIONS[option] = value[0]
else:
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify':
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify' or option == 'notice_notify_block':
OPTIONS[option] = weechat.config_string_to_boolean(
weechat.config_get_plugin(option))
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
else:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
else:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
else:
OPTIONS[option] = weechat.config_get_plugin(option)
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
else:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
else:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
if option == 'client_id':
curlopt['httpheader'] = "Client-ID: " + value[0]
def config_change(pointer, name, value):
option = name.replace('plugins.var.python.'+SCRIPT_NAME+'.','')
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify':
if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify' or option == 'notice_notify_block':
value=weechat.config_string_to_boolean(value)
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
if value == 1:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
if value == 1:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
if option == 'debug':
if value == 0:
curlopt['verbose'] = "0"
if value == 1:
curlopt['verbose'] = "1"
if option == 'ssl_verify':
if value == 0:
curlopt['ssl_verifypeer'] = "0"
curlopt['ssl_verifyhost'] = "0"
if value == 1:
curlopt['ssl_verifypeer'] = "1"
curlopt['ssl_verifyhost'] = "2"
if option == 'client_id':
curlopt['httpheader'] = "Client-ID: " + value
OPTIONS[option] = value
return weechat.WEECHAT_RC_OK
......@@ -551,6 +568,8 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
" plugins.var.python.twitch.prefix_nicks (default: 1)\n"
" plugins.var.python.twitch.debug (default: 0)\n"
" plugins.var.python.twitch.ssl_verify (default: 0)\n"
" plugins.var.python.twitch.notice_notify_block (default: 1)\n"
" plugins.var.python.twitch.client_id (default: awtv6n371jb7uayyc4jaljochyjbfxs)\n"
"\n\n"
" This script checks stream status of any channel on any servers listed\n"
" in the \"plugins.var.python.twitch.servers\" setting. When you switch\n"
......@@ -584,19 +603,29 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
" If you do not have a oauth token one can be generated for your account here\n"
" https://twitchapps.com/tmi/\n"
"\n"
" This script now by default limits the level of NOTICEs from twitch server\n"
" What this does is makes it so 'Now hosting' notifications are classes as a low level message\n"
" So they no longer show up in your hotlist like a 'actual' message\n"
" If you would like to disable this set the following\n"
" /set plugins.var.python.twitch.notice_notify_block 0\n"
"\n"
" If would like to use your own Client-ID it can be set with\n"
" /set plugins.var.python.twitch.client_id (clientid)\n"
"\n"
" This script also has whisper support that works like a standard query. \"/query user\"\n\n",
"", "twitch_main", "")
weechat.hook_signal('buffer_switch', 'twitch_buffer_switch', '')
weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'config_change', '')
config_setup()
weechat.hook_modifier("irc_in_CLEARCHAT", "twitch_clearchat", "")
weechat.hook_modifier("irc_in_CLEARMSG", "twitch_clearmsg", "")
weechat.hook_modifier("irc_in_RECONNECT", "twitch_reconnect", "")
weechat.hook_modifier("irc_in_USERSTATE", "twitch_suppress", "")
weechat.hook_modifier("irc_in_HOSTTARGET", "twitch_suppress", "")
weechat.hook_modifier("irc_in_ROOMSTATE", "twitch_roomstate", "")
weechat.hook_modifier("irc_in_USERNOTICE", "twitch_usernotice", "")
weechat.hook_modifier("irc_in_WHISPER", "twitch_whisper", "")
weechat.hook_line("", "", "irc_notice+nick_tmi.twitch.tv", "twitch_notice", "")
weechat.hook_modifier("irc_in2_CLEARCHAT", "twitch_clearchat", "")
weechat.hook_modifier("irc_in2_CLEARMSG", "twitch_clearmsg", "")
weechat.hook_modifier("irc_in2_RECONNECT", "twitch_reconnect", "")
weechat.hook_modifier("irc_in2_USERSTATE", "twitch_suppress", "")
weechat.hook_modifier("irc_in2_HOSTTARGET", "twitch_suppress", "")
weechat.hook_modifier("irc_in2_ROOMSTATE", "twitch_roomstate", "")
weechat.hook_modifier("irc_in2_USERNOTICE", "twitch_usernotice", "")
weechat.hook_modifier("irc_in2_WHISPER", "twitch_whisper", "")
weechat.hook_modifier("irc_out_PRIVMSG", "twitch_privmsg", "")
weechat.hook_modifier("irc_out_WHOIS", "twitch_whois", "")
weechat.hook_modifier("irc_in_PRIVMSG", "twitch_in_privmsg", "")
weechat.hook_modifier("irc_in2_PRIVMSG", "twitch_in_privmsg", "")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment