Commit 0cb77d2e authored by Nils Görs's avatar Nils Görs

Merge branch 'master' of https://github.com/weechat/scripts

parents 14c8a810 f2ca0fef
......@@ -31,11 +31,13 @@ Then the author will send a pull request on this repository.
There are two ways to send a new release for a script:
* Send a pull request, the commit message must have the name of script,
version, and changes, like that: +
* Send a pull request (*recommended*). +
The commit message must have the name of script, version, and changes,
like that: +
`script.py 0.3: fix...` +
Please submit only one script per pull request.
* Use the form at: <https://weechat.org/scripts/update/>.
Only one script is allowed per pull request.
* Use the form at: <https://weechat.org/scripts/update/> (please use this form
only if you can not send a pull request).
When sending a new version :
......
#
# Copyright (c) 2010-2015 by Nils Görs <weechatter@arcor.de>
# Copyright (c) 2010-2017 by Nils Görs <weechatter@arcor.de>
# Copyleft (ɔ) 2013 by oakkitten
#
# colors the channel text with nick color and also highlight the whole line
......@@ -44,6 +44,7 @@
# /buffer set localvar_set_colorize_lines *yellow
# history:
# 3.5: new options "highlight_words" and "highlight_words_color" (idea by jokrebel)
# 3.4: new options "tags" and "ignore_tags"
# 3.3: use localvar "colorize_lines" for buffer related color (idea by tomoe-mami)
# 3.2: minor logic fix
......@@ -106,29 +107,33 @@
use strict;
my $PRGNAME = "colorize_lines";
my $VERSION = "3.4";
my $VERSION = "3.5";
my $AUTHOR = "Nils Görs <weechatter\@arcor.de>";
my $LICENCE = "GPL3";
my $DESCR = "Colorize users' text in chat area with their nick color, including highlights";
my %config = ("buffers" => "all", # all, channel, query
"blacklist_buffers" => "", # "a,b,c"
"lines" => "on",
"highlight" => "on", # on, off, nicks
"nicks" => "", # "d,e,f", "/file"
"own_lines" => "on", # on, off, only
"tags" => "irc_privmsg",
"ignore_tags" => "irc_ctcp",
my %config = ("buffers" => "all", # all, channel, query
"blacklist_buffers" => "", # "a,b,c"
"lines" => "on",
"highlight" => "on", # on, off, nicks
"nicks" => "", # "d,e,f", "/file"
"own_lines" => "on", # on, off, only
"tags" => "irc_privmsg",
"ignore_tags" => "irc_ctcp",
"highlight_words" => "off", # on, off
"highlight_words_color" => "black,darkgray",
);
my %help_desc = ("buffers" => "Buffer type affected by the script (all/channel/query, default: all)",
"blacklist_buffers" => "Comma-separated list of channels to be ignored (e.g. freenode.#weechat,*.#python)",
"lines" => "Apply nickname color to the lines (off/on/nicks). The latter will limit highlighting to nicknames in option 'nicks'",
"highlight" => "Apply highlight color to the highlighted lines (off/on/nicks). The latter will limit highlighting to nicknames in option 'nicks'",
"nicks" => "Comma-separater list of nicks (e.g. freenode.cat,*.dog) OR file name starting with '/' (e.g. /file.txt). In the latter case, nicknames will get loaded from that file inside weechat folder (e.g. from ~/.weechat/file.txt). Nicknames in file are newline-separated (e.g. freenode.dog\\n*.cat)",
"own_lines" => "Apply nickname color to own lines (off/on/only). The latter turns off all other kinds of coloring altogether",
"tags" => "Comma-separated list of tags to accept (see /debug tags)",
"ignore_tags" => "Comma-separated list of tags to ignore (see /debug tags)",
my %help_desc = ("buffers" => "Buffer type affected by the script (all/channel/query, default: all)",
"blacklist_buffers" => "Comma-separated list of channels to be ignored (e.g. freenode.#weechat,*.#python)",
"lines" => "Apply nickname color to the lines (off/on/nicks). The latter will limit highlighting to nicknames in option 'nicks'",
"highlight" => "Apply highlight color to the highlighted lines (off/on/nicks). The latter will limit highlighting to nicknames in option 'nicks'",
"nicks" => "Comma-separater list of nicks (e.g. freenode.cat,*.dog) OR file name starting with '/' (e.g. /file.txt). In the latter case, nicknames will get loaded from that file inside weechat folder (e.g. from ~/.weechat/file.txt). Nicknames in file are newline-separated (e.g. freenode.dog\\n*.cat)",
"own_lines" => "Apply nickname color to own lines (off/on/only). The latter turns off all other kinds of coloring altogether",
"tags" => "Comma-separated list of tags to accept (see /debug tags)",
"ignore_tags" => "Comma-separated list of tags to ignore (see /debug tags)",
"highlight_words" => "highlight word(s) in text, matching word(s) in weechat.look.highlight",
"highlight_words_color" => "color for highlight word in text (fg:bg)",
);
my @ignore_tags_array;
......@@ -223,12 +228,41 @@ sub colorize_cb
$color = $channel_color if ($channel_color);
} else {
# oh well
return $string;
return $string if ($config{highlight_words} ne "on");
}
}
my $right_nocolor = weechat::string_remove_color($right, "");
if ((
$config{highlight_words} eq "on"
) && ($my_nick ne $nick) && (
weechat::string_has_highlight($right_nocolor, weechat::config_string(weechat::config_get("weechat.look.highlight")))
))
{
my $high_word_color = weechat::color(weechat::config_get_plugin("highlight_words_color"));
my $reset = weechat::color('reset');
my @highlight_array = split(/,/,weechat::config_string(weechat::config_get("weechat.look.highlight")));
my @line_array = split(/ /,$right);
foreach my $l (@line_array) {
foreach my $h (@highlight_array) {
my $i = $h;
# check word case insensitiv || check if word matches without "(?-i)" at beginning
if ( lc($l) eq lc($h) || (index($h,"(?-i)") != -1 && ($l eq substr($i,5,length($i)-5,""))) ) {
$right =~ s/\Q$l\E/$high_word_color$l$reset/;
# word starts with (?-i) and has a wildcard ?
} elsif ((index($h,"(?-i)") != -1) && (index($h,"*") != -1) ){
my $i = $h;
my $t = substr($i,5,length($i)-5,"");
my $regex = weechat::string_mask_to_regex($t);
$right =~ s/\Q$l\E/$high_word_color$l$reset/ if ($l =~ /^$regex$/i); # use * without sensitive
}elsif ((index($h,"*") == 0 || index($h,"*") == length($h)-1)){# wildcard at beginning or end ?
my $regex = weechat::string_mask_to_regex($h);
$right =~ s/\Q$l\E/$high_word_color$l$reset/ if ($l =~ /^$regex$/i);
}
}
}
}
######################################## inject colors and go!
my $out = "";
if ($action) {
# remove the first color reset - after * nick
......
This diff is collapsed.
......@@ -17,6 +17,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 2017-12-14: Sébastien Helleu <flashcode@flashtux.org>
# 0.6 : rename command "/autosetbuffer" by "/buffer_autoset" in example
#
# 2015-04-05: nils_2 (freenode.#weechat)
# 0.5 : change priority of hook_signal('buffer_opened') to 100
#
......@@ -49,7 +52,7 @@ except Exception:
SCRIPT_NAME = 'histman'
SCRIPT_AUTHOR = 'nils_2 <weechatter@arcor.de>'
SCRIPT_VERSION = '0.5'
SCRIPT_VERSION = '0.6'
SCRIPT_LICENSE = 'GPL'
SCRIPT_DESC = 'save and restore global and/or buffer command history'
......@@ -395,9 +398,9 @@ if __name__ == '__main__':
' save the command history manually (for example with /cron script):\n'
' /' + SCRIPT_NAME + ' save\n'
' save and restore command history for buffer #weechat on freenode (text only):\n'
' /autosetbuffer add irc.freenode.#weechat localvar_set_save_history text\n'
' /buffer_autoset add irc.freenode.#weechat localvar_set_save_history text\n'
' save and restore command history for weechat core buffer (commands only):\n'
' /autosetbuffer add core.weechat localvar_set_save_history command\n',
' /buffer_autoset add core.weechat localvar_set_save_history command\n',
'save %-'
'|| list %-',
'histman_cmd_cb', '')
......
......@@ -12,7 +12,7 @@ import json
SCRIPT_NAME = 'mqtt_notify'
SCRIPT_AUTHOR = 'Guillaume Subiron <maethor@subiron.org>'
SCRIPT_VERSION = '0.1'
SCRIPT_VERSION = '0.2'
SCRIPT_LICENSE = 'WTFPL'
SCRIPT_DESC = 'Sends notifications using MQTT'
......@@ -44,7 +44,7 @@ def on_msg(*a):
msg['buffer'] = w.buffer_get_string(msg['buffer'], 'short_name')
cli = mqtt.Client()
if w.config.get_plugin('mqtt_user'):
if w.config_get_plugin('mqtt_user'):
cli.username_pw_set(w.config_get_plugin('mqtt_user'),
password=w.config_get_plugin('mqtt_password'))
cli.connect(w.config_get_plugin('mqtt_host'),
......
......@@ -2,9 +2,9 @@ import weechat as w
SCRIPT_NAME = "noirccolors"
SCRIPT_AUTHOR = "Fredrick Brennan <fredrick.brennan1@gmail.com>"
SCRIPT_VERSION = "0.2"
SCRIPT_VERSION = "0.3"
SCRIPT_LICENSE = "Public domain"
SCRIPT_DESC = "Remove IRC colors from buffers with the localvar 'noirccolors' set. To disable IRC colors in the current buffer, type /buffer set localvar_set_noirccolors true. You can also set this with autosetbuffer. :)"
SCRIPT_DESC = "Remove IRC colors from buffers with the localvar 'noirccolors' set. To disable IRC colors in the current buffer, type /buffer set localvar_set_noirccolors true. You can also set this with script buffer_autoset.py. :)"
w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '')
......
......@@ -24,6 +24,10 @@
# (this script requires WeeChat 0.3.0 or newer)
#
# History:
# 2017-11-20, Nils Görs <weechatter@arcor.de>
# version 0.15: make script python3 compatible
# : fix problem with empty "command_on_*" options
# : add option "no_output"
# 2014-08-02, Nils Görs <weechatter@arcor.de>
# version 0.14: add time to detach message. (idea by Mikaela)
# 2014-06-19, Anders Bergh <anders1@gmail.com>
......@@ -66,7 +70,7 @@ import datetime, time
SCRIPT_NAME = "screen_away"
SCRIPT_AUTHOR = "xt <xt@bash.no>"
SCRIPT_VERSION = "0.14"
SCRIPT_VERSION = "0.15"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Set away status on screen detach"
......@@ -80,6 +84,7 @@ settings = {
'ignore': ('', 'Comma-separated list of servers to ignore.'),
'set_away': ('on', 'Set user as away.'),
'ignore_relays': ('off', 'Only check screen status and ignore relay interfaces'),
'no_output': ('off','no detach/attach information will be displayed in buffer'),
}
TIMER = None
......@@ -144,7 +149,8 @@ def screen_away_timer_cb(buffer, args):
w.infolist_free(infolist)
if (attached and AWAY) or (check_relays and CONNECTED_RELAY and not attached and AWAY):
w.prnt('', '%s: Screen attached. Clearing away status' % SCRIPT_NAME)
if not w.config_string_to_boolean(w.config_get_plugin('no_output')):
w.prnt('', '%s: Screen attached. Clearing away status' % SCRIPT_NAME)
for server, nick in get_servers():
if set_away:
w.command(server, "/away")
......@@ -152,20 +158,23 @@ def screen_away_timer_cb(buffer, args):
nick = nick[:-len(suffix)]
w.command(server, "/nick %s" % nick)
AWAY = False
for cmd in w.config_get_plugin("command_on_attach").split(";"):
w.command("", cmd)
if w.config_get_plugin("command_on_attach"):
for cmd in w.config_get_plugin("command_on_attach").split(";"):
w.command("", cmd)
elif not attached and not AWAY:
if not CONNECTED_RELAY:
w.prnt('', '%s: Screen detached. Setting away status' % SCRIPT_NAME)
if not w.config_string_to_boolean(w.config_get_plugin('no_output')):
w.prnt('', '%s: Screen detached. Setting away status' % SCRIPT_NAME)
for server, nick in get_servers():
if suffix and not nick.endswith(suffix):
w.command(server, "/nick %s%s" % (nick, suffix));
if set_away:
w.command(server, "/away %s %s" % (w.config_get_plugin('message'), time.strftime(w.config_get_plugin('time_format'))))
AWAY = True
for cmd in w.config_get_plugin("command_on_detach").split(";"):
w.command("", cmd)
if w.config_get_plugin("command_on_detach"):
for cmd in w.config_get_plugin("command_on_detach").split(";"):
w.command("", cmd)
return w.WEECHAT_RC_OK
......@@ -173,7 +182,7 @@ def screen_away_timer_cb(buffer, args):
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
version = w.info_get('version_number', '') or 0
for option, default_desc in settings.iteritems():
for option, default_desc in settings.items():
if not w.config_is_set_plugin(option):
w.config_set_plugin(option, default_desc[0])
if int(version) >= 0x00030500:
......
......@@ -20,6 +20,9 @@
#
# idea by shad0VV@freenode.#weechat
#
# 2017-12-14: Sébastien Helleu <flashcode@flashtux.org>
# 0.6 : rename command "/autosetbuffer" by "/buffer_autoset" in example
#
# 2017-04-02: nils_2, (freenode.#weechat)
# 0.5 : support of "/input jump_smart" and "/buffer +/-" (reported: squigz)
#
......@@ -52,7 +55,7 @@ except Exception:
SCRIPT_NAME = "stick_buffer"
SCRIPT_AUTHOR = "nils_2 <weechatter@arcor.de>"
SCRIPT_VERSION = "0.5"
SCRIPT_VERSION = "0.6"
SCRIPT_LICENSE = "GPL"
SCRIPT_DESC = "Stick buffers to particular windows, like irssi"
......@@ -239,7 +242,7 @@ Examples:
Stick buffer #weechat to window 2:
/buffer #weechat
/buffer set localvar_set_stick_buffer_to_window 2
/autosetbuffer add irc.freenode.#weechat stick_buffer_to_window 2
/buffer_autoset add irc.freenode.#weechat stick_buffer_to_window 2
Set the default stick-to window to window 5:
/set plugins.var.python.{script_name}.default_stick_window 5
List buffers with persistent stickiness:
......
......@@ -26,9 +26,12 @@
# settings:
# plugins.var.python.twitch.servers (default: twitch)
# plugins.var.python.twitch.prefix_nicks (default: 1)
# plugins.var.python.twitch.debug (default: 0)
#
# # History:
#
# 2017-11-02, mumixam
# v0.4: added debug mode for API calls, minor bugfixes
# 2017-06-10, mumixam
# v0.3: fixed whois output of utf8 display names
# 2016-11-03, mumixam
......@@ -40,12 +43,13 @@
SCRIPT_NAME = "twitch"
SCRIPT_AUTHOR = "mumixam"
SCRIPT_VERSION = "0.3"
SCRIPT_VERSION = "0.4"
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]')
'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')
}
......@@ -59,7 +63,7 @@ import ast
clientid='awtv6n371jb7uayyc4jaljochyjbfxs'
params = '?client_id='+clientid
curlopt = {"timeout": "5"}
def days_hours_minutes(td):
age = ''
hours = td.seconds // 3600
......@@ -82,8 +86,8 @@ def twitch_main(data, buffer, args):
if not (server in OPTIONS['servers'].split() and type == 'channel'):
return weechat.WEECHAT_RC_OK
url = 'https://api.twitch.tv/kraken/streams/' + username
url_hook_process = weechat.hook_process(
"url:" + url+params, 7 * 1000, "stream_api", buffer)
weechat.hook_process_hashtable(
"url:" + url+params, curlopt, 7 * 1000, "stream_api", buffer)
return weechat.WEECHAT_RC_OK
......@@ -114,7 +118,12 @@ def channel_api(data, command, rc, stdout, stderr):
try:
jsonDict = json.loads(stdout.strip())
except Exception as e:
weechat.prnt(data['buffer'], 'TWITCH: Error with twitch API')
weechat.prnt(data['buffer'], '%stwitch.py: error communicating with twitch api' % weechat.prefix('error'))
if OPTIONS['debug']:
weechat.prnt(data['buffer'],'%stwitch.py: return code: %s' % (weechat.prefix('error'),rc))
weechat.prnt(data['buffer'],'%stwitch.py: stdout: %s' % (weechat.prefix('error'),stdout))
weechat.prnt(data['buffer'],'%stwitch.py: stderr: %s' % (weechat.prefix('error'),stderr))
weechat.prnt(data['buffer'],'%stwitch.py: exception: %s' % (weechat.prefix('error'),e))
return weechat.WEECHAT_RC_OK
currentbuf = weechat.current_buffer()
name = data['name']
......@@ -144,8 +153,8 @@ def channel_api(data, command, rc, stdout, stderr):
weechat.prnt(data['buffer'], makeutf8(output))
url = 'https://api.twitch.tv/kraken/users/' + \
name.lower() + '/follows/channels'
urlh = weechat.hook_process(
"url:" + url+params, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': name, 'dname': dname}))
weechat.hook_process_hashtable(
"url:" + url+params, curlopt, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': name, 'dname': dname}))
if len(jsonDict) == 18:
dname = jsonDict['display_name']
......@@ -168,8 +177,8 @@ def channel_api(data, command, rc, stdout, stderr):
pcolor, pformat, dcolor, ncolor, user, dcolor, ccolor))
else:
url = 'https://api.twitch.tv/api/channels/' + data['name'].lower()
urlh = weechat.hook_process(
"url:" + url+params, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': name, 'dname': data['name']}))
weechat.hook_process_hashtable(
"url:" + url+params, curlopt, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': name, 'dname': data['name']}))
count = jsonDict['_total']
if count:
output = '%s%s %s[%s%s%s]%s %sFollowing%s: %s' % (
......@@ -182,7 +191,12 @@ def stream_api(data, command, rc, stdout, stderr):
try:
jsonDict = json.loads(stdout.strip())
except Exception as e:
weechat.prnt(data, 'TWITCH: Error with twitch API')
weechat.prnt(data, '%stwitch.py: error communicating with twitch api' % weechat.prefix('error'))
if OPTIONS['debug']:
weechat.prnt(data,'%stwitch.py: return code: %s' % (weechat.prefix('error'),rc))
weechat.prnt(data,'%stwitch.py: stdout: %s' % (weechat.prefix('error'),stdout))
weechat.prnt(data,'%stwitch.py: stderr: %s' % (weechat.prefix('error'),stderr))
weechat.prnt(data,'%stwitch.py: exception: %s' % (weechat.prefix('error'),e))
return weechat.WEECHAT_RC_OK
currentbuf = weechat.current_buffer()
title_fg = weechat.color(
......@@ -206,7 +220,7 @@ def stream_api(data, command, rc, stdout, stderr):
weechat.prnt(data, 'ERROR: The page could not be found, or has been deleted by its owner.')
return weechat.WEECHAT_RC_OK
if not 'stream' in jsonDict.keys():
weechat.prnt(data, 'TWITCH: Error with twitch API')
weechat.prnt(data, 'twitch.py: Error with twitch API (stream key missing from json)')
return weechat.WEECHAT_RC_OK
if not jsonDict['stream']:
line = "STREAM: %sOFFLINE%s %sCHECKED AT: %s" % (
......@@ -291,7 +305,7 @@ def twitch_clearchat(data, modifier, modifier_data, string):
rul = weechat.color("-underline")
if user:
if 'ban-duration' in tags:
if tags['ban-reason']:
if 'ban-reason' in tags and tags['ban-reason']:
bn=tags['ban-reason'].replace('\s',' ')
weechat.prnt(buffer,"%s--%s %s has been timed out for %s seconds %sReason%s: %s" %
(pcolor, ccolor, user, tags['ban-duration'], ul, rul, bn))
......@@ -402,7 +416,7 @@ def twitch_privmsg(data, modifier, server_name, string):
'irc_message_parse', {"message": string})
if message['channel'].startswith('#'):
return string
newmsg = 'PRIVMSG jtv :.w ' + message['nick'] + ' ' + message['text']
newmsg = 'PRIVMSG #%s :/w %s %s' % (message['nick'],message['nick'],message['text'])
return newmsg
......@@ -438,8 +452,8 @@ def twitch_whois(data, modifier, server_name, string):
username = msg['nick'].lower()
currentbuf = weechat.current_buffer()
url = 'https://api.twitch.tv/kraken/channels/' + username
url_hook = weechat.hook_process(
"url:" + url+params, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': username}))
url_hook = weechat.hook_process_hashtable(
"url:" + url+params, curlopt, 7 * 1000, "channel_api", str({'buffer': currentbuf, 'name': username}))
return ""
def config_setup():
......@@ -449,7 +463,7 @@ def config_setup():
weechat.config_set_plugin(option, value[0])
OPTIONS[option] = value[0]
else:
if option == 'prefix_nicks':
if option == 'prefix_nicks' or option == 'debug':
OPTIONS[option] = weechat.config_string_to_boolean(
weechat.config_get_plugin(option))
else:
......@@ -457,7 +471,7 @@ def config_setup():
def config_change(pointer, name, value):
option = name.replace('plugins.var.python.'+SCRIPT_NAME+'.','')
if option == 'prefix_nicks':
if option == 'prefix_nicks' or option == 'debug':
value=weechat.config_string_to_boolean(value)
OPTIONS[option] = value
return weechat.WEECHAT_RC_OK
......@@ -469,6 +483,7 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
" settings:\n"
" plugins.var.python.twitch.servers (default: twitch)\n"
" plugins.var.python.twitch.prefix_nicks (default: 1)\n"
" plugins.var.python.twitch.debug (default: 0)\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"
......@@ -482,12 +497,15 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
"\n\n"
" This script also will prefix users nicks (@ for mod, % for sub,\n"
" and ~ for broadcaster). This will break the traditional function\n"
" of /ignore add nightbot and will require you to prefix nicks if you\n"
" want to ignore someone /ignore add re:[~@%]{0,3}nightbot should ignore\n"
" of `/ignore add nightbot` and will require you to prefix nicks if you\n"
" want to ignore someone `/ignore add re:[~@%]{0,3}nightbot` should ignore\n"
" a nick with all or none of the prefixes used by this script.\n"
" NOTE: This may cause high cpu usage in very active chat and/or on slower cpus.\n"
" This can also be disabled by setting\n /set plugins.var.python.twitch.prefix_nicks off\n"
"\n\n"
" If you are experiencing errors you can enable debug mode by setting\n"
" /set plugins.var.python.twitch.debug on\n"
"\n\n"
" Required server settings:\n"
" /server add twitch irc.twitch.tv\n"
" /set irc.server.twitch.capabilities \"twitch.tv/membership,twitch.tv/commands,twitch.tv/tags\"\n"
......
......@@ -26,7 +26,7 @@ import re
SCRIPT_NAME = 'unhighlight'
SCRIPT_AUTHOR = 'xiagu'
SCRIPT_VERSION = '0.1.0'
SCRIPT_VERSION = '0.1.1'
SCRIPT_LICENSE = 'GPL3'
SCRIPT_DESC = 'Allows per-buffer specification of a regex that prevents highlights.'
......@@ -93,7 +93,7 @@ Examples:
Unhighlight SASL authentication messages for double logins:
/buffer weechat
/buffer set localvar_set_unhighlight_regex SaslServ
/autosetbuffer add core.weechat localvar_set_unhighlight_regex SaslServ
/buffer_autoset add core.weechat localvar_set_unhighlight_regex SaslServ
List buffers with autoset unhighlights:
/{script_name} list
Show this help:
......
......@@ -24,6 +24,7 @@ import tempfile
import time
import calendar
import socket
import getpass
# This twitter plugin can be extended even more. Just look at the twitter api
# doc here: https://dev.twitter.com/docs/api/1.1
......@@ -119,7 +120,7 @@ desc_dict = dict(
"of the user that you reply to in the tweet text. If this is not " +
"the case this will be treated like a normal tweet instead.",
new_tweets="Get new tweets from your home_timeline. This is only " +
"useful if you have disabled the auto updater",
"useful if you have disconnected from the home twitter stream",
follow_user="<user>, Add user to people you follow",
unfollow_user="<user>, Remove user for people you follow",
following="[|<id>|<user>|<user> <id>], Show 'friends' of <user> or " +
......@@ -337,6 +338,12 @@ def stream_message(buffer,tweet):
#TODO make the event printing better
weechat.prnt_date_tags(buffer, 0, "no_highlight", "%s%s" % (weechat.prefix("network"),
tweet['source']['screen_name'] + " " + event_str + " " + tweet['target']['screen_name'] + extra_str))
elif 'friends' in tweet:
#This should be the initital message you get listing friend ids when connecting to the twitter stream
weechat.prnt(buffer, "%s%s" % (weechat.prefix("network"), "Connected to twitter streaming API."))
#Get new tweets since the last update (we might have missed some if this is after a reconnect)
#Get latest tweets from timeline
my_command_cb("silent", buffer, "new")
else:
weechat.prnt(buffer, "%s%s" % (weechat.prefix("network"),
"recv stream data: " + str(tweet)))
......@@ -344,7 +351,7 @@ def stream_message(buffer,tweet):
def twitter_stream_cb(buffer,fd):
#accept connection
server = sock_fd_dict[sock_fd_dict[fd]]
server = sock_fd_dict[ sock_fd_dict[str(fd)] ]
conn, addr = server.accept()
tweet = ""
data = True
......@@ -371,7 +378,7 @@ def twitter_stream_cb(buffer,fd):
#We need to send over the stream options
options = dict(screen_name = script_options['screen_name'],
name = sock_fd_dict[fd],
name = sock_fd_dict[str(fd)],
alt_rt_style = int(script_options['alt_rt_style']),
home_replies = int(script_options['home_replies']),
token = script_options["oauth_token"],
......@@ -442,10 +449,11 @@ def twitter_stream(cmd_args):
# configuration. So it's defined here if the defaults change.
stream_options = dict( timeout=None, block=True, heartbeat_timeout=90 )
# Reconnect timer, when zero it will not try to reconnect
re_timer = 1
# Reconnect timer list [1sec, 5sec, 10sec, 1min, 2min]
re_timer = [1,2,10,60,120]
re_timer_idx = 0
while re_timer:
while True:
try:
if name == "twitter":
#home timeline stream
......@@ -504,8 +512,8 @@ def twitter_stream(cmd_args):
client.sendall(bytes(str(tweet),"utf-8"))
client.close()
stream_end_message = "Text message"
# Reset the reconnect timer when we get a new message
re_timer = 1
# Reset the reconnect timer index when we get a new message
re_timer_idx = 0
else:
#Got a other type of message
client = connect()
......@@ -514,14 +522,12 @@ def twitter_stream(cmd_args):
stream_end_message = "Unhandled type message"
client = connect()
client.sendall(bytes('"Disconnected, trying to reconnect."',"utf-8"))
client.sendall(bytes('"Disconnected, trying to reconnect in {0} sec. Reason: {1}"'.format(re_timer[re_timer_idx], stream_end_message),"utf-8"))
client.close()
if re_timer > 5:
re_timer = 0
else:
time.sleep(re_timer)
re_timer += 4
time.sleep(re_timer[re_timer_idx])
if re_timer_idx < (len(re_timer) - 1):
re_timer_idx += 1
return "Stream shut down after: " + stream_end_message + ". You'll have to restart the stream manually. (:re_home, if home stream)"
......@@ -558,7 +564,7 @@ def create_stream(name, args = ""):
setup_buffer(buffer)
if not sock_fd_dict.get(name):
file_name = tempfile.gettempdir() + "/we_tw_" + name
file_name = tempfile.gettempdir() + "/we_tw_" + getpass.getuser() + "_" + name
if os.path.exists(file_name):
os.remove(file_name)
......@@ -1161,8 +1167,6 @@ def oauth_proc_cb(data, command, rc, out, err):
for nick in process_output:
add_to_nicklist(buffer,nick)
#Get latest tweets from timeline
my_command_cb("silent", buffer, "new")
elif data == "auth1":
#First auth step to request pin code
oauth_token, oauth_token_secret = parse_oauth_tokens(out)
......@@ -1237,13 +1241,13 @@ def finish_init():
return
setup_buffer(buffer)
#Add friends to nick list and print new tweets
#Add friends to nick list
weechat.hook_process("python3 " + SCRIPT_FILE_PATH + " " +
script_options["oauth_token"] + " " + script_options["oauth_secret"] + " " +
"f " + script_options['screen_name'] + " []", 10 * 1000, "oauth_proc_cb", "friends")
if __name__ == "__main__" and weechat_call:
weechat.register( SCRIPT_NAME , "DarkDefender", "1.2.6", "GPL3", "Weechat twitter client", "", "")
weechat.register( SCRIPT_NAME , "DarkDefender", "1.2.7", "GPL3", "Weechat twitter client", "", "")
if not import_ok:
weechat.prnt("", "Can't load twitter python lib >= " + required_twitter_version)
......@@ -1251,7 +1255,7 @@ if __name__ == "__main__" and weechat_call:
else:
hook_commands_and_completions()
# Set register script options if not available
#Set register script options if not available
for option, default_value in script_options.items():
if not weechat.config_is_set_plugin(option):
......@@ -1263,11 +1267,10 @@ if __name__ == "__main__" and weechat_call:
weechat.config_set_plugin(option, default_value)
read_config()
# hook for config changes
#Hook for config changes
weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_cb", "")
# create buffer
#Create buffer
twit_buf = weechat.buffer_new("twitter", "buffer_input_cb", "", "buffer_close_cb", "")
#Hook text input so we can update the bar item
......@@ -1275,7 +1278,8 @@ if __name__ == "__main__" and weechat_call:
if script_options['auth_complete']:
finish_init()
#create home_timeline stream
#Create home_timeline stream.
#This will indirectly trigger the ":new" command if stream sucessfully starts
create_stream("twitter")
else:
weechat.prnt(twit_buf,"""You have to register this plugin with twitter for it to work.
......
# coding: utf-8
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Kengo Tateishi <embrace.ddd.flake.peace@gmail.com>
# https://github.com/tkengo/weechat-url-hinter
......@@ -35,7 +35,7 @@ require 'singleton'
# Register url-hinter plugin to weechat and do initialization.
#
def weechat_init
Weechat.register('url_hinter', 'Kengo Tateish', '0.4', 'GPL3', 'Open an url in the weechat buffer to type a hint', '', '')
Weechat.register('url_hinter', 'Kengo Tateish', '0.41', 'GPL3', 'Open an url in the weechat buffer to type a hint', '', '')
Weechat.hook_command(
'url_hinter',
'Search url strings, and highlight them, and if you type a hint key, open the url related to hint key.',
......@@ -192,7 +192,7 @@ class Hint
private
def get_hint_keys
option = 'hintkeys'
option = 'hintkeys'
if Weechat.config_is_set_plugin(option) == 0
Weechat.config_set_plugin(option, 'jfhkgyuiopqwertnmzxcvblasd')
end
......@@ -350,7 +350,9 @@ class Line
end
def remove_color_message
Weechat.string_remove_color(message.dup, '')
ret = Weechat.string_remove_color(message.dup, '')
ret.force_encoding("UTF-8")
return ret
end
def next
......
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