Multi-server, multi-channels news bot.
works with !news, !channews, and !clannews
commands are:
!news
!news add
!news delete [all]
!news return <1-10>
(can replace ! with . and @, also triggers on !channews and !clannews)
;news script
;~~~~~~~~~~~~~~~~~~
;~~~~~Change ## to ~~~~
;~~max kept lines of news ~
;~~~~~~~~~~~~~~~~~~
alias -l maxnews { return 10 }
on *:LOAD:{
set %newsreturn 3
}
on *:START:{
if (!$isdir(news)) { mkdir news }
}
on $*:TEXT:/^[!@.](c[lh]an)?news\b/Si:#: {
var %send = $iif($left($$1,1) == @,.msg $chan,.notice $nick)
if ($2 == $null) {
if (!$isfile($+(news\,$network,.,$chan,.news.txt))) || ($lines($+(news\,$network,.,$chan,.news.txt)) == 0) { %send There is no news for this channel! | return }
var %total $lines($+(news\,$network,.,$chan,.news.txt))
var %temp $calc(%total - %newsreturn)
while (%temp <= %total) {
var %output $addtok(%output,$gettok($read($+(news\,$network,.,$chan,.news.txt),%temp),3,61),124)
inc %temp
}
%send 7Latest news for $chan $+ : $replace(%output,$chr(124),$+($chr(15),$chr(32),$chr(124),$chr(32)))
}
elseif ($2 == add) {
if ($nick isop $chan) || ($nick ishop $chan) {
if ($3) {
write $+(news\,$network,.,$chan,.news.txt) $+(<,$asctime(dd/mm/yyyy HH:nn:ss),>) $+ = $+ $nick $+ = $+ $$3-
$iif($nick !isop $chan,set -u30 %new. $+ $chan $+ . $+ $network yes)
%send 7Success! You have added this to the channel news: $$3-
cleanup $lines($+(news\,$network,.,$chan,.news.txt)) $+(news\,$network,.,$chan,.news.txt)
}
else { You must specify something to add! }
}
else { notice $nick You must be an Op or Half-Op to use that command! }
}
elseif ($2 == return) {
if ($nick isop $chan) || ($nick ishop $chan) {
if ($3 isnum 1-10) {
set %newsreturn $calc($$3 - 1)
%send I will now return7 $$3 news $iif($$3 == 1,item,items) $+ !
}
else { %send You must specify a number between 1 and 10! }
}
else { %send You must be an On or Half-Op to use that command! }
}
elseif ($2 == delete) {
if ($nick isop $chan) {
if ($3 != all) {
write -d $+(news\,$network,.,$chan,.news.txt)
notice $nick the last news post has been deleted
}
else {
.remove $+(news\,$network,.,$chan,.news.txt)
notice $nick The news for $chan has been cleared!
}
}
elseif ($nick ishop $chan) {
if ($eval($+(%, new., $chan, ., $network), 2) != $null) {
write -d $+(news\,$network,.,$chan,.news.txt)
unset %new. $+ $chan $+ . $+ $network
notice $nick the last news post has been deleted
}
else { notice $nick there has been no news post in the last thirty seconds. }
}
}
elseif ($2 == help) {
var %send notice $nick
%send News bot by Savage_CL
%send Commands are:
%send !news or !channews or !clannews to return the news (all users)
%send !news add <new news> (ops and halfops only)
%send !news return <1-10> for amount of news returned (ops and halfops only)
%send !news delete Deletes the latest news post (ops and halfops only)
%send you may only use !news delete for thirty seconds after the last post so you may correct errors (ops and halfops only)
%send !news delete all will delete all news for the channel (ops only)
}
}
alias -l network { return $iif($network,$v1,$gettok(%temp,$calc($numtok(%temp,46) - 1),46)) }
alias -l cleanup {
if ($$1 > $maxnews) {
write -dl1 $$2
}
}
what Jethro_ meant by saying "Why do you use many checks for op and halfop?"
is you have
if ($nick isop $chan) || ($nick ishop $chan) {
everywhere when you could have done one or maybe two seeing how you have the code
and instead of doing the check like this
if ($nick isop $chan) || ($nick ishop $chan) {
you could do it like this
if ($nick(#,$nick,oh)) {
but whatever to each their own......