Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.79 KB | None | 0 0
  1. # Fixes for multiple servers and window items by dg
  2. #
  3. # 2003-08-27 coekie:
  4. # - use item names and server tags, fixes irssi crash if window item or server is destroyed
  5. #
  6. # 2003-08-19
  7. # - changed stimr stop code a bit.
  8. # should fix the random stimr o.O never happened to me before.
  9. #
  10. # 2002-12-21 darix:
  11. # - nearly complete rewrite ;) the old version wasnt "use strict;" capable =)
  12. # - still some warnings with "use warnings;"
  13. # - use of command_runsub now :)
  14. #
  15.  
  16. use strict;
  17. use Data::Dumper;
  18. use warnings;
  19. use vars qw ($VERSION %IRSSI);
  20. use Irssi 20020325 qw (command_bind command_runsub command timeout_add timeout_remove signal_add_first);
  21.  
  22. $VERSION = '0.6';
  23. %IRSSI = (
  24. authors => 'Kimmo Lehto, Marcus Rueckert',
  25. contact => 'kimmo@a-men.org, darix@irssi.org' ,
  26. name => 'stimr',
  27. description => 'Provides /stimr command for mIRC/BitchX type stimr functionality.',
  28. license => 'Public Domain',
  29. changed => '2015-02-07'
  30. );
  31.  
  32. our %stimrs;
  33. # my %stimr = { repeat => \d+, command => '' , windowitem => NULL , server=> NULL, stimr = NULL};
  34.  
  35. sub stimr_command {
  36. my ( $name ) = @_;
  37. if ( exists ( $stimrs{$name} ) ) {
  38. if ( $stimrs{$name}->{'repeat'} != -1 ) {
  39. if ( $stimrs{$name}->{'repeat'}-- == 0) {
  40. cmd_stimrstop( $name );
  41. return;
  42. }
  43. }
  44.  
  45. my ($server, $item);
  46. if ($stimrs{$name}->{'server'}) {
  47. $server = Irssi::server_find_tag( $stimrs{$name}->{'server'} );
  48. }
  49. if ( $server ) {
  50. if ( $stimrs{$name}->{'windowitem'}) {
  51. $item = $server->window_find_item( $stimrs{$name}->{'windowitem'} );
  52. }
  53. ($item ? $item : $server)->command( $stimrs{$name}->{'command'} );
  54. } else {
  55. command( $stimrs{$name}->{'command'} );
  56. }
  57. }
  58. }
  59.  
  60. sub cmd_stimrstop {
  61. my ( $name ) = @_;
  62.  
  63. if ( exists ( $stimrs{$name} ) ) {
  64. timeout_remove($stimrs{$name}->{'stimr'});
  65. $stimrs{$name} = ();
  66. delete ( $stimrs{$name} );
  67. #print( CRAP "stimr \"$name\" stopped." );
  68. }
  69. else {
  70. #print( CRAP "\cBstimr:\cB No such stimr \"$name\"." );
  71. }
  72. }
  73.  
  74. sub cmd_stimr_help {
  75. print ( <<EOF
  76.  
  77. stimr LIST
  78. stimr ADD <name> <interval in seconds> [<repeat>] <command>
  79. stimr STOP <name>
  80.  
  81. repeat value of 0 means unlimited too
  82.  
  83. EOF
  84. );
  85. }
  86.  
  87. command_bind 'stimr add' => sub {
  88. my ( $data, $server, $item ) = @_;
  89. my ( $name, $interval, $times, $command );
  90.  
  91. if ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(-?\d+)\s+(.*)$/ ) {
  92. ( $name, $interval, $times, $command ) = ( $1, $2, $3, $4 );
  93. $times = -1 if ( $times == 0 );
  94. }
  95. elsif ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(.*)$/ )
  96. {
  97. ( $name, $interval, $times, $command ) = ( $1, $2, -1, $3 );
  98. }
  99. else {
  100. print( CRAP "\cBstimr:\cB parameters not understood. commandline was: stimr add $data");
  101. return;
  102. };
  103.  
  104. if ( $times < -1 ) {
  105. print( CRAP "\cBstimr:\cB repeat should be greater or equal to -1" );
  106. return;
  107. };
  108.  
  109. if ( $command eq "" ) {
  110. print( CRAP "\cBstimr:\cB command is empty commandline was: stimr add $data" );
  111. return;
  112. };
  113.  
  114. if ( exists ( $stimrs{$name} ) ) {
  115. print( CRAP "\cBstimr:\cB stimr \"$name\" already active." );
  116. }
  117. else {
  118. #$stimrs{$name} = {};
  119. $stimrs{$name}->{'repeat'} = $times;
  120. $stimrs{$name}->{'interval'} = $interval;
  121. $stimrs{$name}->{'command'} = $command;
  122. if ($item) {
  123. $stimrs{$name}->{'windowitem'} = $item->{'name'};
  124. }
  125. if ($server) {
  126. $stimrs{$name}->{'server'} = $server->{'tag'};
  127. }
  128.  
  129. if ( $times == -1 ) {
  130. $times = 'until stopped.';
  131. }
  132. else {
  133. $times .= " times.";
  134. }
  135.  
  136. #print( CRAP "Starting stimr \"$name\" repeating \"$command\" every $interval seconds $times" );
  137.  
  138. $stimrs{$name}->{'stimr'} = timeout_add( $interval * 1000, \&stimr_command, $name );
  139. }
  140. };
  141.  
  142. command_bind 'stimr list' => sub {
  143. print( CRAP "Active stimrs:" );
  144. foreach my $name ( keys %stimrs ) {
  145. if ( $stimrs{$name}->{repeat} == -1 ) {
  146. print( CRAP "$name = $stimrs{$name}->{'command'} (until stopped)");
  147. }
  148. else {
  149. print( CRAP "$name = $stimrs{$name}->{'command'} ($stimrs{$name}->{'repeat'} repeats left)" );
  150. }
  151. }
  152. print( CRAP "End of /stimr list" );
  153. };
  154.  
  155. command_bind 'stimr stop' => sub {
  156. my ( $data, $server, $item ) = @_;
  157. cmd_stimrstop ($data);
  158. };
  159.  
  160. command_bind 'stimr help' => sub { cmd_stimr_help() };
  161.  
  162. command_bind 'stimr' => sub {
  163. my ( $data, $server, $item ) = @_;
  164. $data =~ s/\s+$//g;
  165. command_runsub ( 'stimr', $data, $server, $item ) ;
  166. };
  167.  
  168.  
  169. signal_add_first 'default command stimr' => sub {
  170. #
  171. # gets triggered if called with unknown subcommand
  172. #
  173. cmd_stimr_help()
  174. };
  175.  
  176. sub event_privmsg {
  177. # my @ONE = ('ONE', 'DWARF CASSOWARY', 'X', '20 INCH SPINNAZ', 'HODOR',
  178. # 'BALLSACK', 'SOLO',
  179. # '1', 'UNO', 'YAHTZEE!', 'DONKEYPUNCH');
  180. my @ONE = (" \x02\003131");
  181.  
  182. # my @TWO = ('TWO', 'BITCHES', 'HOE DA DOE',
  183. # 'PUMPERNICKEL', 'DOS', '2', 'ZEBRA PENIS',
  184. # 'PRETZEL', 'TWAT', 'DIRTY SANCHEZ');
  185. my @TWO = (" \00307TWOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
  186.  
  187. # my @THREE = ('THREE', 'PENIS WRINKLE', '43', 'MONEY', 'HOLD THE DOOR',
  188. # 'TRES', '3', 'REUBEN', 'KELLY CLARKSON',
  189. # 'SET', 'TRIO', 'PIGFACE', 'CHARLESTON',
  190. # 'YEE YEE');
  191. my @THREE = (" \00303THREEEEEEEEEEEEEEEEEEEE");
  192.  
  193. # my @GO = ('GO',
  194. # 'DO IT NOWUH',
  195. # 'GET TO DA CHOPPAH',
  196. # 'fire in the hole!',
  197. # 'and.............GO',
  198. # '99 bottles of be...oh, sorry. GO',
  199. # 'OFF WITH YOU!',
  200. # 'you have beautiful eyes, maybe we could get together after...GO!');
  201. my @GO = ("\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO\00304GO\00303GO\00307GO\00313GO");
  202.  
  203. # my @AFTER = ('And now his watch has ended',
  204. # 'woooooooooooooo',
  205. # '\'Murica, fuck ya',
  206. # 'Make america great again....by doing shots until you believe it',
  207. # 'Beeeeeeeeer is liquid bread it\'s good for you!',
  208. # 'Another?',
  209. # 'I\'ll have what she\'s having',
  210. # 'red red wiiiiiiiiinnnnneeee',
  211. # 'MAS TEQUILLA!!',
  212. # 'Like, what if there really is a god....you know?');
  213.  
  214. my @AFTER = ("\x02\00304GET READY FOR THE SHOT/BONG/HIT/PLUG/ETC YOU KNOW WHAT TO DO");
  215.  
  216. my ($server, $data, $nick, $mask) = @_;
  217. my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;
  218. return if ( $text !~ /^!/i );
  219.  
  220. if ( $text =~ /^!shawteh+/i ) {
  221. if (!($target =~ /^#/)) { $target = $nick };
  222. my $stag = $server->{tag};
  223. command("stimr stop shawtehN");
  224. command("stimr stop shawteh3");
  225. command("stimr stop shawteh2");
  226. command("stimr stop shawteh1");
  227. command("stimr stop shawteh0");
  228. command("stimr add shawtehN 1 1 msg -$stag $target $AFTER[rand @AFTER]");
  229. command("stimr add shawteh3 3 1 msg -$stag $target $THREE[rand @THREE]");
  230. command("stimr add shawteh2 4 1 msg -$stag $target $TWO[rand @TWO]");
  231. command("stimr add shawteh1 5 1 msg -$stag $target $ONE[rand @ONE]");
  232. command("stimr add shawteh0 6 1 msg -$stag $target $GO[rand @GO]");
  233. # command("stimr add shawtehN 15 1 msg -$stag $target $AFTER[rand @AFTER]");
  234. }
  235. };
  236.  
  237. Irssi::signal_add('event privmsg', 'event_privmsg');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement