You are not logged in.
Pages: 1
Hello, first I would like to make an outline of what I want to accomplish:
I want to make alerts using awesome's notification library naught to go together with
weechat. So when someone highlights me or msg me I will get a notification.
Sounds simple, huh?
I know some Lua, which I guess is what I need.
Any good links for weechat programming or maybe you have a script for this task you have written?
Everything that is remotely similar to what I want to do is helpful.
Thanks for taking time.
Offline
The WeeChat plugin API documentation may help you: http://www.weechat.org/files/doc/stable … pi.en.html
Here's a Perl reference plugin: http://www.0x11.net/notify-remote/remot … ication.pl
And in Python: http://www.weechat.org/files/scripts/notify.py
Looks like you need to hook irc_privmsg.
Good luck.
Offline
Thanks tindzk, that was a great help.
Turns out it's really simple, have some fine tuning to do but t works.
weechat.register("Naughty-alert", "Felix Wallin", "1.0", "GPL3", "Highlight Alert", "", "")
function alert_naughty()
os.execute('notify-send "privmsg received"')
end
weechat.hook_signal("*,irc_in2_privmsg","alert_naughty", "")
that simple. dbus is great.
EDIT: it doesn't notify on highlights yet, soon to come.
Last edited by Nibble (2010-05-10 15:01:52)
Offline
Below is a script my friend wrote to do something like this. It will write highlights to a file ($HOME/.weechat/logs/events). I use DWM so in my .xinitrc I have something like:
while :; do
im=$(wc -l $HOME/.weechat/logs/events)
echo "I:${im}"
sleep 10
done | dwm
#
# jabber_message_handler
#
# Filters and processes messages on the jabber.&bitlbee channel.
#
# * Highlighted messages are logged to /var/log/weechat/events
# file so they can be processed by osd_weechat_events.sh and
# counted in dwm status bar.
#
# Changelog
# =========
#
# Version 0.05
# * Use HOME env var instead of tilde.
# Version 0.04
# * Save configuration settings in plugins.conf.
# Version 0.03
# * Replace "our" with "my" in code. (Bug: message handling stops
# working, requires restart)
# * Include verbose options in help message.
#
use warnings;
use strict;
# Name of the command
my $CMD_NAME = 'jabber_message_handler';
my $SCRIPT_NAME = 'jabber_message_handler';
my $SCRIPT_VERSION = '0.5';
my $SCRIPT_DESCR = 'Log events and format reminder messages';
# Names of the settings
my $CONFIG_ENABLED = 'enabled';
my $CONFIG_VERBOSE = 'verbose';
my $CONFIG_EVENTS = 'events_file';
# Default settings
my $DEFAULT_ENABLED = 'true';
my $DEFAULT_VERBOSE = 'false';
my $DEFAULT_EVENTS = $ENV{HOME} . '/.weechat/logs/events';
# Usage:
my $ARGS= '[on|off] [verbose [on|off]]';
my @ARGS_DESCRS = (
'on: enable',
'off: disable',
'verbose [on]: set verbose on',
'verbose off: set verbose off',
' ',
'without any arguments, displays current settings'
);
weechat::register(
'jabber_message_handler',
'Jim Karsten',
$SCRIPT_VERSION,
'GPL3',
$SCRIPT_DESCR,
'',
'',
);
if ( weechat::config_get_plugin($CONFIG_ENABLED) eq "" ) {
weechat::config_set_plugin($CONFIG_ENABLED, $DEFAULT_ENABLED)
}
if ( weechat::config_get_plugin($CONFIG_VERBOSE) eq "" ) {
weechat::config_set_plugin($CONFIG_VERBOSE, $DEFAULT_VERBOSE)
}
if ( weechat::config_get_plugin($CONFIG_EVENTS) eq "" ) {
weechat::config_set_plugin($CONFIG_EVENTS, $DEFAULT_EVENTS)
}
my $verbose = weechat::config_get_plugin($CONFIG_VERBOSE) eq 'true' ? 1 : 0;
# Display a summary of the settings
print_settings();
weechat::hook_command(
$CMD_NAME,
'Log jabber messages',
$ARGS,
join("\n", @ARGS_DESCRS),
'',
$CMD_NAME,
'',
);
weechat::hook_signal('weechat_highlight', 'highlight_message', "");
weechat::hook_signal('irc_pv', 'irc_pv', "");
weechat::hook_signal('weechat_pv', 'weechat_pv', "");
#
# highlight_message
#
# Sent: nothing
# Return: nothing
# Purpose:
#
# Delegate highlight message.
#
sub highlight_message {
my $type = 'highlight';
print_it("highlight_message - received message.") if $verbose;
process_message( $type, @_ );
}
#
# irc_pv
#
# Sent: nothing
# Return: nothing
# Purpose:
#
# Delegate irc_pv message.
#
sub irc_pv {
my $type = 'irc_pv';
print_it("DEBUG - irc_pv()") if $verbose;
return weechat::WEECHAT_RC_OK;
}
#
# weechat_pv
#
# Sent: nothing
# Return: nothing
# Purpose:
#
# Delegate weechat_pv message.
#
sub weechat_pv {
my $type = 'weechat_pv';
print_it("DEBUG - weechat_pv()") if $verbose;
return weechat::WEECHAT_RC_OK;
}
#
# process_message
#
# Sent: nothing
# Return: add_message_handler return value
# Purpose:
#
# Process incoming message.
#
sub process_message {
if ( weechat::config_get_plugin($CONFIG_ENABLED) ne "true" ) {
return weechat::WEECHAT_RC_OK;
}
print_it( "process message arguments - " . join('X:', @_ ) ) if $verbose;
my $message = parse_message( @_ );
log_event( $message );
return weechat::WEECHAT_RC_OK;
}
#
# parse_message
#
# Sent: irc message
# Return: hash ref
# Purpose:
#
# Parse the irc message into it's components.
#
sub parse_message {
print_it( "parse message arguments - " . join('X:', @_ ) ) if $verbose;
my ( $type, $data, $buffer, $args ) = @_;
my ( $nick, $message ) = ( $args =~ /(.*?)\t(.*)/ );
print_it("parse_message - nick: $nick") if $verbose;
print_it("parse_message - message: $message") if $verbose;
return {
nick => $nick,
msg => $message,
type => $type,
};
}
#
# log_event
#
# Sent: message hash ref
# Return: nothing
# Purpose:
#
# Log the event. Each line logged increments the message
# counter in dwm status bar.
#
sub log_event {
my ( $message ) = @_;
my $EVENTS = weechat::config_get_plugin($CONFIG_EVENTS);
print_it("log_event - logging event to $EVENTS") if $verbose;
my $timestamp = `date`; chomp $timestamp;
my $msg = join("|", $timestamp,
$message->{type},
$message->{nick},
$message->{msg}
);
print_it("log_event - timestamp = $timestamp") if $verbose;
print_it("log_event - msg = $msg") if $verbose;
if ( ! -w $EVENTS) {
print_it("Unable to open event log for writing: $!");
return;
}
open my $event_log, ">> $EVENTS" or do {
print_it("Unable to open event log for writing: $!");
exit 1;
};
print $event_log $msg, "\n" or do {
print_it("Unable to print message to event log");
return;
};
close $event_log;
}
#
# print_it
#
# Sent: string to print
# Return: nothing
# Purpose:
#
# Print message to jabber channel.
#
sub print_it {
my ( $str ) = @_;
weechat::print(
weechat::buffer_search('irc_raw:T', 'jabber.&bitlbee'),
$str,
);
}
#
# print_settings
#
# Sent: nothing
# Return: nothing
# Purpose:
#
# Print the current config settings.
#
sub print_settings {
weechat::print( weechat::current_buffer(), $CMD_NAME . ' settings:' );
if ( weechat::config_get_plugin($CONFIG_ENABLED) eq "true") {
weechat::print(
weechat::current_buffer(),
" enabled"
);
}
else {
weechat::print(
weechat::current_buffer(),
" disabled"
);
}
if ( weechat::config_get_plugin($CONFIG_VERBOSE) eq "true" ) {
weechat::print(
weechat::current_buffer(),
" verbose: on"
);
}
else {
weechat::print(
weechat::current_buffer(),
" verbose: off"
);
}
weechat::print(
weechat::current_buffer(),
sprintf(" events log file: %s", weechat::config_get_plugin($CONFIG_EVENTS))
);
return;
}
sub jabber_message_handler {
my ( $data, $buffer, $args ) = @_;
my @params = split(/ /, $args);
if ( scalar(@params) > 0 ) {
if ($params[0] eq 'on') {
weechat::config_set_plugin($CONFIG_ENABLED, "true");
}
elsif ($params[0] eq 'off') {
weechat::config_set_plugin($CONFIG_ENABLED, "false");
}
elsif ($params[0] eq 'verbose') {
weechat::config_set_plugin($CONFIG_VERBOSE, "true");
}
}
if ( scalar(@params) > 1 ) {
if ($params[0] eq 'verbose') {
if ($params[1] eq 'on') {
weechat::config_set_plugin($CONFIG_VERBOSE, "true");
}
else {
weechat::config_set_plugin($CONFIG_VERBOSE, "false");
}
}
}
$verbose = weechat::config_get_plugin($CONFIG_VERBOSE) eq 'true' ? 1 : 0;
print_settings();
return weechat::WEECHAT_RC_OK;
}
Last edited by steve___ (2010-05-11 04:03:44)
Offline
This puts the nick and text in the notify bubbles, plus it beeps the term. Combined with urxvt's urgentOnBell and mapAlert settings, that's a lot of notification .
weechat.register('notify', 'James Campos', '0.0.0', 'MIT',
'Notify on highlight', '', '')
weechat.hook_signal('weechat_highlight', 'notify', '')
weechat.hook_signal('irc_pv', 'notify', '')
function notify (data, signal, signal_data)
os.execute('echo -n \a')
nick, text = string.match(signal_data, '(.-)\t(.+)')
os.execute('notify-send ' .. string.format('%q %q', nick, text))
return weechat.WEECHAT_RC_OK
end
Offline
You can also find an elaborate weechat -> awesome notification system here
Look in ./weechat/lua/naughtynotice.lua and ./config/awesome/widget/irc.lua
Offline
@alterecco: thanks for your lib :-)
I'm trying to finish configuring it for an integration with my config of Awesome WM.
EDIT:
actually, I'm using jabber in weechat through the jabber script.
So, it notifys only for IRC but not for jabber. It'll be nice if it worked too!
I'm gonna have a closer look at your lib, see if I can manage to do something.
Last edited by Rolinh (2011-05-18 21:14:32)
Offline
Pages: 1