view findplayer.pl @ 11:22a51e8c0a69

Update copyright date. Remove CVS ID.
author darius@inchoate.localdomain
date Fri, 29 Feb 2008 21:05:14 +1030
parents 3ef64337d86b
children
line wrap: on
line source

############################################################################
# Run the game-monitor script when triggered
#
# $Id$
############################################################################
#
# Copyright (C) 2007 Daniel O'Connor. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
############################################################################

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;

$VERSION = '1.00';
%IRSSI = (
    authors     => 'Darius',
    contact     => 'darius\@dons.net.au',
    name        => 'findplayer',
    description => 'Looks for players on game-monitor',
    license     => 'BSD',
);

my $lastran = 0;

sub event_privmsg {
  # $data = "nick/#channel :text"
  my ($server, $data, $nick, $address) = @_;
  my ($target, $text) = split(/ :/, $data, 2);

  #print CLIENTCRAP "target = \"$target\"";
  if (lc($target) ne "#teabf" && lc($target) ne "#tea" && lc($target) ne "darius") {
    return;
  }
  #print CLIENTCRAP "target = \"$target\"";

  # Remove colours, bold etc (taken from cleanpublic.pl)
  $text =~ s/\x03\d?\d?(,\d?\d?)?|\x02|\x1f|\x16|\x06|\x07//g;
  #print CLIENTCRAP "text is $text";

  if ($text =~ /^!fp *(.*)/) {
    if ($lastran + Irssi::settings_get_int('fp_mininter') > time()) {
      print CLIENTCRAP "ignoring command from $nick";
      return;
    }
    $lastran = time();

    my $string = $1;
    $string =~ s/[^0-9a-zA-Z .,\[\]]//g;
    #print CLIENTCRAP "Target found - $string";
    if ($string eq "") {
	$string = "[TEA]";
    	#print CLIENTCRAP "No target, using [TEA]";
    }
    $server->command("msg $target Looking for \"$string\" on game-monitor.com...");
    open (SCR, "-|", "/home/doconnor/bin/scrape-gm.py", $string);
    my $i = 0;
    while (<SCR>) {
      chomp;
      $server->command("msg $target $_");
      $i++;
      if ($i > Irssi::settings_get_int('fp_maxlen')) {
	$server->command("msg $target Too many results, truncating");
    }
    close SCR;
  }
}

Irssi::signal_add("event privmsg", "event_privmsg");
Irssi::settings_add_int('misc', 'fp_mininter', 10);
Irssi::settings_add_int('misc', 'fp_maxlen', 10);

print CLIENTCRAP "findplayer loaded";
1;

#;;; Local Variables: ***
#;;; mode:perl ***
#;;; End: ***