From: Alexander Færøy Date: Sat, 31 May 2014 11:10:46 +0000 (+0200) Subject: Import scripts from scripts.irssi.org X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=2d0759e6ca5767b48bcc85bf38c2c43d5f0b63b1;p=irssi-scripts.irssi.org.git Import scripts from scripts.irssi.org --- diff --git a/scripts/8-ball.pl b/scripts/8-ball.pl new file mode 100644 index 0000000..04564a7 --- /dev/null +++ b/scripts/8-ball.pl @@ -0,0 +1,124 @@ +#8-ball / decision ball +# +#What is this? +# +#The 8-ball (Eight-ball) is a decision ball which i bought +#in a gadget shop when i was in London. I then came up with +#the idea to make an irc-version of this one :) +#There are 16 possible answers that the ball may give you. +# +# +#usage +# +#Anyone in the same channel as the one who runs this script may +#write "8-ball: question ?" without quotes and where question is +#a question to ask the 8-ball. +#An answer is given randomly. The possible answers are the exact +#same answers that the real 8-ball gives. +# +#Write "8-ball" without quotes to have the the ball tell you +#how money questions it've got totally. +# +#Write "8-ball version" without quotes to have him tell what +#his version is. +# +# +use strict; +use vars qw($VERSION %IRSSI); + +use Irssi qw(command_bind signal_add); +use IO::File; +$VERSION = '0.20'; +%IRSSI = ( + authors => 'Patrik Jansson', + contact => 'gein@knivby.nu', + name => '8-ball', + description => 'Dont like to take decisions? Have the 8-ball do it for you instead.', + license => 'GPL', +); + +sub own_question { + my ($server, $msg, $target) = @_; + question($server, $msg, "", $target); +} + +sub public_question { + my ($server, $msg, $nick, $address, $target) = @_; + question($server, $msg, $nick.": ", $target); +} +sub question($server, $msg, $nick, $target) { + my ($server, $msg, $nick, $target) = @_; + $_ = $msg; + if (!/^8-ball/i) { return 0; } + + if (/^8-ball:.+\?$/i) { + my $ia = int(rand(16)); + my $answer = ""; + SWITCH: { + if ($ia==0) { $answer = "Yes"; last SWITCH; } + if ($ia==1) { $answer = "No"; last SWITCH; } + if ($ia==2) { $answer = "Outlook so so"; last SWITCH; } + if ($ia==3) { $answer = "Absolutely"; last SWITCH; } + if ($ia==4) { $answer = "My sources say no"; last SWITCH; } + if ($ia==5) { $answer = "Yes definitely"; last SWITCH; } + if ($ia==6) { $answer = "Very doubtful"; last SWITCH; } + if ($ia==7) { $answer = "Most likely"; last SWITCH; } + if ($ia==8) { $answer = "Forget about it"; last SWITCH; } + if ($ia==9) { $answer = "Are you kidding?"; last SWITCH; } + if ($ia==10) { $answer = "Go for it"; last SWITCH; } + if ($ia==11) { $answer = "Not now"; last SWITCH; } + if ($ia==12) { $answer = "Looking good"; last SWITCH; } + if ($ia==13) { $answer = "Who knows"; last SWITCH; } + if ($ia==14) { $answer = "A definite yes"; last SWITCH; } + if ($ia==15) { $answer = "You will have to wait"; last SWITCH; } + if ($ia==16) { $answer = "Yes, in due time"; last SWITCH; } + if ($ia==17) { $answer = "I have my doubts"; last SWITCH; } + } + $server->command('msg '.$target.' '.$nick.'8-ball says: '.$answer); + + my ($fh, $count); + $fh = new IO::File; + $count = 0; + if ($fh->open("< .8-ball")){ + $count = <$fh>; + $fh->close; + } + $count++; + $fh = new IO::File; + if ($fh->open("> .8-ball")){ + print $fh $count; + $fh->close; + }else{ + print "Couldn't open file for output. The value $count couldn't be written."; + return 1; + } + return 0; + } elsif (/^8-ball$/i) { + + my ($fh, $count); + $fh = new IO::File; + $count = 0; + if ($fh->open("< .8-ball")){ + $count = <$fh>; + $server->command('msg '.$target.' 8-ball says: I\'ve got '.$count.' questions so far.'); + $fh->close; + }else{ + print "Couldn't open file for input"; + return 1; + } + return 0; + + } elsif (/^8-ball version$/i){ + $server->command('msg '.$target.' My version is: '.$VERSION); + return 0; + } else { + if(!/^8-ball says/i){ + $server->command('msg '.$target.' '.$nick.'A question please.'); + return 0; + } + } + +} + +signal_add("message public", "public_question"); +signal_add("message own_public", "own_question"); diff --git a/scripts/Cirssi.pl b/scripts/Cirssi.pl new file mode 100644 index 0000000..947a373 --- /dev/null +++ b/scripts/Cirssi.pl @@ -0,0 +1,722 @@ +use strict; +use vars qw($VERSION %IRSSI); +# Consolidate Irssi Player +# +# Copyright (C) 2009 Dani Soufi +# +# 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 3 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, see . +# +# Change Log: +# v2.0.0: +# - Start/Play(Toggle)/Stop/Pause/Unpause/Next/Previous/Volume MOC Player control functions are added. +# - MOC Player support is implemented. +# v1.1.2: +# - The script is now meant to be a bit more intelligent in dealing with song tags and different user song display settings. +# - Display album name in --details if it exists. +# v1.1.0: +# - Script's name is renamed to Consolidate Irssi Player on global basis to expand it's use in the future. +# - Removed cmd_shuffle{} and cmd_repeat{} functions since they aren't supported anymore by Audacious2. +# - Added use --details flag for bitrate and frequency details in current playing song. +# - Added Jump to specific song in the playing list according to track number. +# - Added Volume control support from Irssi. +# - Updated the script to work with the newest Audacious v2 and audtool2 available. +# v1.0.4: +# - Added Repeat on/off capability +# - Added Shuffle on/off capability +# - Fixed script output handling for audacious version in case audacious isn't running +# - If encountered a problem with audacious version, try changing `audacious --version` to `audtool -v` +# v1.0.3: +# - Added Playlist functionality +# - Added Song details (Bitrate/Frequency/Length/Volume) +# - Current song notice with song details (Optional) +# v1.0.2: +# - The script now handles warning support if you got audacious not running +# - Added track number, current time elapse and total track time +# - Added Stop functionality +# v1.0.1: +# - Added ability to autonotify the channel after skipping a song (optional) +# - Added Skip/Play/Pause/Resume calls +# +# How To Use? +# Copy your script into ~/.irssi/scripts/ directory +# Load your script with /script load audacious in your Irssi Client +# Type '/audacious help' in any channel for script commands +# For autoload insert your script into ~/.irssi/scripts/autorun/ directory +# Even better would be if you placed them in ~/.irssi/scripts/ and created symlinks in autorun directory +# +use Irssi; +use IPC::Open3; + +$VERSION = '2.0.0'; +%IRSSI = ( + authors => "Dani Soufi (compengi)", + contact => "IRC: Freenode network, #ubuntu-lb", + name => "Consolidate Irssi Player", + description => "Controls Audacious2 and MOCP from Irssi", + license => "GNU General Public License", + url => "http://bazaar.launchpad.net/~compengi/%2Bjunk/Cirssi/annotate/head%3A/Cirssi.pl", + changed => "Thu Aug 14 22:43 CET 2009", +); + +################################################################################# +# Please do not change anything below this, unless you know what you are doing. # +################################################################################# + +sub cmd_aud_song { + my ($data, $server, $witem) = @_; + # Get current song information. + if ($witem && ($witem->{type} eq "CHANNEL")) { + + # Read output. + my ( $wtr, $rdr, $err ); + my $pid = open3( $wtr, $rdr, $err, + 'audtool2', '--current-song-tuple-data', 'file-name') or die $!; + + # Make it global. + my $file; + { + local $/; + $file = <$rdr>; + $file =~ s/\.(?i:mp3|cda|aa3|ac3|aif|ape|med|mpu|wave|mpc|oga|wma|ogg|wav|aac|flac)\n//; + } + + if ($data ne "--details") { + if (`ps -C audacious2` =~ /audacious/) { + my $position = `audtool2 --playlist-position`; + # I'm the most nasty variable ever. + my $song = `audtool2 --current-song`; + my $current = `audtool2 --current-song-output-length`; + my $total = `audtool2 --current-song-length`; + my $artist = `audtool2 --current-song-tuple-data artist`; + my $album = `audtool2 current-song-tuple-data album`; + my $title = `audtool2 --current-song-tuple-data title`; + chomp($song); + chomp($position); + chomp($current); + chomp($total); + chomp($artist); + chomp($album); + chomp($title); + + # If we notice that the user sorted his playlist + # by song title, we will try to be nice and parse + # the existing artist for him. + if ($song !~ /$artist/) { + # If $song is different from $album, + # we add the artist to output line. + # Else strip the album from $song. + if ($song !~ /$album/) { + # If we have no song tags, $song will be set to the file's name. + # In this case, we drop the file's extension know to us and print it. + if ($song =~ /$file/) { + $witem->command("/me is listening to: $file ($current/$total)"); + } + else { + $witem->command("/me is listening to: $artist - $song ($current/$total)"); + } + } + else { + $song =~ s/$album - //im; + $witem->command("/me is listening to: $artist - $song ($current/$total)"); + } + } + else { + $witem->command("/me is listening to: $artist - $title ($current/$total)"); + } + } + else { + $witem->print("Audacious is not currently running."); + } + } + if ($data eq "--details") { + # Show more details in the output. + if (`ps -C audacious2` =~ /audacious/) { + my $position = `audtool2 --playlist-position`; + # I'm a nasty variable. + my $song = `audtool2 --current-song`; + my $current = `audtool2 --current-song-output-length`; + my $total = `audtool2 --current-song-length`; + my $bitrate = `audtool2 --current-song-bitrate-kbps`; + my $frequency = `audtool2 --current-song-frequency-khz`; + my $album = `audtool2 current-song-tuple-data album`; + my $artist = `audtool2 --current-song-tuple-data artist`; + my $title = `audtool2 --current-song-tuple-data title`; + chomp($song); + chomp($position); + chomp($current); + chomp($total); + chomp($bitrate); + chomp($frequency); + chomp($album); + chomp($artist); + chomp($title); + + # Check against an empty string. + # If it's empty, we don't print it. + if ($album ne "") { + # Make sure $song doesn't match $artist. + # Else we print the $song as it is. + if ($song !~ /$artist/) { + # If $song is different from $album, + # we add the artist to output line. + # Else strip the album from $song. + if ($song !~ /$album/) { + if ($song =~ /$file/) { + $witem->command("/me is listening to: $artist - $song from $album ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + } + else { + $witem->command("/me is listening to: $artist - $title from $album ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + } + elsif ($song =~ /\[ $album \]/) { + $witem->command("/me is listening to: $artist - $title from $album ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + else { + $song =~ s/$album - //im; + $witem->command("/me is listening to: $song from $album ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + } + elsif ($song =~ /$file/) { + $witem->command("/me is listening to: $file ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + else { + $witem->command("/me is listening to: $artist - $title ($current/$total) [$bitrate Kbps/$frequency KHz]"); + } + } + else { + $witem->print("Audacious is not currently running."); + } + } + return 1; + } +} + +sub cmd_aud_next { + my ($data, $server, $witem) = @_; + # Skip to the next track. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $next = `audtool2 --playlist-advance`; + + $witem->print("Skipped to next track."); + } + else { + $witem->print("Can't skip to next track. Check your Audacious."); + } + return 1; + } +} + +sub cmd_aud_previous { + my ($data, $server, $witem) = @_; + # Skip to the previous track. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $reverse = `audtool2 --playlist-reverse`; + + $witem->print("Skipped to previous track."); + } + else { + $witem->print("Can't skip to next track. Check your Audacious."); + } + return 1; + } +} + +sub cmd_aud_play { + my ($data, $server, $witem) = @_; + # Start playback. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $play = `audtool2 --playback-play`; + + $witem->print("Started playback."); + } + else { + $witem->print("Playback can't be performed now."); + } + return 1; + } +} + +sub cmd_aud_pause { + my ($data, $server, $witem) = @_; + # Pause playback. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $pause = `audtool2 --playback-pause`; + + $witem->print("Paused playback."); + } + else { + $witem->print("Pause can be only performed when Audacious is running."); + } + return 1; + } +} + +sub cmd_aud_stop { + my ($data, $server, $witem) = @_; + # Pause playback. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $stop = `audtool2 --playback-stop`; + + $witem->print("Stopped playback."); + } + else { + $witem->print("This way you can't start Audacious."); + } + return 1; + } +} + +sub cmd_aud_volume { + my ($data, $server, $witem) = @_; + # Set volume and make sure the value is an integer + # that lays between 0 and 100. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + + if ($data eq "") { + $witem->print("Use /audacious volume to set a specific volume value"); + } + elsif ($data < 0 or $data > 100) { + $witem->print("Given value is out of range [0-100]."); + return 0; + } + elsif ($data =~ /^[\d]+$/) { + system 'audtool2','--set-volume', $data; + my $volume = `audtool2 --get-volume`; + chomp($volume); + $witem->print("Volume is changed to $volume%%"); + } + else { + $witem->print("Please use a value [0-100] instead."); + } + } + else { + $witem->print("Volume can't be set in the current state."); + } + return 1; + } +} + +sub cmd_aud_jump { + my ($data, $server, $witem) = @_; + # Jump to a specific track, making sure that + # the selected track number exists. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + + if ($data eq "") { + $witem->print("Use /audacious jump number to jump to it in your playlist."); + } + elsif ($data =~ /^[\d]+$/) { + # Many thanks to Khisanth for this awesome fix! + my ( $wtr, $rdr, $err ); + my $pid = open3( $wtr, $rdr, $err, + 'audtool2', '--playlist-jump', $data) or die $!; + my $output; + { + local $/; + $output = <$rdr>; + } + if ($output =~ /invalid/) { + $witem->print("Track #$data isn't found in your playlist."); + } + else { + $witem->print("Jumped to track #$data."); + } + } + else { + $witem->print("Please use a valid integer."); + } + } + else { + $witem->print("Start your audacious first."); + } + return 1; + } +} + +sub cmd_aud_playlist { + my ($data, $server, $witem) = @_; + # Displays entire playlist loaded. + if (`ps -C audacious2` =~ /audacious/) { + my $display = `audtool2 --playlist-display`; + chomp($display); + + Irssi::print("$display"); + } + else { + $witem->print("Start your player first."); + } + return 1; +} + +sub cmd_aud_details { + my ($data, $server, $witem) = @_; + # Displays current song's details. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if (`ps -C audacious2` =~ /audacious/) { + my $bitrate = `audtool2 --current-song-bitrate-kbps`; + my $frequency = `audtool2 --current-song-frequency-khz`; + my $length = `audtool2 --current-song-length`; + my $volume = `audtool2 --get-volume`; + chomp($bitrate); + chomp($frequency); + chomp($length); + chomp($volume); + + $witem->print("Current song details: rate: $bitrate kbps - freq: $frequency KHz - l: $length min - vol: $volume%%"); + } + else { + $witem->print("Your player doesn't seem to be running"); + } + return 1; + } +} + +sub cmd_aud_version { + my ($data, $server, $witem) = @_; + # Displays version information to the channel. + if ($witem && ($witem->{type} eq "CHANNEL")) { + if ($data eq "--audtool") { + my $audtool = `audtool2 --version`; + chop $audtool; + + $witem->command("/me is running: Consolidate Irssi Player v$VERSION with $audtool"); + } + elsif ($data eq "--audacious") { + my $audacious = `audacious2 --version`; + chop $audacious; + + $witem->command("/me is running: Consolidate Irssi Player v$VERSION with $audacious"); + } + return 1; + } +} + +sub cmd_audacious { + my ($data, $server, $witem) = @_; + if ($data =~ m/^[(song)|(next)|(previous)|(play)|(pause)|(stop)|(help)|(volume)|(jump)|(playlist)|(details)|(about)]/i) { + Irssi::command_runsub('audacious', $data, $server, $witem); + } + else { + Irssi::print("Use /audacious