# version:0.5 loader:pf # $Id: relay.dsm,v 1.19 2007/03/24 07:09:08 brian Exp $ # # relay.dsm - Channel relay module for DarkStar/EPIC5 # Copyright (c) 2002, 2003 Brian Weiss # See the 'COPYRIGHT' file for more information. # # This script uses serial number 451 for all /ON hooks. # queue cleanup.relay { for alias in (relc relm reln relp relpo relsc relsm relsn relsp relspo) { ^alias -$alias; }; for hook in (ctcp ctcp_reply msg notice public public_other send_msg send_notice send_public) { ^on #$hook 451 -"*"; }; ^on #hook 451 -"CONFIG RELAY_BUFFER_SIZE *"; ^on #hook 451 -"UNLOADMOD formats"; ^on #send_ctcp 451 -"PRIVMSG *"; }; if (!isloaded(formats)) { ^local ask $'The relay module depends on the formats module - Load it now? '; if (ask == [y]) loadmod formats; }; addconfig RELAY_BUFFER_SIZE 10; addconfig -b RELAY_STRIP_CRAP 1; alias relay (type, ...) { if (!type) { xecho -b Usage: /RELAY [-clear|-list| []]; xecho -b Available types: ctcp ctcp_reply msg notice public public_other send_ctcp send_msg send_notice send_public send_public_other; return; }; switch ($tolower($type)) { (c) (ctcp) {relay.main CTCP $*} (cr) (ctcp_reply) {relay.main CTCP_REPLY $*} (m) (msg) {relay.main MSG $*} (n) (notice) {relay.main NOTICE $*} (p) (public) {relay.main PUBLIC $*} (po) (public_other) {relay.main PUBLIC_OTHER $*} (sc) (send_ctcp) {relay.main SEND_CTCP $*} (sm) (send_msg) {relay.main SEND_MSG $*} (sn) (send_notice) {relay.main SEND_NOTICE $*} (sp) (send_public) {relay.main SEND_PUBLIC $*} (spo) (send_public_other) {relay.main SEND_PUBLIC_OTHER $*} }; }; alias relc (...) {relay c $*}; alias relcr (...) {relay cr $*}; alias relm (...) {relay m $*}; alias reln (...) {relay n $*}; alias relp (...) {relay p $*}; alias relpo (...) {relay po $*}; alias relsc (...) {relay sc $*}; alias relsm (...) {relay sm $*}; alias relsn (...) {relay sn $*}; alias relsp (...) {relay sp $*}; alias relspo (...) {relay spo $*}; alias relay.additem (type, text) { if (!type || !text) { echo Error: relay.additem: Not enough arguments; return; }; if (numitems(relay.$type) >= CONFIG.RELAY_BUFFER_SIZE) { @ delitem(relay.$type 0); }; @ setitem(relay.$type $numitems(relay.$type) $text); }; alias relay.main (type, ...) { if (!type) { echo Error: relay.main: Not enough arguments; return; }; if (!FORMAT[$type]) { echo Error: relay.main: Format variable $toupper($type) has no value; return; }; @ :array = [relay.] ## tolower($type); if (!numitems($array)) { echo Error: relay.main: No items found for type [$type]; return; }; switch ($tolower($0)) { (-c%) { @ delarray($array); return; } (-l%) { relay.showitems $array $type; return; } (*) { if ([$0] == []) { @ :inum = numitems($array) - 1; } else if ([$0] < 0 || [$0] >= numitems($array)) { echo Error: relay.main: Item number out of range; return; } else { @ :inum = [$0]; }; } }; if (![$1]) { @ :target = T; } else { @ :target = [$1]; }; if (CONFIG.RELAY_STRIP_CRAP) { msg $target $stripcrap(ALL $fparse($type $getitem($array $inum))); } else { msg $target $fparse($type $getitem($array $inum)); }; }; # # Displays the contents of after being passed # through $fparse( ...) # alias relay.showitems (array, format, void) { if (!array || !format) { echo Error: relay.showitems: Not enough arguments; return; }; echo Item# Value; for cnt from 0 to ${numitems($array) - 1} { echo $[4]cnt $fparse($format $getitem($array $cnt)); }; }; on #-ctcp 451 "*" {relay.additem ctcp $*}; on #-ctcp_reply 451 "*" {relay.additem ctcp_reply $*}; on #-msg 451 "*" {relay.additem msg $0 $userhost() $1-}; on #-notice 451 "*" {relay.additem notice $0 $userhost() $1-}; on #-public 451 "*" {relay.additem public $*}; on #-public_other 451 "*" {relay.additem public_other $*}; on #-send_ctcp 451 "PRIVMSG *" { unless ([$2] != [ACTION]) { relay.additem send_ctcp $*; }; }; on #-send_msg 451 "*" {relay.additem send_msg $*}; on #-send_notice 451 "*" {relay.additem send_notice $*}; on #-send_public 451 "*" { if ([$0] == C) { relay.additem send_public $0 $servernick() $1-; } else { relay.additem send_public_other $0 $servernick() $1-; }; }; on #-hook 451 "CONFIG RELAY_BUFFER_SIZE *" { @ :newval = CONFIG.RELAY_BUFFER_SIZE; @ :oldval = [$2-]; if (newval != [] && (!isnumber(b10 $newval) || newval < 0)) { xecho -b Value must be an integer greater than or equal to 0; if (oldval == []) { defer dset -RELAY_BUFFER_SIZE; } else { defer dset RELAY_BUFFER_SIZE $oldval; }; }; }; on #-hook 451 "UNLOADMOD formats" { xecho -b WARNING: The relay module depends on the formats module - Unloading it may prevent relay from functioning properly; };