summaryrefslogtreecommitdiffstats
path: root/modules/event.pl
diff options
context:
space:
mode:
authorLibravataricxcnika <icxcnika@antispammeta.net>2014-04-22 23:46:10 +0400
committerLibravataricxcnika <icxcnika@antispammeta.net>2014-04-22 23:46:10 +0400
commitac56812a5a79b5187a89cb7dcd9078c11ffed54e (patch)
tree8b0cd4718ec93d76127793c2ee2dc2914253b9c0 /modules/event.pl
parent02ce9f49538d6a89c6562708a0ac2871b2d46dc3 (diff)
added some things in gitignore,
added connection tx/rx info to status reports, added exit, sync, and ping commands, bot says which channel a restricted person tries to use ops command on, blacklist system is more intelligent (reason, person adding, can be removed), added functionality for working with URLs, automatically retries to join channels that are throttled, make sure we send passwords to NickServ@services., fixed a scheduling loophole that was exploitable, greatly reduced startup warnings due to slow syncing
Diffstat (limited to 'modules/event.pl')
-rw-r--r--modules/event.pl57
1 files changed, 55 insertions, 2 deletions
diff --git a/modules/event.pl b/modules/event.pl
index 3c41df4..d3e3fa5 100644
--- a/modules/event.pl
+++ b/modules/event.pl
@@ -7,6 +7,7 @@ use Text::LevenshteinXS qw(distance);
use IO::All;
use POSIX qw(strftime);
use Regexp::Wildcards;
+use HTTP::Request;
sub cs {
my ($chan) = @_;
@@ -71,6 +72,8 @@ sub new
$conn->add_handler('statsdebug', \&on_statsdebug);
$conn->add_handler('endofstats', \&on_endofstats);
$conn->add_handler('channelurlis', \&on_channelurlis);
+ $conn->add_handler('480', \&on_jointhrottled);
+ $conn->add_handler('invite', \&blah); # This doesn't need to be fancy; I just need it to go through inspect
bless($self);
return $self;
}
@@ -79,6 +82,16 @@ my $clearstatsp = 1;
my %statsp = ();
my %oldstatsp = ();
+sub on_jointhrottled
+{
+ my ($conn, $event) = @_;
+ my $chan = $event->{args}->[1];
+ ASM::Util->dprint("$event->{nick}: $chan: $event->{args}->[2]", 'snotice');
+ if ($event->{args}->[2] =~ /throttle exceeded, try again later/) {
+ $conn->schedule(5, sub { $conn->join($chan); });
+ }
+}
+
sub on_statsdebug
{
my ($conn, $event) = @_;
@@ -222,7 +235,7 @@ sub on_connect {
$conn->sl("MODE $event->{args}->[0] +Q-i");
if (lc $event->{args}->[0] ne lc $::settings->{nick}) {
ASM::Util->dprint('Attempting to regain my main nick', 'startup');
- $conn->privmsg( 'NickServ', "regain $::settings->{nick} $::settings->{pass}" );
+ $conn->privmsg( 'NickServ@services.', "regain $::settings->{nick} $::settings->{pass}" );
}
$conn->sl('CAP REQ :extended-join multi-prefix account-notify'); #god help you if you try to use this bot off freenode
}
@@ -325,10 +338,38 @@ sub on_public
$::sc{lc $event->{to}->[0]}{users}{lc $event->{nick}}{msgtime} = time;
$::log->logg( $event );
$::db->logg( $event );
+# if ($event->{args}->[0] =~ /(https?:\/\/bitly.com\/\w+)|(https?:\/\/bit.ly\/\w+)|(https?:\/\/j.mp\/\w+)/i) {
+# my $reqid = $::async->add( HTTP::Request->new( GET => $1 ) );
+# $::httpRequests{$reqid} = $event;
+# my ($response, $id) = $::async->wait_for_next_response( 1 );
+# if (defined($response)) {
+# on_httpResponse($conn, $id, $response);
+# }
+# else { $conn->schedule( 1, sub { checkHTTP($conn); } ); }
+# }
$::inspector->inspect( $conn, $event );
$::commander->command( $conn, $event );
}
+sub checkHTTP
+{
+ my ($conn) = @_;
+ my ($response, $id) = $::async->next_response();
+ if (defined ($response)) {
+ on_httpResponse($conn, $id, $response);
+ }
+ $conn->schedule( 1, sub { checkHTTP($conn); } );
+}
+
+sub on_httpResponse
+{
+ my ($conn, $id, $response) = @_;
+ my $event = $::httpRequests{$id};
+ delete $::httpRequests{$id};
+ $::inspector->inspect( $conn, $event, $response );
+}
+# if ($response->{_previous}->{_headers}->{location} =~ /^https?:\/\/bitly.com\/a\/warning/)
+
sub on_notice
{
my ($conn, $event) = @_;
@@ -778,11 +819,23 @@ sub on_whoxover
my $size = `ps -p $$ h -o size`;
my $cputime = `ps -p $$ h -o time`;
chomp $size; chomp $cputime;
+ my ($tx, $rx);
+ if ($conn->{_tx}/1024 > 1024) {
+ $tx = sprintf("%.2fMB", $conn->{_tx}/(1024*1024));
+ } else {
+ $tx = sprintf("%.2fKB", $conn->{_tx}/1024);
+ }
+ if ($conn->{_rx}/1024 > 1024) {
+ $rx = sprintf("%.2fMB", $conn->{_rx}/(1024*1024));
+ } else {
+ $rx = sprintf("%.2fKB", $conn->{_rx}/1024);
+ }
$conn->privmsg($::settings->{masterchan}, "Finished syncing after " . (time - $::starttime) . " seconds. " .
"I'm tracking " . (scalar (keys %::sn)) . " nicks" .
" across " . (scalar (keys %::sc)) . " tracked channels." .
" I'm using " . $size . "KB of RAM" .
- " and have used " . $cputime . " of CPU time.");
+ ", have used " . $cputime . " of CPU time" .
+ ", have sent $tx of data, and received $rx of data.");
my %x = ();
foreach my $c (@{$::settings->{autojoins}}) { $x{$c} = 1; }
foreach my $cx (keys %::sc) { delete $x{$cx}; }