weechat

- me personal weechat setup 🔵🟢
git clone git://git.acid.vegas/weechat.git
Log | Files | Refs | Archive | README

fuckyou.pl (5875B)

      1 # Ported from irssi to WeeChat by the Krusty Krab
      2 
      3 use Time::HiRes qw(time);
      4 use Digest::MD5 qw(md5_hex);
      5 
      6 
      7 #__        ___    ____  _   _ ___ _   _  ____   _   _ ____ ___ _   _  ____
      8 #\ \      / / \  |  _ \| \ | |_ _| \ | |/ ___| | | | / ___|_ _| \ | |/ ___|
      9 # \ \ /\ / / _ \ | |_) |  \| || ||  \| | |  _  | | | \___ \| ||  \| | |  _
     10 #  \ V  V / ___ \|  _ <| |\  || || |\  | |_| | | |_| |___) | || |\  | |_| |
     11 #   \_/\_/_/   \_\_| \_\_| \_|___|_| \_|\____|  \___/|____/___|_| \_|\____|
     12 #
     13 # _____ _   _ _____ ____  _____   ____   ____ ____  ___ ____ _____ ____
     14 #|_   _| | | | ____/ ___|| ____| / ___| / ___|  _ \|_ _|  _ \_   _/ ___|
     15 #  | | | |_| |  _| \___ \|  _|   \___ \| |   | |_) || || |_) || | \___ \
     16 #  | | |  _  | |___ ___) | |___   ___) | |___|  _ < | ||  __/ | |  ___) |
     17 #  |_| |_| |_|_____|____/|_____| |____/ \____|_| \_\___|_|    |_| |____/
     18 #
     19 # __  __    _ __   __  ____  _____    _    _     _  __   __
     20 #|  \/  |  / \\ \ / / |  _ \| ____|  / \  | |   | | \ \ / /
     21 #| |\/| | / _ \\ V /  | |_) |  _|   / _ \ | |   | |  \ \//
     22 #| |  | |/ ___ \| |   |  _ <| |___ / ___ \| |___| |___| |
     23 #|_|  |_/_/   \_\_|   |_| \_\_____/_/   \_\_____|_____|_|
     24 #
     25 # _____ _   _  ____ _  _____ _   _  ____      _    _   _ _   _  _____   __
     26 #|  ___| | | |/ ___| |/ /_ _| \ | |/ ___|    / \  | \ | | \ | |/ _ \ \ / /
     27 #| |_  | | | | |   | ' / | ||  \| | |  _    / _ \ |  \| |  \| | | | \ V /
     28 #|  _| | |_| | |___| . \ | || |\  | |_| |  / ___ \| |\  | |\  | |_| || |
     29 #|_|    \___/ \____|_|\_\___|_| \_|\____| /_/   \_\_| \_|_| \_|\___/ |_|
     30 #
     31 #__   _____  _   _ ____    _   _ ____  _____ ____  ____
     32 #\ \ / / _ \| | | |  _ \  | | | / ___|| ____|  _ \/ ___|
     33 # \ V / | | | | | | |_) | | | | \___ \|  _| | |_) \___ \
     34 #  | || |_| | |_| |  _ <  | |_| |___) | |___|  _ < ___) |
     35 #  |_| \___/ \___/|_| \_\  \___/|____/|_____|_| \_\____/
     36 
     37 
     38 my $SCRIPT_NAME = 'fuckyou';
     39 my $SCRIPT_AUTHOR = 'Goat-See <mrtheplague@gmail.com>';
     40 my $SCRIPT_VERSION = '2.3';
     41 my $SCRIPT_LICENCE = 'urmom';
     42 my $SCRIPT_DESC = '/fuckyou NICK numberchannels';
     43 
     44 my %OPTIONS = (
     45 	forcejoin => ['Command to forcejoin. ratbox uses forcejoin, unreal sajoin',
     46 		'forcejoin'],
     47 	forcepart => ['Command to forcepart. ratbox uses forcepart, unreal sapart',
     48 		'forcepart'],
     49 	furry => ['Channel prefix (include # or &)', '&HYE'],
     50 	parallel => ['Number of channels to send per forcejoin command', 1],
     51 	whois_cmd => ['Prefix to whois user (e.g. for ratbox operspy, "/whois !")',
     52 		'/whois '],
     53 	);
     54 
     55 sub fuckyou
     56 {
     57 	my $buffer = shift;
     58 	my $nig = $$ * time;
     59 	my @jews;
     60 	push @jews, "${FURRY}_".md5_hex($nig + $_) for (1..$PARALLEL);
     61 
     62 	weechat::command($buffer, "/quote $FORCEJOIN $target ".join(',', @jews));
     63 
     64 	return weechat::WEECHAT_RC_OK;
     65 }
     66 
     67 sub cmd_fuckyou
     68 {
     69 	my (undef, $buffer, $data) = @_;
     70 	my $server = weechat::buffer_get_string($buffer, 'localvar_server');
     71 	my $amt_end;
     72 	($target, $amt_end) = split / +/, $data;
     73 	our ($FORCEJOIN, $FURRY, $PARALLEL) = (
     74 		weechat::config_get_plugin('forcejoin'),
     75 		weechat::config_get_plugin('furry'),
     76 		weechat::config_get_plugin('parallel'));
     77 
     78 	weechat::unhook($signal) if $signal;
     79 	weechat::unhook($timer) if $timer;
     80 
     81 	unless ($target) {
     82 		weechat::print($buffer, 'Stopped any current /fuckyou');
     83 		return weechat::WEECHAT_RC_OK;
     84 	}
     85 	$amt_end //= 0;
     86 
     87 	$signal = weechat::hook_signal("$server,irc_raw_in_402", 'irc_402', '');
     88 	$timer = weechat::hook_timer(50, 0, $amt_end, 'fuckyou', $buffer);
     89 
     90 	return weechat::WEECHAT_RC_OK;
     91 }
     92 
     93 sub cmd_unfuckyou
     94 {
     95 	my (undef, $buffer, $data) = @_;
     96 	my ($server, $channel) = (
     97 		weechat::buffer_get_string($buffer, 'localvar_server'),
     98 		weechat::buffer_get_string($buffer, 'localvar_channel')
     99 		);
    100 	my $WHOIS = weechat::config_get_plugin('whois_cmd');
    101 
    102 	unless ($data) {
    103 		weechat::print($buffer, '/unfuckyou user user2 user3');
    104 		return weechat::WEECHAT_RC_OK;
    105 	}
    106 
    107 	foreach my $dick (split / +/, $data) {
    108 		weechat::hook_hsignal_send(
    109 			'irc_redirect_command',
    110 			{
    111 				server => "$server",
    112 				pattern => "whois",
    113 				signal => "sigwhois"
    114 			});
    115 		weechat::hook_signal_send(
    116 			'irc_input_send',
    117 			weechat::WEECHAT_HOOK_SIGNAL_STRING,
    118 			"$server;;1;;$WHOIS$dick"
    119 			);
    120 	}
    121 
    122 	return weechat::WEECHAT_RC_OK;
    123 }
    124 
    125 sub event_whois_channels
    126 {
    127 	my %hashtable = %{$_[2]};
    128 	my $FORCEPART = weechat::config_get_plugin('forcepart');
    129 	my $FURRY = weechat::config_get_plugin('furry');
    130 	my $counter = 0;
    131 	my ($nick, $channels);
    132 
    133 	for (split /^/, $hashtable{output}) {
    134 		if (/^:[^ ]* 319 [^ ]+ ([^ ]+) :(.*)$/) {
    135 			($nick, $channels) = ($1, $2);
    136 		} else { next; }
    137 
    138 		$channels =~ s/ +$//;
    139 
    140 		my @niggers = split / +/, $channels;
    141 		foreach (@niggers)
    142 		{
    143 			s/^[!@%+]*([&#])/$1/;
    144 			if(/${FURRY}_[a-f0-9]+/i)
    145 			{
    146 				#Irssi::print("Forceparting $nick from $_");
    147 				weechat::command('', "/quote $FORCEPART $nick $_");
    148 				++$counter;
    149 			}
    150 		}
    151 	}
    152 
    153 	weechat::print('', "Forceparted $nick from $counter channels")
    154 		if $counter;
    155 
    156 	return weechat::WEECHAT_RC_OK;
    157 }
    158 
    159 sub irc_402 {
    160 	my $message = pop;
    161 	my $targmatch = quotemeta $target;
    162 
    163 	return weechat::WEECHAT_RC_OK
    164 		unless ($message =~ /^[^ ]* 402 [^ ]+ $targmatch /i);
    165 	weechat::unhook($signal);
    166 	weechat::unhook($timer);
    167 
    168 	return weechat::WEECHAT_RC_OK;
    169 }
    170 
    171 if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
    172  $SCRIPT_LICENCE, $SCRIPT_DESC, '', '')) {
    173 	weechat::hook_command('fuckyou', '', '[<nick> [<amt>]]',
    174 		"if nick is not given, stops current fuckyou, if any is running\n\n".
    175 		"amt is 0 by default - user will be fuckyoud until they disconnect\n".
    176 		"or you stop it manually\n",
    177 		'', 'cmd_fuckyou', '');
    178 	weechat::hook_command('unfuckyou', '', '<nick> [nick...]', '', '',
    179 		'cmd_unfuckyou', '');
    180 	weechat::hook_hsignal('irc_redirection_sigwhois_whois',
    181 		'event_whois_channels', '');
    182 
    183 	for my $option (keys %OPTIONS) {
    184 		weechat::config_set_plugin($option, $OPTIONS{$option}[1])
    185 		 unless weechat::config_is_set_plugin($option);
    186 		weechat::config_set_desc_plugin($option, $OPTIONS{$option}[0]);
    187 	}
    188 }