summaryrefslogtreecommitdiffstats
path: root/weechat
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-10-27 23:54:08 -0400
committerJesse Luehrs <doy@tozt.net>2013-10-27 23:57:33 -0400
commit647e000e0d5021d7684ade725599ad78634f8ad4 (patch)
tree7d24ca7137e517e501a590e055bc1e51cd2ad663 /weechat
parentdad82f6d1eaf565300fc6833f6da43b2f1097801 (diff)
downloadconf-647e000e0d5021d7684ade725599ad78634f8ad4.tar.gz
conf-647e000e0d5021d7684ade725599ad78634f8ad4.zip
update some things from their external sources
Diffstat (limited to 'weechat')
-rw-r--r--weechat/perl/autoload/buffers.pl152
-rw-r--r--weechat/perl/autoload/chatters.pl27
-rw-r--r--weechat/python/autoload/bitlbee_typing_notice.py162
3 files changed, 238 insertions, 103 deletions
diff --git a/weechat/perl/autoload/buffers.pl b/weechat/perl/autoload/buffers.pl
index 447777f..e2b49e5 100644
--- a/weechat/perl/autoload/buffers.pl
+++ b/weechat/perl/autoload/buffers.pl
@@ -1,6 +1,6 @@
#
-# Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org>
-# Copyright (C) 2011-2012 Nils G <weechatter@arcor.de>
+# Copyright (C) 2008-2013 Sebastien Helleu <flashcode@flashtux.org>
+# Copyright (C) 2011-2013 Nils G <weechatter@arcor.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,7 +19,11 @@
# Display sidebar with list of buffers.
#
# History:
-#
+# 2013-10-20, nils_2@freenode.#weechat:
+# v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
+# 2013-09-27, nils_2@freenode.#weechat:
+# v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
+# : fix problem with linefeed at end of list of buffers (reported by grawity)
# 2012-10-18, nils_2@freenode.#weechat:
# v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
# : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
@@ -134,7 +138,8 @@
use strict;
use Encode qw( decode encode );
# -------------------------------[ internal ]-------------------------------------
-my $version = "3.8";
+my $SCRIPT_NAME = "buffers";
+my $version = "4.0";
my $BUFFERS_CONFIG_FILE_NAME = "buffers";
my $buffers_config_file;
@@ -152,26 +157,33 @@ my %buffers_timer = ();
my %Hooks = ();
# --------------------------------[ init ]--------------------------------------
-weechat::register("buffers", "Sebastien Helleu <flashcode\@flashtux.org>", $version,
- "GPL3", "Sidebar with list of buffers", "", "");
+weechat::register($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>", $version,
+ "GPL3", "Sidebar with list of buffers", "shutdown_cb", "");
my $weechat_version = weechat::info_get("version_number", "") || 0;
buffers_config_init();
buffers_config_read();
-weechat::bar_item_new("buffers", "build_buffers", "");
-weechat::bar_new("buffers", "0", "0", "root", "", "left", "horizontal",
+weechat::bar_item_new($SCRIPT_NAME, "build_buffers", "");
+weechat::bar_new($SCRIPT_NAME, "0", "0", "root", "", "left", "horizontal",
"vertical", "0", "0", "default", "default", "default", "1",
- "buffers");
+ $SCRIPT_NAME);
+
+if ( check_bar_item() == 0 )
+{
+ weechat::command("","/bar show " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
+}
+
weechat::hook_signal("buffer_*", "buffers_signal_buffer", "");
weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
weechat::hook_signal("hotlist_*", "buffers_signal_hotlist", "");
-weechat::hook_signal("window_switch", "buffers_signal_buffer", "");
#weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
-weechat::bar_item_update("buffers");
+weechat::bar_item_update($SCRIPT_NAME);
+
+
if ($weechat_version >= 0x00030600)
{
- weechat::hook_focus("buffers", "buffers_focus_buffers", "");
+ weechat::hook_focus($SCRIPT_NAME, "buffers_focus_buffers", "");
weechat::hook_hsignal("buffers_mouse", "buffers_hsignal_mouse", "");
weechat::key_bind("mouse", \%mouse_keys);
}
@@ -206,10 +218,13 @@ weechat::hook_command( $cmd_buffers_detach,
if ($weechat_version >= 0x00030800)
{
weechat::hook_config("buffers.look.detach", "hook_timer_detach", "");
+ $Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_buffer", "") if ( weechat::config_integer( $options{"detach"}) > 0 );
}
weechat::hook_config("buffers.look.show_lag", "hook_timer_lag", "");
+ $Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "") if ( weechat::config_boolean($options{"show_lag"}) );
+
# -------------------------------- [ command ] --------------------------------
sub buffers_cmd_whitelist
{
@@ -287,6 +302,7 @@ my ( $data, $buffer, $args ) = @_;
}
return weechat::WEECHAT_RC_OK;
}
+
sub create_whitelist
{
my @buffers_list = @{$_[0]};
@@ -313,7 +329,7 @@ sub hook_timer_detach
weechat::unhook($Hooks{timer_detach}) if $Hooks{timer_detach};
$Hooks{timer_detach} = weechat::hook_timer( weechat::config_integer( $options{"detach"}) * 1000, 60, 0, "buffers_signal_buffer", "");
}
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
@@ -330,7 +346,7 @@ sub hook_timer_lag
weechat::unhook($Hooks{timer_lag}) if $Hooks{timer_lag};
$Hooks{timer_lag} = weechat::hook_timer( weechat::config_integer(weechat::config_get("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
}
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
@@ -398,19 +414,23 @@ my %default_options_look =
"indenting_number" => ["indenting_number", "boolean", "use indenting for numbers. This option only takes effect if bar is left/right positioned", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
"short_names" => ["short_names", "boolean", "display short names (remove text before first \".\" in buffer name)", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
"show_number" => ["show_number", "boolean", "display channel number in front of buffername", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_number_char" => ["number_char", "string", "display a char after channel number", "", 0, 0,".", ".", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_prefix" => ["prefix", "boolean", "show your prefix for channel", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
- "show_prefix_empty" => ["prefix_empty", "boolean", "use a placeholder for channels without prefix", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
+ "show_number_char" => ["number_char", "string", "display a char behind channel number", "", 0, 0,".", ".", 0, "", "", "buffers_signal_config", "", "", ""],
+ "show_prefix" => ["prefix", "boolean", "displays your prefix for channel in front of buffername", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
+ "show_prefix_empty" => ["prefix_empty", "boolean", "use a placeholder for channels without prefix", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
+"show_prefix_query" => ["prefix_for_query", "string", "prefix displayed in front of query buffer", "", 0, 0,"", "", 0, "", "", "buffers_signal_config", "", "", ""],
"sort" => ["sort", "integer", "sort buffer-list by \"number\" or \"name\"", "number|name", 0, 0,"number", "number", 0, "", "", "buffers_signal_config", "", "", ""],
"core_to_front" => ["core_to_front", "boolean", "core buffer and buffers with free content will be listed first. Take only effect if buffer sort is by name", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
"jump_prev_next_visited_buffer" => ["jump_prev_next_visited_buffer", "boolean", "jump to previously or next visited buffer if you click with left/right mouse button on currently visiting buffer", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
"name_size_max" => ["name_size_max","integer","maximum size of buffer name. 0 means no limitation","",0,256,0,0,0, "", "", "buffers_signal_config", "", "", ""],
"name_crop_suffix" => ["name_crop_suffix","string","contains an optional char(s) that is appended when buffer name is shortened","",0,0,"+","+",0,"","","buffers_signal_config", "", "", ""],
- "detach" => ["detach", "integer","detach channel from buffers list after a specific period of time (in seconds) without action (weechat ≥ 0.3.8 required)", "", 0, 31536000,0, "number", 0, "", "", "buffers_signal_config", "", "", ""],
+ "detach" => ["detach", "integer","detach channel from buffers list after a specific period of time (in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")", "", 0, 31536000,0, "number", 0, "", "", "buffers_signal_config", "", "", ""],
"immune_detach_buffers"=> ["immune_detach_buffers", "string", "Comma seperated list of buffers to NOT automatically detatch. Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"", "", 0, 0,"", "", 0, "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""],
"detach_query" => ["detach_query", "boolean", "query buffer will be detachted", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
"detach_free_content" => ["detach_free_content", "boolean", "buffers with free content will be detached (Ex: iset, chanmon)", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
+ "detach_displayed_buffers" => ["detach_displayed_buffers", "boolean", "buffers displayed in a (split) window will be detached", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
+ "detach_display_window_number" => ["detach_display_window_number", "boolean", "window number will be add, behind buffer name (this option takes only effect with \"detach_displayed_buffers\" option)", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
"mark_inactive" => ["mark_inactive", "boolean", "if option is \"on\", inactive buffers (those you are not in) will have parentesis around them. An inactive buffer will not be detached.", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
+ "toggle_bar" => ["toogle_bar", "boolean", "if option is \"on\", buffers bar will hide/show when script is (un)loaded.", "", 0, 0,"on","on", 0, "", "", "buffers_signal_config", "", "", ""],
);
# section "color"
my $section_color = weechat::config_new_section($buffers_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
@@ -443,7 +463,8 @@ my %default_options_look =
$default_options_look{$option}[3],$default_options_look{$option}[4],$default_options_look{$option}[5],
$default_options_look{$option}[6],$default_options_look{$option}[7],$default_options_look{$option}[8],
$default_options_look{$option}[9],$default_options_look{$option}[10],$default_options_look{$option}[11],
- $default_options_look{$option}[12],$default_options_look{$option}[13],$default_options_look{$option}[14]);
+ $default_options_look{$option}[12],$default_options_look{$option}[13],$default_options_look{$option}[14],
+ $default_options_look{$option}[15]);
}
}
@@ -515,6 +536,7 @@ sub build_buffers
$buffer->{"number"} = $number;
$buffer->{"active"} = $active;
$buffer->{"current_buffer"} = weechat::infolist_integer($infolist, "current_buffer");
+ $buffer->{"num_displayed"} = weechat::infolist_integer($infolist, "num_displayed");
$buffer->{"plugin_name"} = weechat::infolist_string($infolist, "plugin_name");
$buffer->{"name"} = weechat::infolist_string($infolist, "name");
$buffer->{"short_name"} = weechat::infolist_string($infolist, "short_name");
@@ -593,6 +615,31 @@ sub build_buffers
push(@current1, $buffer);
}
}
+ elsif ( $buffer->{"current_buffer"} eq 0
+ and not exists $hotlist{$buffer->{"pointer"}}
+# and $buffer->{"type"} eq "channel"
+ and exists $buffers_timer{$buffer->{"pointer"}}
+ and $detach_time > 0
+ and $weechat_version >= 0x00030800
+ and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
+ { # check for option detach_displayed_buffers and if buffer is displayed in a split window
+ if ( $buffer->{"num_displayed"} eq 1
+ and weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0 )
+ {
+ my $infolist_window = weechat::infolist_get("window","","");
+ while (weechat::infolist_next($infolist_window))
+ {
+ my $buffer_ptr = weechat::infolist_pointer($infolist_window, "buffer");
+ if ($buffer_ptr eq $buffer->{"pointer"})
+ {
+ $buffer->{"window"} = weechat::infolist_integer($infolist_window, "number");
+ }
+ }
+ weechat::infolist_free($infolist_window);
+
+ push(@current2, $buffer);
+ }
+ }
}
else # buffer in "immune_detach_buffers"
{
@@ -831,6 +878,9 @@ sub build_buffers
}
}
}
+
+ $str .= weechat::config_string( $options{"show_prefix_query"}) if (weechat::config_string( $options{"show_prefix_query"} ) ne "" and $buffer->{"type"} eq "private");
+
if (weechat::config_boolean( $options{"show_prefix"} ) eq 1)
{
my $nickname = weechat::buffer_get_string($buffer->{"pointer"}, "localvar_nick");
@@ -880,38 +930,32 @@ sub build_buffers
if (weechat::config_boolean( $options{"short_names"} ) eq 1)
{
- my $name = $buffer->{"short_name"};
- $name = '?' . $name if $buffer->{"type"} eq 'private';
- $name =~ s|#iinteractive/|#|;
if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
{
- $str .= encode("UTF-8", substr(decode("UTF-8", $name), 0, weechat::config_integer($options{"name_size_max"})));
+ $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"short_name"}), 0, weechat::config_integer($options{"name_size_max"})));
$str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat::config_integer($options{"name_size_max"}));
$str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
$str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
}
else
{
- $str .= $name;
+ $str .= $buffer->{"short_name"};
$str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
$str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
}
}
else
{
- my $name = $buffer->{"name"};
- $name = '?' . $name if $buffer->{"type"} eq 'private';
- $name =~ s|#iinteractive/|#|;
if (weechat::config_integer($options{"name_size_max"}) >= 1) # check max_size of buffer name
{
- $str .= encode("UTF-8", substr(decode("UTF-8", $name,), 0, weechat::config_integer($options{"name_size_max"})));
+ $str .= encode("UTF-8", substr(decode("UTF-8", $buffer->{"name"},), 0, weechat::config_integer($options{"name_size_max"})));
$str .= weechat::color(weechat::config_color( $options{"color_number_char"})).weechat::config_string($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat::config_integer($options{"name_size_max"}));
$str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
$str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
}
else
{
- $str .= $name;
+ $str .= $buffer->{"name"};
$str .= add_inactive_parentless($buffer->{"type"},$buffer->{"nicks_count"});
$str .= add_hotlist_count($buffer->{"pointer"},%hotlist);
}
@@ -930,10 +974,21 @@ sub build_buffers
$str .= weechat::color("default") . " (" . weechat::color($color_lag) . $lag . weechat::color("default") . ")";
}
}
+ if (weechat::config_boolean($options{"detach_displayed_buffers"}) eq 0
+ and weechat::config_boolean($options{"detach_display_window_number"}) eq 1)
+ {
+ if ($buffer->{"window"})
+ {
+ $str .= weechat::color("default") . " (" . weechat::color(weechat::config_color( $options{"color_number"})) . $buffer->{"window"} . weechat::color("default") . ")";
+ }
+ }
$str .= "\n";
$old_number = $buffer->{"number"};
}
+ # remove spaces and/or linefeed at the end
+ $str =~ s/\s+$//;
+ chomp($str);
return $str;
}
@@ -1057,13 +1112,13 @@ my ($data, $signal, $signal_data) = @_;
}
}
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
sub buffers_signal_hotlist
{
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
@@ -1072,20 +1127,20 @@ sub buffers_signal_config_whitelist
{
@whitelist_buffers = ();
@whitelist_buffers = split( /,/, weechat::config_string( $options{"look_whitelist_buffers"} ) );
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
sub buffers_signal_config_immune_detach_buffers
{
@immune_detach_buffers = ();
@immune_detach_buffers = split( /,/, weechat::config_string( $options{"immune_detach_buffers"} ) );
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
sub buffers_signal_config
{
- weechat::bar_item_update("buffers");
+ weechat::bar_item_update($SCRIPT_NAME);
return weechat::WEECHAT_RC_OK;
}
@@ -1096,7 +1151,7 @@ sub buffers_focus_buffers
my %info = %{$_[1]};
my $item_line = int($info{"_bar_item_line"});
undef my $hash;
- if (($info{"_bar_item_name"} eq "buffers") && ($item_line >= 0) && ($item_line <= $#buffers_focus))
+ if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
{
$hash = $buffers_focus[$item_line];
}
@@ -1202,3 +1257,30 @@ sub check_immune_detached_buffers
}
return 0;
}
+
+sub shutdown_cb
+{
+ weechat::command("","/bar hide " . $SCRIPT_NAME) if ( weechat::config_boolean($options{"toggle_bar"}) eq 1 );
+ return weechat::WEECHAT_RC_OK
+}
+
+sub check_bar_item
+{
+ my $item = 0;
+ my $infolist = weechat::infolist_get("bar", "", "");
+ while (weechat::infolist_next($infolist))
+ {
+ my $bar_items = weechat::infolist_string($infolist, "items");
+ if (index($bar_items,$SCRIPT_NAME) != -1)
+ {
+ my $name = weechat::infolist_string($infolist, "name");
+ if ($name ne $SCRIPT_NAME)
+ {
+ $item = 1;
+ last;
+ }
+ }
+ }
+ weechat::infolist_free($infolist);
+ return $item;
+} \ No newline at end of file
diff --git a/weechat/perl/autoload/chatters.pl b/weechat/perl/autoload/chatters.pl
index 7478f9b..993ccad 100644
--- a/weechat/perl/autoload/chatters.pl
+++ b/weechat/perl/autoload/chatters.pl
@@ -39,12 +39,14 @@
# Version 0.3: missing return value for callbacks fixed
# version check added
# improved option handling
+# 2013-02-07, Ailin Nemui <anti.teamidiot.de>
+# Version 0.4: add focus info
#
use strict;
use warnings;
-my $version = "0.3";
+my $version = "0.4";
my $script_name = "chatters";
my $weechat_version = "";
@@ -88,8 +90,12 @@ weechat::hook_timer(60000, 0, 0, "cleanup_chatters", 0);
# On config change
weechat::hook_config("plugins.var.perl.${script_name}.*", "config_change_cb", "");
+
weechat::bar_item_new($chatters_bar_item_name, "chatters_bar_cb", "");
+# For mouse support
+weechat::hook_focus($chatters_bar_item_name, "chatters_focus_cb", "") if $weechat_version >= 0x00030600;
+
###############################################################################
# Buffer update callback
sub chatters_bar_cb
@@ -131,7 +137,7 @@ sub buffer_close_cb
{
delete $chatter_groups{$channel};
}
-return weechat::WEECHAT_RC_OK;
+ return weechat::WEECHAT_RC_OK;
}
###############################################################################
@@ -202,7 +208,22 @@ sub config_change_cb
{
cleanup_chatters();
}
-return weechat::WEECHAT_RC_OK;
+ return weechat::WEECHAT_RC_OK;
+}
+
+###############################################################################
+# Adds nick info to focus hashtable
+sub chatters_focus_cb
+{
+ my $channel = buf_to_channel_key($_[1]{_buffer});
+ if ($channel and $chatter_groups{$channel} and
+ $_[1]{_bar_item_line} > 0 and $_[1]{_bar_item_line} <= keys %{ $chatter_groups{$channel} })
+ {
+ +{ nick => (sort {uc($a) cmp uc($b)} keys %{ $chatter_groups{$channel} })[$_[1]{_bar_item_line}-1] }
+ }
+ else {
+ $_[1]
+ }
}
###############################################################################
diff --git a/weechat/python/autoload/bitlbee_typing_notice.py b/weechat/python/autoload/bitlbee_typing_notice.py
index 307083b..7e76988 100644
--- a/weechat/python/autoload/bitlbee_typing_notice.py
+++ b/weechat/python/autoload/bitlbee_typing_notice.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2010 by Alexander Schremmer <alex@alexanderweb.de>
+# Copyright (c) 2013 by Corey Halpin <chalpin@cs.wisc.edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,78 +18,89 @@
#
#
-# (this script requires WeeChat 0.3.0 or newer)
+# (this script requires WeeChat 0.3.6 or newer)
#
# History:
+# 2013-06-24, Priska Herger <policecar@23bit.net>
+# version 0.4: bug fix: if TYPING 0, don't show typing.
+# 2013-04-27, Corey Halpin <chalpin@cs.wisc.edu>
+# version 0.3:
+# * Use irc_message_parse to extract nicks
+# * Send typing = 0 at message completion in private buffers
+# * Make server, channel, and timeout configurable w/o editing plugin code.
# 2010-05-20, Alexander Schremmer <alex@alexanderweb.de>
# version 0.2: also handle users that do not send a TYPING 0 msg before quitting
# removed InfoList code
# 2010-05-16, Alexander Schremmer <alex@alexanderweb.de>
# version 0.1: initial release
+
+# Configuration options via /set:
+#
+# 'channel'
+# description: Name of your bitlbee channel
+# command: /set plugins.var.python.bitlbee_typing_notice.channel &bitlbee
+#
+# 'server'
+# description: Server running your bitlbee instance.
+# command: /set plugins.var.python.bitlbee_typing_notice.server localhost
+#
+# 'timeout'
+# description: Send "not typing" after this many seconds w/o typing.
+# command: /set plugins.var.python.bitlbee_typing_notice.timeout 4
+#
+# Note, the plugin must be reloaded after either of these settings are changed.
+# /python reload works for this.
+
+
import weechat as w
import re
SCRIPT_NAME = "bitlbee_typing_notice"
SCRIPT_AUTHOR = "Alexander Schremmer <alex@alexanderweb.de>"
-SCRIPT_VERSION = "0.2"
+SCRIPT_VERSION = "0.4"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Shows when somebody is typing on bitlbee and sends the notice as well"
+typing = {} # Record nicks who sent typing notices. key = subject nick, val = typing level.
-bitlbee_channel = "&bitlbee"
-bitlbee_server_name = "bitlbee"
-
-KEEP_TYPING_TIMEOUT = 1
-STOP_TYPING_TIMEOUT = 7
-
-typing = {}
-sending_typing = {}
-
+sending_typing = {} # Nicks to whom we're sending typing notices.
+# key = target nick, val = sequence number used to determine when the typing notice
+# should be removed.
def channel_has_nick(server, channel, nick):
buffer = w.buffer_search("", "%s.%s" % (server, channel))
return bool(w.nicklist_search_nick(buffer, "", nick))
-
-def redraw(nick):
- w.bar_item_update("bitlbee_typing_notice")
-
-
+# Callback which checks for ctcp typing notices sent to us.
+# Updates typing data, hides the ctcp notices.
def ctcp_cb(data, modifier, modifier_data, string):
- if modifier_data != bitlbee_server_name:
+ if modifier_data != w.config_get_plugin("server"):
+ return string
+ msg_hash = w.info_get_hashtable(
+ "irc_message_parse", {"message": string} )
+ if msg_hash["command"] != "PRIVMSG":
return string
- match = re.match(r'(.*) PRIVMSG (.*)', string)
+ match = re.search('\001TYPING ([0-9])\001', msg_hash["arguments"])
if match:
- host, msg = match.groups()
- match = re.search('\001TYPING ([0-9])\001', msg)
- if match:
- nick = re.match(':(?P<nick>.+)!', string).groups()[0]
- typing_level = int(match.groups()[0])
- if typing_level == 0:
- try:
- del typing[nick]
- except KeyError:
- pass
- redraw(nick)
- elif typing_level == 1:
- typing[nick] = 1
- # XXX add ICQ/Yahoo hack
- redraw(nick)
- elif typing_level == 2:
- typing[nick] = 2
- redraw(nick)
- return ""
- return string
- buffer = w.buffer_search("", "%s.%s" % (server, channel))
+ nick = msg_hash["nick"]
+ typing_level = int(match.groups()[0])
+ if typing_level == 0 and nick in typing:
+ del typing[nick]
+ elif typing_level > 0:
+ typing[nick] = typing_level
+ w.bar_item_update("bitlbee_typing_notice")
+ return ""
+ else:
+ return string
+
def stop_typing(data, signal, signal_data):
- nick = re.match(':(?P<nick>.+)!', signal_data).groups()[0]
- try:
- del typing[nick]
- except KeyError:
- pass
- redraw(nick)
+ msg_hash = w.info_get_hashtable(
+ "irc_message_parse", {"message": signal_data } )
+ if msg_hash["nick"] in typing:
+ del typing[msg_hash["nick"]]
+ w.bar_item_update("bitlbee_typing_notice")
return w.WEECHAT_RC_OK
def typed_char(data, signal, signal_data):
@@ -98,41 +110,52 @@ def typed_char(data, signal, signal_data):
channel = w.buffer_get_string(buffer, 'localvar_channel')
buffer_type = w.buffer_get_string(buffer, 'localvar_type')
- if server != bitlbee_server_name or input_s.startswith("/"):
+ if server != w.config_get_plugin("server") or input_s.startswith("/"):
return w.WEECHAT_RC_OK
if buffer_type == "private":
- if input_s:
+ if len(input_s)==0:
+ send_typing(channel, 0) # Line sent or deleted -- no longer typing
+ else:
send_typing(channel, 1)
- elif channel == bitlbee_channel:
+ elif channel == w.config_get_plugin("channel"):
nick_completer = w.config_string("weechat.completion.nick_completer")
parts = input_s.split(":", 1)
if len(parts) > 1:
nick = parts[0]
send_typing(nick, 1)
-
return w.WEECHAT_RC_OK
def typing_disable_timer(data, remaining_calls):
nick, cookie = data.rsplit(":", 1)
cookie = int(cookie)
- if sending_typing[nick] == cookie:
+ if nick in sending_typing and sending_typing[nick]==cookie:
send_typing_ctcp(nick, 0)
- sending_typing[nick] = False
+ del sending_typing[nick]
return w.WEECHAT_RC_OK
+
def send_typing_ctcp(nick, level):
- buffer = w.buffer_search("irc", "%s.%s" % (bitlbee_server_name, bitlbee_channel))
+ if not channel_has_nick(w.config_get_plugin("server"),
+ w.config_get_plugin("channel"), nick):
+ return
+ buffer = w.buffer_search("irc", "%s.%s" %
+ (w.config_get_plugin("server"),
+ w.config_get_plugin("channel")) )
w.command(buffer, "/mute -all /ctcp %s TYPING %i" % (nick, level))
+
def send_typing(nick, level):
- if not channel_has_nick(bitlbee_server_name, bitlbee_channel, nick):
- return
- cookie = sending_typing.get(nick, 1) + 1
- if not sending_typing.get(nick, None):
- send_typing_ctcp(nick, level)
- sending_typing[nick] = cookie
- w.hook_timer(4000, 0, 1, "typing_disable_timer", "%s:%i" % (nick, cookie))
+ if level == 0 and nick in sending_typing:
+ send_typing_ctcp(nick, 0)
+ del sending_typing[nick]
+ elif level > 0 :
+ if nick not in sending_typing:
+ send_typing_ctcp(nick, level)
+ cookie = sending_typing.get(nick, 0) + 1
+ sending_typing[nick] = cookie
+ w.hook_timer( int(1000 * float(w.config_get_plugin('timeout'))), 0, 1,
+ "typing_disable_timer", "%s:%i" % (nick, cookie))
def typing_notice_item_cb(data, buffer, args):
@@ -147,11 +170,20 @@ def typing_notice_item_cb(data, buffer, args):
return ""
-if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
+# Main
+if __name__ == "__main__":
+ if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
- w.hook_signal("input_text_changed", "typed_char", "")
- w.hook_signal(bitlbee_server_name + ",irc_in_quit", "stop_typing", "")
- w.hook_signal(bitlbee_server_name + ",irc_in_privmsg", "stop_typing", "")
- w.bar_item_new('bitlbee_typing_notice', 'typing_notice_item_cb', '')
- w.hook_modifier("irc_in_privmsg", "ctcp_cb", "")
+ if not w.config_get_plugin('channel'):
+ w.config_set_plugin('channel', "&bitlbee")
+ if not w.config_get_plugin('server'):
+ w.config_set_plugin('server', "localhost")
+ if not w.config_get_plugin('timeout'):
+ w.config_set_plugin('timeout', "4")
+
+ w.hook_signal("input_text_changed", "typed_char", "")
+ w.hook_signal(w.config_get_plugin("server")+",irc_in_quit", "stop_typing", "")
+ w.hook_signal(w.config_get_plugin("server")+",irc_in_privmsg", "stop_typing", "")
+ w.bar_item_new('bitlbee_typing_notice', 'typing_notice_item_cb', '')
+ w.hook_modifier("irc_in_privmsg", "ctcp_cb", "")