Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Fixes for multiple servers and window items by dg
- #
- # 2003-08-27 coekie:
- # - use item names and server tags, fixes irssi crash if window item or server is destroyed
- #
- # 2003-08-19
- # - changed stimr stop code a bit.
- # should fix the random stimr o.O never happened to me before.
- #
- # 2002-12-21 darix:
- # - nearly complete rewrite ;) the old version wasnt "use strict;" capable =)
- # - still some warnings with "use warnings;"
- # - use of command_runsub now :)
- #
- use strict;
- use Data::Dumper;
- use warnings;
- use vars qw ($VERSION %IRSSI);
- use Irssi 20020325 qw (command_bind command_runsub command timeout_add timeout_remove signal_add_first);
- $VERSION = '0.6';
- %IRSSI = (
- authors => 'Kimmo Lehto, Marcus Rueckert',
- contact => 'kimmo@a-men.org, darix@irssi.org' ,
- name => 'stimr',
- description => 'Provides /stimr command for mIRC/BitchX type stimr functionality.',
- license => 'Public Domain',
- changed => '2015-02-07'
- );
- our %stimrs;
- # my %stimr = { repeat => \d+, command => '' , windowitem => NULL , server=> NULL, stimr = NULL};
- sub stimr_command {
- my ( $name ) = @_;
- if ( exists ( $stimrs{$name} ) ) {
- if ( $stimrs{$name}->{'repeat'} != -1 ) {
- if ( $stimrs{$name}->{'repeat'}-- == 0) {
- cmd_stimrstop( $name );
- return;
- }
- }
- my ($server, $item);
- if ($stimrs{$name}->{'server'}) {
- $server = Irssi::server_find_tag( $stimrs{$name}->{'server'} );
- }
- if ( $server ) {
- if ( $stimrs{$name}->{'windowitem'}) {
- $item = $server->window_find_item( $stimrs{$name}->{'windowitem'} );
- }
- ($item ? $item : $server)->command( $stimrs{$name}->{'command'} );
- } else {
- command( $stimrs{$name}->{'command'} );
- }
- }
- }
- sub cmd_stimrstop {
- my ( $name ) = @_;
- if ( exists ( $stimrs{$name} ) ) {
- timeout_remove($stimrs{$name}->{'stimr'});
- $stimrs{$name} = ();
- delete ( $stimrs{$name} );
- #print( CRAP "stimr \"$name\" stopped." );
- }
- else {
- #print( CRAP "\cBstimr:\cB No such stimr \"$name\"." );
- }
- }
- sub cmd_stimr_help {
- print ( <<EOF
- stimr LIST
- stimr ADD <name> <interval in seconds> [<repeat>] <command>
- stimr STOP <name>
- repeat value of 0 means unlimited too
- EOF
- );
- }
- command_bind 'stimr add' => sub {
- my ( $data, $server, $item ) = @_;
- my ( $name, $interval, $times, $command );
- if ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(-?\d+)\s+(.*)$/ ) {
- ( $name, $interval, $times, $command ) = ( $1, $2, $3, $4 );
- $times = -1 if ( $times == 0 );
- }
- elsif ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(.*)$/ )
- {
- ( $name, $interval, $times, $command ) = ( $1, $2, -1, $3 );
- }
- else {
- print( CRAP "\cBstimr:\cB parameters not understood. commandline was: stimr add $data");
- return;
- };
- if ( $times < -1 ) {
- print( CRAP "\cBstimr:\cB repeat should be greater or equal to -1" );
- return;
- };
- if ( $command eq "" ) {
- print( CRAP "\cBstimr:\cB command is empty commandline was: stimr add $data" );
- return;
- };
- if ( exists ( $stimrs{$name} ) ) {
- print( CRAP "\cBstimr:\cB stimr \"$name\" already active." );
- }
- else {
- #$stimrs{$name} = {};
- $stimrs{$name}->{'repeat'} = $times;
- $stimrs{$name}->{'interval'} = $interval;
- $stimrs{$name}->{'command'} = $command;
- if ($item) {
- $stimrs{$name}->{'windowitem'} = $item->{'name'};
- }
- if ($server) {
- $stimrs{$name}->{'server'} = $server->{'tag'};
- }
- if ( $times == -1 ) {
- $times = 'until stopped.';
- }
- else {
- $times .= " times.";
- }
- #print( CRAP "Starting stimr \"$name\" repeating \"$command\" every $interval seconds $times" );
- $stimrs{$name}->{'stimr'} = timeout_add( $interval * 1000, \&stimr_command, $name );
- }
- };
- command_bind 'stimr list' => sub {
- print( CRAP "Active stimrs:" );
- foreach my $name ( keys %stimrs ) {
- if ( $stimrs{$name}->{repeat} == -1 ) {
- print( CRAP "$name = $stimrs{$name}->{'command'} (until stopped)");
- }
- else {
- print( CRAP "$name = $stimrs{$name}->{'command'} ($stimrs{$name}->{'repeat'} repeats left)" );
- }
- }
- print( CRAP "End of /stimr list" );
- };
- command_bind 'stimr stop' => sub {
- my ( $data, $server, $item ) = @_;
- cmd_stimrstop ($data);
- };
- command_bind 'stimr help' => sub { cmd_stimr_help() };
- command_bind 'stimr' => sub {
- my ( $data, $server, $item ) = @_;
- $data =~ s/\s+$//g;
- command_runsub ( 'stimr', $data, $server, $item ) ;
- };
- signal_add_first 'default command stimr' => sub {
- #
- # gets triggered if called with unknown subcommand
- #
- cmd_stimr_help()
- };
- sub event_privmsg {
- # my @ONE = ('ONE', 'DWARF CASSOWARY', 'X', '20 INCH SPINNAZ', 'HODOR',
- # 'BALLSACK', 'SOLO',
- # '1', 'UNO', 'YAHTZEE!', 'DONKEYPUNCH');
- my @ONE = (" \x02\003131");
- # my @TWO = ('TWO', 'BITCHES', 'HOE DA DOE',
- # 'PUMPERNICKEL', 'DOS', '2', 'ZEBRA PENIS',
- # 'PRETZEL', 'TWAT', 'DIRTY SANCHEZ');
- my @TWO = (" \00307TWOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
- # my @THREE = ('THREE', 'PENIS WRINKLE', '43', 'MONEY', 'HOLD THE DOOR',
- # 'TRES', '3', 'REUBEN', 'KELLY CLARKSON',
- # 'SET', 'TRIO', 'PIGFACE', 'CHARLESTON',
- # 'YEE YEE');
- my @THREE = (" \00303THREEEEEEEEEEEEEEEEEEEE");
- # my @GO = ('GO',
- # 'DO IT NOWUH',
- # 'GET TO DA CHOPPAH',
- # 'fire in the hole!',
- # 'and.............GO',
- # '99 bottles of be...oh, sorry. GO',
- # 'OFF WITH YOU!',
- # 'you have beautiful eyes, maybe we could get together after...GO!');
- my @GO = ("\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO");
- # my @AFTER = ('And now his watch has ended',
- # 'woooooooooooooo',
- # '\'Murica, fuck ya',
- # 'Make america great again....by doing shots until you believe it',
- # 'Beeeeeeeeer is liquid bread it\'s good for you!',
- # 'Another?',
- # 'I\'ll have what she\'s having',
- # 'red red wiiiiiiiiinnnnneeee',
- # 'MAS TEQUILLA!!',
- # 'Like, what if there really is a god....you know?');
- my @AFTER = ("\x02\00304GET READY FOR THE SHOT/BONG/HIT/PLUG/ETC YOU KNOW WHAT TO DO");
- my ($server, $data, $nick, $mask) = @_;
- my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
- return if ( $text !~ /^!/i );
- if ( $text =~ /^!shawteh+/i ) {
- if (!($target =~ /^#/)) { $target = $nick };
- my $stag = $server->{tag};
- command("stimr stop shawtehN");
- command("stimr stop shawteh3");
- command("stimr stop shawteh2");
- command("stimr stop shawteh1");
- command("stimr stop shawteh0");
- command("stimr add shawtehN 1 1 msg -$stag $target $AFTER[rand @AFTER]");
- command("stimr add shawteh3 3 1 msg -$stag $target $THREE[rand @THREE]");
- command("stimr add shawteh2 4 1 msg -$stag $target $TWO[rand @TWO]");
- command("stimr add shawteh1 5 1 msg -$stag $target $ONE[rand @ONE]");
- command("stimr add shawteh0 6 1 msg -$stag $target $GO[rand @GO]");
- # command("stimr add shawtehN 15 1 msg -$stag $target $AFTER[rand @AFTER]");
- }
- };
- Irssi::signal_add('event privmsg', 'event_privmsg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement