weechat- me personal weechat setup 🔵🟢 |
git clone git://git.acid.vegas/weechat.git |
Log | Files | Refs | Archive | README |
cflood.pl (4571B)
1 #{{{ BSD License 2 # Copyright (c) 2008 hzu/zionist 3 # All rights reserved. 4 # 5 # Redistribution and use in source and binary forms, with or 6 # without modification, are permitted provided that the following 7 # conditions are met: 8 # 9 # 1. Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # 2. The name of the author may not be used to endorse or promote products 12 # derived from this software without specific prior written permission. 13 # 14 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 16 # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 17 # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 #}}} 25 26 # Ported from irssi to WeeChat by the Krusty Krab 27 28 use strict; 29 use warnings; 30 no strict 'subs'; 31 32 my $SCRIPT_NAME = 'colourflood'; 33 my $SCRIPT_AUTHOR = 'hzu'; 34 my $SCRIPT_VERSION = '0.3'; 35 my $SCRIPT_LICENCE = 'BSD'; 36 my $SCRIPT_DESC = 'A-rab style ircing'; 37 38 my $USAGE = <<EOF; 39 options: 40 -r Random back & foreground colours (default) 41 -f Amount of times the message is flooded 42 -fg font colour, available colours: 43 black, blue, green 44 lightred, red, magenta, orange 45 yellow, lightgreen, cyan, 46 lightcyan, lightblue, 47 lightmagenta, gray, lightgray. 48 -bg background colour, available colours: 49 black, blue, green, red, 50 magenta, orange, green, cyan, 51 lightcyan, lightblue, 52 lightmagenta, gray, lightgray 53 EOF 54 55 our %clr = ( 56 black => 1, 57 blue => 2, 58 green => 3, 59 lightred => 4, 60 red => 5, 61 magenta => 6, 62 orange => 7, 63 yellow => 8, 64 lightgreen => 9, 65 cyan => 10, 66 lightcyan => 11, 67 lightblue => 12, 68 lightmagenta => 13, 69 gray => 14, 70 lightgray => 15, 71 ); 72 73 if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION, 74 $SCRIPT_LICENCE, $SCRIPT_DESC, '', '')) { 75 weechat::hook_command('cflood', $SCRIPT_DESC, '[options] text', 76 $USAGE, '', 'cmd_cflood', ''); 77 78 my %OPTIONS = ( 79 dir => ['Database directory', 80 weechat::info_get('weechat_dir', '').'/yiffs'], 81 db => ['Default database', 'yiffs'], 82 solodb => ['Default database when nick is omitted', 'solos'], 83 ); 84 85 for my $option (keys %OPTIONS) { 86 weechat::config_set_plugin($option, $OPTIONS{$option}[1]) 87 unless weechat::config_is_set_plugin($option); 88 weechat::config_set_desc_plugin($option, $OPTIONS{$option}[0]); 89 } 90 } 91 92 sub colour { 93 my ($fg, $bg, $text) = @_; 94 my $fore = ($fg =~ /^[0-9][0-9]?$/) ? $fg : $clr{$fg}; 95 my $back = ($fg =~ /^[0-9][0-9]?$/) ? $bg : $clr{$bg}; 96 $fore-- if $fore == $back; 97 $text = "\003$fore,$back $text \003$back,$fore $text "; 98 $text x= (int 400 / length $text); 99 return "$text\003"; 100 } 101 102 sub parse { 103 my @args = ( split / +/, shift ); 104 my ( %todo, $text, $body ); 105 106 while ( ($_ = shift @args) ne '' ) { 107 /^-r$/ and next; 108 /^-f$/ and $todo{f} = shift @args, next; 109 /^-fg$/ and $todo{fg} = shift @args, next; 110 /^-bg$/ and $todo{bg} = shift @args, next; 111 /^-/ and weechat::print('', weechat::prefix('error'). 112 'Invalid arguments (see /help cflood)'), return; 113 $text = @args < 1 ? $_ : "$_ " . join ' ', @args; 114 last; 115 } 116 117 if (!(defined $todo{fg}) || !(defined $todo{bg})) { 118 $body = ""; 119 my @rnd_clr = keys %clr; 120 foreach ( 1 .. (defined $todo{f} ? $todo{f} : 1 ) ) { 121 $body .= colour($rnd_clr[rand @rnd_clr], 122 $rnd_clr[rand @rnd_clr], $text, $todo{f}); 123 $body .= "\n"; 124 } 125 } else { 126 $body = ""; 127 foreach ( 1 .. (defined $todo{f} ? $todo{f} : 1 ) ) { 128 $body .= colour( $todo{fg}, $todo{bg}, $text ); 129 $body .= "\n"; 130 } 131 } 132 return $body; 133 } 134 135 sub cmd_cflood { 136 my (undef, $buffer, $data) = @_; 137 my $ret; 138 139 return weechat::WEECHAT_RC_OK if ($data eq ''); 140 141 chomp( $ret = parse($data) ); 142 143 if ($ret =~ /\n/) { 144 map { weechat::command($buffer, "/msg * $_") } (split /\n/, $ret); 145 } else { 146 weechat::command($buffer, "/msg * $ret"); 147 } 148 149 return weechat::WEECHAT_RC_OK; 150 }