Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • weechat/scripts
1 result
Show changes
Commits on Source (4)
#
# 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
Loading
Loading
@@ -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
Loading
Loading
@@ -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;
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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'
 
Loading
Loading
@@ -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'),
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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 " +
Loading
Loading
@@ -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)))
Loading
Loading
@@ -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
Loading
Loading
@@ -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"],
Loading
Loading
@@ -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
Loading
Loading
@@ -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()
Loading
Loading
@@ -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)"
 
Loading
Loading
@@ -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)
 
Loading
Loading
@@ -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)
Loading
Loading
@@ -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)
Loading
Loading
@@ -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):
Loading
Loading
@@ -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
Loading
Loading
@@ -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.
Loading
Loading