Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

Using notify-send with IRSSI

Requires libnotify, have fun!

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
        authors     => 'Chrelad',
        contact     => '[email protected]',
        name        => 'notify',
        description => 'Display a pop-up alert for different events.',
        url         => 'http://google.com',
        license     => 'GNU General Public License',
        changed     => '$Date: 2007-02-07 12:00:00 +0100 (Thu, 7 Feb 2008) $'
);

#--------------------------------------------------------------------
# Created by Chrelad
# Feb 7, 2008
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# The notify function for public message
#--------------------------------------------------------------------

sub pub_msg {
        my ($server,$msg,$nick,$address,$target) = @_;
        `notify-send -t 8000 "${target} : ${nick}" "${msg}"`;
}

#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------

Irssi::signal_add_last("message public", "pub_msg");
#- end

Play sound for certain events in IRSSI

Perl script to allow sounds to be played for different events in IRSSI

Just keep adding handlers to IRSSI's pools pointing to different functions for different events or whatever you want.

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
        authors     => 'Chrelad',
        contact     => '[email protected]',
        name        => 'alert',
        description => 'Play sounds for different events in IRSSI.',
        url         => 'http://google.com',
        license     => 'GNU General Public License',
        changed     => '$Date: 2007-02-07 12:00:00 +0100 (Thu, 7 Feb 2008) $'
);

#--------------------------------------------------------------------
# Created by Chrelad
# Feb 7, 2008
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# The sound playing function for public message
#--------------------------------------------------------------------

sub pub_msg {
        my ($server,$msg,$nick,$address,$target) = @_;
        `mplayer -quiet ~/file.mp3 > /dev/null`;
}

#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------

Irssi::signal_add_last("message public", "pub_msg");
#- end

Somewhat ridiculous XML parser + image generator

Seriously needs caching. SRSLY

<?php
        class ImageGeneration {
                function getInfo($name) {
                        $this->loadDefaultInfo();
                        $XML = new XMLReader;
                        $XML->open("http://chat.hypermutt.net/online/user/".$name.".xml");
                        $wn = array();

                        while($XML->read()) {
                                if ($XML->nodeType == XMLReader::ELEMENT) {
                                        $wn[] = $XML->name;
                                }
                                if ($XML->nodeType == XMLReader::TEXT) {
                                        if ("user/info/nick" == implode('/', $wn)) {
                                                $this->name = $XML->value . ". ";
                                        }
                                        if ("user/info/online" == implode('/', $wn)) {
                                                $this->away = ($XML->value == "TRUE") ? true : false;
                                        }


                                        if ("user/info/connected" == implode('/', $wn)) {
                                                $this->onlinefor = strtotime($XML->value);
                                        }
                                        if ("user/info/timenow" == implode('/', $wn)) {
                                                $sc = (strtotime($XML->value) - $this->onlinefor);
                                                $t = floor($sc/86400);
                                                        $c["days"] = ($t > 0) ? $t."D " : ""; $sc = ($sc-$t*86400);
                                                $t = floor($sc/3600);
                                                        $c["hours"] = ($t > 0) ? $t."H " : ""; $sc = ($sc-$t*3600);
                                                $t = floor($sc/60);
                                                        $c["minutes"] = ($t > 0) ? $t."M " : "";
                                                $this->onlinefor = $c["days"].$c["hours"].$c["minutes"];
                                        }
                                        

                                        if ("user/info/away" == implode('/', $wn)) {
                                                $this->away = ($XML->value == "TRUE") ? true : false;
                                        }
                                        if ("user/info/awaymsg" == implode('/', $wn)) {
                                                $this->awaymessage = $XML->value;
                                        }
                                        if ("user/channels/channel/name" == implode('/', $wn)) {
                                                $this->channels .= str_replace('#','',$XML->value)." ";
                                        }
                                }
                                if ($XML->nodeType == XMLReader::END_ELEMENT) {
                                        array_pop($wn);
                                }
                        }
                        $XML->close();
                }
                
                function loadDefaultInfo() {
                        $this->name = ". ";
                        $this->online = true;
                        $this->onlinefor = "";
                        $this->away = true;
                        $this->awaymessage = "";
                        $this->channels = "";
                }
        
                function drawImage() {
                        header("Content-type: image/png");
                        $image = imagecreatefrompng("background.png");
                                $white = imagecolorallocate($image, 255, 255, 255);
                                $red   = imagecolorallocate($image, 255, 0, 0);
                                $green = imagecolorallocate($image, 0, 255, 0);
                                $feb = "slkscreb.ttf";
                                $fnn = "slkscr.ttf";
                        
                        $sizes["name"]   = imagettfbbox(6, 0, $feb, $this->name);
                        $sizes["online"] = imagettfbbox(6, 0, $feb, "online: ");
                        $sizes["away"]   = imagettfbbox(6, 0, $feb, "away: ");
                        $sizes["yes"]    = imagettfbbox(6, 0, $feb, "yes ");
                        $sizes["#"]     = imagettfbbox(6, 0, $feb, "#: ");
                        
                        imagettftext($image, 6, 0, 22, 8, -$white, $feb, $this->name);
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4]), 8, -$white, $feb, "online:");
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4] + ($sizes["online"][4] - $sizes["away"][4])), 18, -$white, $feb, "away:");
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4] + ($sizes["online"][4] - $sizes["#"][4])),    28, -$white, $feb, "#: ");
                        
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4] + $sizes["online"][4]),  8, -(($this->online) ? $green : $red), $feb, (($this->online) ? "yes" : "no"));
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4] + $sizes["online"][4]), 18, -((!$this->away)  ? $green : $red), $feb, (($this->away)   ? "yes" : "no"));
                        
                        if ($this->online)
                                imagettftext($image, 6, 0, (22 + $sizes["name"][4] + $sizes["online"][4] + $sizes["yes"][4]),  8, $white, $fnn, $this->onlinefor);
                        if ($this->away)
                                imagettftext($image, 6, 0, (22 + $sizes["name"][4] + $sizes["online"][4] + $sizes["yes"][4]), 18, $white, $fnn, $this->awaymessage);
                        imagettftext($image, 6, 0, (22 + $sizes["name"][4] + $sizes["online"][4]), 28, $white, $fnn, $this->channels);
                        
                        imagepng($image);
                        imagedestroy($image);
                }
        }
        
        $x = new ImageGeneration;
        $x->getInfo($_GET['name']);
        $x->drawImage();
?>
« Newer Snippets
Older Snippets »
3 total  XML / RSS feed