#!/usr/bin/perl # # For use with a eggdrop TCL # Usage: %mame game # Returns: shortname: Description $gamelist = "/home/lazy/bot/scripts/mame056.txt"; # Generated by: mamew.exe -listfull #$gamelist = "mame053.txt"; $prefix = "MAME Game Search"; if (@ARGV == 0 || $ARGV =~ /\W/) { # Checks for the number of arguments, and the contents print "$prefix Usage: \002%mame gamename\002\n"; exit; } $search = join(" ", @ARGV); open(GAMELIST, $gamelist) or print "$prefix: Unable to find game list\n" and exit; while () { @game = split(/\s+/, $_); $shortname = $game[0]; # Short game name is the first word if ($shortname =~ /^$search$/i) { $longname = join(" ", @game); # Put the long game name into a variable $longname =~ s/"(.*)"//; print "$prefix: $search -> $1\n"; close(GAMELIST); exit; } } # Not able to find an exact match, try searching the long name for the string seek GAMELIST, 0, 0; # Return to the beginning of the file $games = ""; $count = 1; # Count of games $chars = 0; # Number of characters (450 letter limit on IRC) $chars += length($prefix) + length($search) + 10; # 10 being the number of extra characters # " -> ", " [...]" while () { if ($_ =~ /$search/i) { @game = split(/\s+/, $_); $shortname = shift(@game); # Remove the first word, it's the short name $longname = join(" ", @game); # Put the long game name into a variable $longname =~ s/"(.*)"//; $chars += length($1) + length($shortname) + 4; # See how many characters this would be if ($chars > 448) { $games .= " [...]"; # More than the limit for IRC last; } if ($games) { $games .= ", "; } $games .= "$1 [$shortname]"; # Add to the list } } if ($games) { print "$prefix: $search -> $games\n"; close (GAMELIST); exit; } close (GAMELIST); print "$prefix: Unable to find $search\n";