Commit 5f420262 authored by Sébastien Helleu's avatar Sébastien Helleu

Add new scripts audacious.pl, fortune.pl, kernel.pl, shuffle.pl

parent 81c287f1
#
# Copyright (c) 2006 by DeltaS4 <deltas4@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
#
#
# Changelog:
# 0.1: first version
# 0.2: now you don't need the Song Change plugin enabled because
# it uses audtool --current-song to get the music name as nenolod
# suggested (http://boards.nenolod.net/index.php?showtopic=147). :)
# 0.3: port to WeeChat 0.2.7 by Trashlord
#
weechat::register ("audacious", "Trashlord", "0.3", "GPL", "audacious-weechat current song script (usage: /music)", "", "");
weechat::hook_command("music", "", "", "", "", "audtool", "");
sub audtool {
my ($data, $buffer, $args) = @_;
chomp(my ($cs, $cslen) = (`audtool --current-song`, `audtool --current-song-length`));
weechat::command($buffer, "/me is playing $cs ($cslen)");
return weechat::WEECHAT_RC_OK;
}
# This script is a port from the original fortune.pl irssi script written by
# Ivo Marino <eim@cpan.org>. This script is in the public domain
#
# Original WeeChat Author: Julien Louis <ptitlouis@sysif.net>
#
# Port to WeeChat 0.2.7: Sid Vicious (aka Trashlord) <dornenreich666@gmail.com>
weechat::register("fortune", "Trashlord", "0.2", "Public domain", "Send a random fortune cookie to a specified nick", "", "");
weechat::hook_command("fortune", "Send a random fortune cookie to a specified nick",
"<nick> [lang]",
"<nick> The nickname to send the fortune cookie\n" .
" [lang] The cookie language (Default: en)\n",
"", "fortune", "");
sub fortune {
my ($data, $buffer, $param) = @_;
my $rc = weechat::WEECHAT_RC_OK;
my $cookie = '';
if ($param) {
(my $nick, my $lang) = split (' ', $param);
$lang = 'en' unless ($lang eq 'de'|| $lang eq 'it' || $lang eq
'en' || $lang eq 'fr' );
weechat::print($buffer, "Nick: " . $nick . ", Lang: \"" . $lang . "\"");
if ($lang eq 'de') {
$cookie = `fortune -x`;
}
elsif ($lang eq 'it') {
$cookie = `fortune -a italia`;
}
else {
$cookie = `fortune -a fortunes literature riddles`;
}
$cookie =~ s/\s*\n\s*/ /g;
if ($cookie) {
weechat::command($buffer, $nick . ": " . $cookie, $channel);
}
else {
weechat::print($buffer, "No cookie.");
$rc = weechat::WEECHAT_RC_ERROR;
}
}
else {
weechat::print ($buffer, "Usage: /fortune <nick> [language]");
$rc = weechat::WEECHAT_RC_ERROR;
}
return $rc;
}
# This is a rewrite of the script "Kernel" for WeeChat.
# This script is for WeeChat 0.2.7
# Written by Julien Louis <ptitlouis@sysif.net>
# Port to WeeChat 0.2.7: Sid Vicious (aka Trashlord) <dornenreich666@gmail.com>
# This script is public domain
use warnings;
use strict;
use IO::Socket;
weechat::register("kernel", "ptitlouis", "0.2", "Public domain", "Display latest stable kernel from kernel.org", "", "");
weechat::hook_command("kernel", "Display latest stable kernel from kernel.org", "", "", "", "kernel", "");
sub get_kernel {
my $buffer = weechat::current_buffer;
my $sock = IO::Socket::INET->new(PeerAddr => 'finger.kernel.org', PeerPort => 79, Proto => 'tcp');
return weechat::WEECHAT_RC_ERROR unless $sock;
$sock->autoflush(1);
chomp(my @versions = <$sock>);
my $stable = "";
for(@versions) {
#Kernel 0 is latest stable, 1 is latest prepatch, 2 is latest snapshot with git
if ($_ =~ /^The latest stable.+:\s+(.+)/) { $stable = $1; }
}
close $sock;
return $stable;
}
sub kernel {
my ($buffer, $kernel) = ($_[1], &get_kernel);
weechat::print($buffer, "The latest stable Linux kernel is $kernel");
return weechat::WEECHAT_RC_OK;
}
# This is a text shuffler
# This script is public domain
# Author: Sid Vicious (Trashlord) <dornenreich666@gmail.com>
use warnings;
use strict;
weechat::register("shuffle", "Trashlord", "0.1", "Public domain", "Simple text shuffler", "", "");
weechat::hook_command("shuffle", "<msg>", "<msg> - message to shuffle", "", "", "cmd_shuffle", "");
#Text shuffler
sub cmd_shuffle {
my ($data, $buffer, $text) = (shift, shift, shift);
my $final;
for(split(" ", $text)) { #We're splitted here, so we can keep the spaces in order, and words in order. we just shuffle letters
my $len = length $_;
my $out;
while ($len > 0) {
my $rand = int(rand($len));
my $letter = substr($_, $rand, 1);
$len--;
substr($_, $rand, 1, "");
$out .= $letter;
}
$final .= $out." ";
}
weechat::command($buffer, $final);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment