Script: awaylog.pl

Log highlights/private messages when you are away.
Author: GolemJ — Version: 0.8 — License: GPL2
For WeeChat ≥ 0.3.0.
Tags: irc, away, log
Added: 2005-07-21 — Updated: 2010-08-01

Download GitHub Repository

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
###############################################################################
#
# Copyright (c) 2008 by GolemJ <golemj@gmail.com>
# 
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
###############################################################################
#
# Log highlights msg to core buffer
# You need to set "notify" to "yes" and "command" to proper command to run
# external command. You also need "shell" script to run external command.
#
# History:
#   2010-06-20, GolemJ <golemj@gmail.com>
#       version 0.8, add posibility to execute command for notification
#   2010-02-14, Emmanuel Bouthenot <kolter@openics.org>
#       version 0.7, add colors and notifications support
#   2009-05-02, FlashCode <flashcode@flashtux.org>:
#       version 0.6, sync with last API changes
#   2008-11-30, GolemJ <golemj@gmail.com>:
#       version 0.5, conversion to WeeChat 0.3.0+
#
###############################################################################

use strict;

weechat::register( "awaylog", "Jiri Golembiovsky", "0.8", "GPL", "Prints highlights to core buffer", "", "" );
weechat::hook_print( "", "", "", 1, "highlight_cb", "" );

if( weechat::config_get_plugin( "on_away_only" ) eq "" ) {
  weechat::config_set_plugin( "on_away_only", "off" );
}

if( weechat::config_get_plugin( "plugin_color" ) eq "" ) {
  weechat::config_set_plugin( "plugin_color", "default" );
}

if( weechat::config_get_plugin( "name_color" ) eq "" ) {
  weechat::config_set_plugin( "name_color", "default" );
}

if( weechat::config_get_plugin( "notify" ) eq "" ) {
  weechat::config_set_plugin( "notify", "off" );
}

if( weechat::config_get_plugin( "command" ) eq "") {
  weechat::config_set_plugin( "command", "" );
}

sub highlight_cb {
  if( $_[5] == 1 ) {
    my $away = weechat::buffer_get_string($_[1], "localvar_away");
    if (($away ne "") || (weechat::config_get_plugin( "on_away_only" ) ne "on"))
    {
        my $buffer_color =  weechat::color(weechat::config_get_plugin( "plugin_color"))
                    . weechat::buffer_get_string($_[1], "plugin")
                    . "."
                    . weechat::buffer_get_string($_[1], "name")
                    . weechat::color("default");
        my $buffer = weechat::buffer_get_string($_[1], "plugin")
                    . "."
                    . weechat::buffer_get_string($_[1], "name");
        my $name_color =  weechat::color(weechat::config_get_plugin( "name_color"))
                    . $_[6]
                    . weechat::color("default");
        my $name   = $_[6];
        my $message_color = "${buffer_color} -- ${name_color} :: $_[7]";
        my $message = "${buffer} -- ${name} :: $_[7]";
        if( weechat::config_get_plugin( "notify" ) ne "on" ) {
          my $command = weechat::config_get_plugin( "command" );
          if( $command ne "" ) {
            if( $command =~ /\$msg/ ) {
              $command =~ s/\$msg/\'$message\'/;
            } else {
              $command = "$command '$message'";
            }
            weechat::command( "", "/shell $command" );
          } else {
            weechat::print("", $message_color);
          }
        } else {
            weechat::print_date_tags("", 0, "notify_highlight", $message_color);
        }
    }
  }

  return weechat::WEECHAT_RC_OK;
}