diff options
| -rw-r--r-- | Plugin/Admin.pm | 24 | ||||
| -rwxr-xr-x | idalius.pl | 142 | 
2 files changed, 42 insertions, 124 deletions
| diff --git a/Plugin/Admin.pm b/Plugin/Admin.pm index 1151fc4..ad07da2 100644 --- a/Plugin/Admin.pm +++ b/Plugin/Admin.pm @@ -26,6 +26,7 @@ sub configure {  	$cmdref->("ignore", sub { $self->ignore(@_); } );  	$cmdref->("don't ignore", sub { $self->do_not_ignore(@_); } ); +	$cmdref->("who are you ignoring?", sub { $self->dump_ignore(@_); } );  	return $self;  } @@ -111,6 +112,7 @@ sub kick {  	return unless is_admin($who);  	return "Syntax: kick <channel> <nick> [reason]" unless @arguments >= 2; +	# FIXME should use $where if it's a channel (?)  	my ($channel, $kickee, undef, $reason) = $rest =~ /^(\S+)\s(\S+)((?:\s)(.*))?$/;  	if ($channel and $kickee) {  		my $nick = (split /!/, $who)[0]; @@ -147,7 +149,9 @@ sub ignore {  	return unless is_admin($who);  	return "Syntax: ignore <nick>" unless @arguments == 1; -	$logger->("ERROR: UNIMPLEMENTED FEATURE"); +	push @{$config{ignore}}, $arguments[0]; + +	return "Ignoring $arguments[0]";  }  sub do_not_ignore { @@ -156,7 +160,23 @@ sub do_not_ignore {  	return unless is_admin($who);  	return "Syntax: don't ignore <nick>" unless @arguments == 1; -	$logger->("ERROR: UNIMPLEMENTED FEATURE"); +	my $target = $arguments[0]; + +	if (grep { $_ eq $target} @{$config{ignore}}) { +		@{$config{ignore}} = grep { $_ ne $target } @{$config{ignore}}; +		return "No longer ignoring $target."; +	} else { +		return "I wasn't ignoring $target anyway."; +	} +} + +sub dump_ignore { +	my ($self, $irc, $logger, $who, $where, $rest, @arguments) = @_; + +	return "Syntax: who are you ignoring?" unless @arguments == 0; + +	# FIXME special case for empty ignore +	return "I am ignoring: " . join ", ", @{$config{ignore}};  } @@ -85,13 +85,22 @@ sub register_command {  sub run_command {  	my ($command_string, $who, $where) = @_;  	my @arguments; -	my ($command, $rest) = split /\s+/, $command_string, 2; -	@arguments = split /\s+/, $rest if $rest; -	if ($commands{$command}) { -		return ($commands{$command})->($irc, \&log_info, $who, $where, $rest, @arguments); -	} else { -		return "No such command \"$command\""; +	my $command_verbatim; +	my $command; + +	for my $c (keys %commands) { +		if (($command_verbatim) = $command_string =~ m/^(\Q$c\E( |$))/) { +			$command = $c; +			last; +		}  	} + +	return "No such command" unless $command; + +	my $rest = (split "\Q$command_verbatim", $command_string, 2)[1]; +	@arguments = split /\s+/, $rest if $rest; + +	return ($commands{$command})->($irc, \&log_info, $who, $where, $rest, @arguments);  }  sub custom_ping { @@ -210,122 +219,11 @@ sub irc_msg {  		return;  	}  	return unless $is_admin; -	# FIXME this needs tidying. Some of this can be factored out, surely. -	if ($what =~ /^nick\s/) { -		my ($newnick) = $what =~ /^nick\s+(\S+)$/; -		if ($newnick) { -			$irc->yield(nick => $newnick); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: nick <nick>"); -		} -	} -	if ($what =~ /^ignore\s/) { -		my ($target) = $what =~ /^ignore\s+(\S+)$/; -		if ($target) { -			push @{$config{ignore}}, $target; -			$irc->yield(privmsg => $nick => "Ignoring $target."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: ignore <nick>"); -		} -	} -	if ($what =~ /^don't ignore\s/) { -		my ($target) = $what =~ /^don't ignore\s+(\S+)$/; -		if ($target) { -			if (grep { $_ eq $target} @{$config{ignore}}) { -				@{$config{ignore}} = grep { $_ ne $target } @{$config{ignore}}; -				$irc->yield(privmsg => $nick => "No longer ignoring $target."); -			} else { -				$irc->yield(privmsg => $nick => "I wasn't ignoring $target anyway."); -			} -		} else { -			$irc->yield(privmsg => $nick => "Syntax: don't ignore <nick>"); -		} -	} -	if ($what =~ /^part\s/) { -		my $message; -		if ($what =~ /^part(\s+(\S+))+$/m) { -			$what =~ s/^part\s+//; -			my ($chan_str, $reason) = split /\s+(?!#)/, $what, 2; -			my @channels = split /\s+/, $chan_str; -			$reason = "Commanded by $nick" unless $reason; -			$irc->yield(part => @channels => $reason); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => -			            "Syntax: part <channel1> [channel2 ...] [partmsg]"); -		} -	} -	if ($what =~ /^join\s/) { -		if ($what =~ /^join(\s+(\S+))+$/) { -			$what =~ s/^join\s+//; -			my @channels = split /\s+/, $what; -			$irc->yield(join => $_) for @channels; -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => -			            "Syntax: join <channel1> [channel2 ...]"); -		} -	} -	if ($what =~ /^say\s/) { -		my ($channel, $message) = $what =~ /^say\s+(\S+)\s(.*)$/; -		if ($channel and $message) { -			$irc->yield(privmsg => $channel => $message); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: say <channel> <msg>"); -		} -	} -	if ($what =~ /^action\s/) { -		my ($channel, $action) = $what =~ /^action\s+(\S+)\s(.*)$/; -		if ($channel and $action) { -			$irc->yield(ctcp => $channel => "ACTION $action"); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: action <channel> <action text>"); -		} -	} -	if ($what =~ /^topic\s/) { -		my ($channel, $topic) = $what =~ /^topic\s+(\S+)\s(.*)?$/; -		if ($channel) { -			$topic = "" unless $topic; -			$irc->yield(topic => $channel => $topic); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: topic <channel> <topic>"); -		} -	} -	if ($what =~ /^who are you ignoring/) { -		my $ignores = join ", ", @{$config{ignore}}; -		$irc->yield(privmsg => $nick => "I am ignoring: $ignores"); -	} -	if ($what =~ /^mode\s/) { -		my ($rest) = $what =~ /^mode\s+(.*)?$/; -		if ($rest) { -			$irc->yield(mode => $rest); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: mode [everything]"); -		} -	} -	if ($what =~ /^kick\s/) { -		my ($channel, $kickee, undef, $reason) = $what =~ /^kick\s+(\S+)\s(\S+)((?:\s)(.*))?$/; -		if ($channel and $kickee) { -			$reason = "Requested by $nick" unless $reason; -			$irc->yield(kick => $channel => $kickee => $reason); -			$irc->yield(privmsg => $nick => "Requested."); -		} else { -			$irc->yield(privmsg => $nick => "Syntax: kick <channel> <nick> [reason]"); -		} -	} -	if ($what =~ /^reconnect/) { -		my ($reason) = $what =~ /^reconnect\s+(.+)$/; -		$irc->yield(privmsg => $nick => "Doing that now"); -		if (!$reason) { -			$reason = $config{quit_msg}; -		} -		$irc->yield(quit => $reason); -	} + +	my $stripped_what = strip_color(strip_formatting($what)); +	my $output = run_command($stripped_what, $who, $nick); +	$irc->yield(privmsg => $nick => $output) if $output; +  	return;  } | 
