if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; }; # Copyright (c) 2004 BlackJac@EFNet # # Version: 1.1.2004.09.24.1 # # This script will allow you to store information about any subject and # return that information to anyone requesting it privately via message # or publically in a channel. # # For someone to request information from your database, they must either # privately message you or say publically in a channel the following # (in this example, using the default command trigger): # !infodb # If an exact match is found, the information will be returned the same # way the request was received (publically or privately). If a pattern # match is found, all matches will be returned the same way the request # was received. # # For someone to add information to your database, they must privately # message you the following (in this example, using the default command # trigger): # !infodbmod # Each item will be stamped with the nick!user@host of the person adding # it and the time it was added. For someone to delete an entry from your # database, they must privately message you the following (in this # example, using the default command trigger): # !infodbmod package infodb; # Watch these channels for information requests (leave a space between each # channel): assign INFODB_CHANS #samplechannel1 #samplechannel2; # Trigger command required to add/change/delete database information entries # via private message: assign INFODB_MOD !infodbmod; # Trigger command required to request information from the database: assign INFODB_REQ !infodb; # Directory where information database is located (leave off the trailing slash): assign INFODB_SAVEDIR ~; # Name of information database file: assign INFODB_SAVEFILE infodb.txt; alias infodb.return (type, target, pattern, void) { if (type && target && @pattern) { @ :matches = getmatches(array.infodb $pattern *); if ((:cnt = numwords($matches)) == 1) { @ :info = getitem(array.infodb $matchitem(array.infodb $pattern *)); defer $type $^\target Match found for $word(0 $info): $restw(3 $info) \(submitted by $word(1 $info) [$stime($word(2 $info))]\); } else if (cnt) { fe ($matches) ii { push :items $word(0 $getitem(array.infodb $ii)); }; defer $type $^\target Possible matches found for $^\pattern\: $numsort($items); } else { defer $type $^\target No match found for $^\pattern; }; }; }; alias infodb.save (void) { if (fexist($INFODB_SAVEDIR) != 1) { @ mkdir($INFODB_SAVEDIR); } else { @ unlink($INFODB_SAVEDIR/$INFODB_SAVEFILE); }; if ((:fd = open($INFODB_SAVEDIR/$INFODB_SAVEFILE W)) > -1) { @ write($fd if \(word\(2 \$loadinfo\(\)\) != [pf]\) \{); @ write($fd load -pf \$word\(1 \$loadinfo\(\)\)\;); @ write($fd return\;); @ write($fd \}\;); @ write($fd); @ write($fd # Do not modify this file); @ write($fd); fe ($jot(0 ${numitems(array.infodb) - 1} 1)) ii { @ write($fd @ setitem\(array.infodb $ii $getitem(array.infodb $ii)\)\;); }; @ close($fd); }; }; ^on #-msg 4 '% $$INFODB_MOD *' { @ :pattern = strip(\$ $2); if ((:item = matchitem(array.infodb $pattern *)) > -1) { @ delitem(array.infodb $item); if ([$3]) { @ setitem(array.infodb $numitems(array.infodb) $pattern $0!$userhost() $time() $strip(\$ $3-)); infodb.save; defer notice $^\0 Updated entry for $^\pattern to the database; } else { if (getarrays(array.infodb)) { infodb.save; } else { @ unlink($INFODB_SAVEDIR/$INFODB_SAVEFILE); }; defer notice $^\0 Deleted entry for $^\pattern from the database; }; } else if ([$3]) { @ setitem(array.infodb $numitems(array.infodb) $pattern $0!$userhost() $time() $strip(\$ $3-)); infodb.save; defer notice $^\0 Added entry for $^\pattern to the database; } else { defer notice $^\0 Unable to find an entry for $^\pattern in the database; }; }; ^on #-msg 4 '% $$INFODB_REQ *' { infodb.return notice $0 $strip(\$ $2); }; fe (public public_other) ii { ^on #-$ii 4 '% \\\\[$$INFODB_CHANS\\\\] $$INFODB_REQ *' { infodb.return msg $1 $strip(\$ $3); }; }; if (fexist($INFODB_SAVEDIR/$INFODB_SAVEFILE) == 1) { load -pf $INFODB_SAVEDIR/$INFODB_SAVEFILE; };