This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Script for banning on join if the nick isn't in a list

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Script for banning on join if the nick isn't in a list

Post by Happolo2 »

Hi.
First of all, hi to everybody. I'm new here and i'm a real newbie in Tcl scripting too. (and sorry for my english too but it's not my first language).

I wanted to try to learn and to make a script by myself but i need a script that it's a bit too difficult for being my first script :) and so i prefer to ask some help.

I need a script for my eggdrop. The script should make a check when a nick joins in a specific channel. If the nick is on a list in a file on the shell the bot has to do nothing. If the nick isn't in the list the bot has to ban the nick (only the nick - so +b nick!*@*), and then delete the ban after 5 minutes. With the ban it has to send also a message to the banned nick.

The file with nicknames must be editable by some nicks with !add nick or !del nick commands.

Last... could be possible with a command like !take list ... (available only for some nicks) ... that the bot will send (through a dcc send) the file with the nick list?

... i was forgotten... could be possible to have a switch for running or not this script? I mean a !start and a !stop command.


I'm a newbie so it's all difficult for me.. but i've especially some doubts:

1) the file with the nick list ... on the shell... could be written/and read by the bot?
2) with the mirc script i use... this file is a .ini file. Must be the same for the bot? Have i to use a .txt file?
3) How can i say to the bot to take commands only from some nicks? Have i to make another file with a list? Is it enough to use flags?
4) Is it possible the use of dcc send for let the bot sending the file's list?
5) I think especially for nicks with { or [ should be more difficult for avoiding conflicts with the script.
6) Do i need any particular configuration of the bot for running a script such this one?


I try to past the script i'm using with mirc if can help to explain better what i need.
(the script hasn't the xdcc send option ... that i'd like to add for the bot).

;Name of the #channel and reason of the ban
alias protect.chan return #channel
alias motivo.ban return Guardian Banned You (Reason of the Ban)

;Nicks than can use !add or !del commands
;%except is for nicks won't be checked by the bot

on *:text:*:#:{
if ($chan == $protect.chan) {
if ($nick == first nick) || ($nick == second nick) || ($nick == ...all nicks can use !add or !del) {
if ($1 == !add) { add $2 }
if ($1 == !del) { del $2 }
}
}
}

on *:join:#:{
var %except = specialnicks*
if ($chan == $protect.chan) {
if ($youarein($nick) || (%except iswm $nick)) { .notice $nick 4Welcome 7 $nick 8In 9#channel 4:) }
else { .timer -o 1 $calc( 10 * 60) .mode # -b $nick | .mode # +b $nick | .kick # $nick 8Reason of the Ban }
}
}

on *:INPUT:#: {
if (!add == $1) { add $2 }
if (!del == $1) { del $2 }
}

alias youarein {
var %total = %nicks
var %x = 1
if (%total != 0) {
while (%x <= %total) {
if ($readini(nick.ini, list, %x) == $1) { return $true }
inc %x
}
}
return $false
}

alias add {
if (!$youarein($1)) {
inc %nicks
.writeini nick.ini list %nicks $1
.msg $protect.chan 9Added0,1 $1 4to the list!
echo -a 9Added0,1 $1 4to the list!

}
else { msg $protect.chan 9 $1 0,1It's already 4in the list! }
}

alias del {
if ($youarein($1)) {
var %x = 1
while (%x <= $calc(%nicks - 1)) {
if ($readini(nick.ini,list,%x) == $1) && (%a != $true) { .writeini nick.ini list %x $readini(nick.ini,list,$calc(%x + 1)) | var %a = $true }
if (%a == $true) { .writeini nick.ini list %x $readini(nick.ini,list,$calc(%x + 1)) }
inc %x
}
.remini nick.ini list %nicks
dec %nicks
.msg $protect.chan 9 $1 0,1deleted from 4the list!
echo -a 9Deleted0,1 $1 4from the list!

}
else { msg $protect.chan 9Il Nick0,1 $2 4Isn't in the list! }
}

alias debug.nick {
set %debug.nick on
var %x = 1
while (%debug.nick == on) {
if ($readini(nick.ini,list,%x)) { inc %x }
else { set %nicks $calc(%x - 1) | set %debug.nick off }
}
}

on 1:START:{ debug.nick }
on *:LOAD:{ set %nicks 0 }

Thank you to everybody.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Re: Script for banning on join if the nick isn't in a list

Post by demond »

Happolo2 wrote: 1) the file with the nick list ... on the shell... could be written/and read by the bot?
2) with the mirc script i use... this file is a .ini file. Must be the same for the bot? Have i to use a .txt file?
3) How can i say to the bot to take commands only from some nicks? Have i to make another file with a list? Is it enough to use flags?
4) Is it possible the use of dcc send for let the bot sending the file's list?
5) I think especially for nicks with { or [ should be more difficult for avoiding conflicts with the script.
6) Do i need any particular configuration of the bot for running a script such this one?
1) yes
2) no
3) bind to flags
4) yes
5) not at all
6) no

Code: Select all

# initialize empty nick list
set nlist {}
# try to read in the list from file
if ![catch {set f [open file.txt]}] {
   set nlist [split [read $f] \n]; close $f
}
# save the list into file every minute
bind time - * save
proc save args {
   set f [open file.txt w]
   foreach n $::nlist {puts $f $n}
   close $f
}
bind join - {#yourchan %} foo
proc foo {n u h c} {
# don't check +o botusers
   if [matchattr $h o|o $c] return
# check if the joining nick is on the list
# -nocase will only work on Tcl 8.5 and higher
# for case-insensitive search on older Tcl versions,
# apply [string tolower] on [lsearch] arguments
   if {[lsearch -noc $::nlist $n] != -1} {
      newchanban $c $n!*@* $::nick badnick 5
      putkick $c $n badnick
   }
}
# allow commands from botmasters only
bind pub m !add bar
bind pub m !del bar
proc bar {n u h c t} {
   if {$::lastbind == "add"} {
      lappend ::nlist $t
   } else {
# Tcl has no 'delete from list by element name' command,
# so we need to get element's index first and then use it with [lreplace]
      if {[set i [lsearch -noc $::nlist $t]] != -1}
         set ::nlist [lreplace $::nlist $i $i]
      }
   }
}
bind pub m !take moo
proc moo {n args} {
   if {[dccsend file.txt $n] != 0} {
      puthelp "notice $n :cannot send"
   }
}
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Code: Select all

if {$::lastbind == "add"} { 
should be

Code: Select all

if {$::lastbind == "!add"} { 
if the bind is !add (if i'm not mistaken :p)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You might also want to avoid duplicates, instead of

Code: Select all

if {$::lastbind == "add"} {
   lappend ::nlist $t
} else {
use

Code: Select all

if {$::lastbind == "!add"} {
   if {[lsearch -noc $::nlist $t] == -1} {
      lappend ::nlist $t
   }
} else {
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Post by Happolo2 »

Really thanks to everybody.
Now i'm sure that i couldn't do it by myself :P

I try to ask you some things for trying to understand and learn.

1)
# initialize empty nick list
set nlist {}
Now with mirc i use an .ini file of this kind:

[ list ]
1=nick1
2=nick2
...
600=nick600

----

Now if i convert this file from .ini to .txt and i upload it on the shell, can i let the bot using this file? Or have i to create an empty new one and add each nick through the bot and the !add command?



2) instead of
# save the list into file every minute
bind time - * save
proc save args {
set f [open file.txt w]
foreach n $::nlist {puts $f $n}
close $f
}
is it possible to save the file only when it is changed using !add or !del commands and not every minute?


3) i haven't understood the "delete" part of the script.
I mean if i type
!add bar nick1
it should add the nick1 to the list

if i type
!del bar nick1 does it works or have i to type !del bar "index" ? or another command?


Sorry if my questions are stupid but i prefer to try to understand what i'm doing and not only to copy a script.

Thanks again for your big help.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Happolo2 wrote:Really thanks to everybody.
Now i'm sure that i couldn't do it by myself :P

I try to ask you some things for trying to understand and learn.

1)
# initialize empty nick list
set nlist {}
Now with mirc i use an .ini file of this kind:

[ list ]
1=nick1
2=nick2
...
600=nick600

----

Now if i convert this file from .ini to .txt and i upload it on the shell, can i let the bot using this file? Or have i to create an empty new one and add each nick through the bot and the !add command?



2) instead of
# save the list into file every minute
bind time - * save
proc save args {
set f [open file.txt w]
foreach n $::nlist {puts $f $n}
close $f
}
is it possible to save the file only when it is changed using !add or !del commands and not every minute?


3) i haven't understood the "delete" part of the script.
I mean if i type
!add bar nick1
it should add the nick1 to the list

if i type
!del bar nick1 does it works or have i to type !del bar "index" ? or another command?


Sorry if my questions are stupid but i prefer to try to understand what i'm doing and not only to copy a script.

Thanks again for your big help.
1) you can, but you'll have to remove the 1=,2=...etc from each line or alter the script to skip it (but removing them is better).

2) You can but what are you so worried about, the list is being saved.

3) !del nick is enough for deleting.
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Post by Happolo2 »

Sir_Fz wrote:
1) you can, but you'll have to remove the 1=,2=...etc from each line or alter the script to skip it (but removing them is better).
I try to explain why i was asking for using .ini file or .txt file but not modified.
Now with Mirc we have 3 mirc clients running this script on three different computers. So sometimes we have to check to have on each mirc the same list of nicks or a nick can be banned because it is only on 2 lists because the third client was out of the channel when the list has been modified.
Now i wanted to make this script running on the shell by the eggdrop and not on the computer... and with your precious help i think i can do it.
Just i thought to the Dcc send command ... so everyone (botmasters) can download the nick list from the shell and put it in his script on the mirc client on his computer.
The problem is that if i can't use the .ini file or if i've to modified the .txt file ... it becomes difficult to have a fast "upgrade" of all lists. (cause the list has more or less 600 nicks).
This is the reason for which i was asking if it was possible to use .ini file or .txt files "just changing .ini to .txt extension".
2) You can but what are you so worried about, the list is being saved.
I was just curious ... it's more than ok also with a save each minute :)
3) !del nick is enough for deleting.
[/quote]

Thanks :)

---

I add another question if i can.
# check if the joining nick is on the list
# -nocase will only work on Tcl 8.5 and higher
# for case-insensitive search on older Tcl versions,
Is there a way for knowing which Tcl Version is on the server where i have my shell account? If there is a different version if i'm not wrong i could be able to install the version i like ... doesn't it?

----

Well thank you again for being so helpfull and with so much patience :)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Happolo2 wrote: Is there a way for knowing which Tcl Version is on the server where i have my shell account? If there is a different version if i'm not wrong i could be able to install the version i like ... doesn't it?
in your shell, type tclsh and then info patchlevel

you can install your own Tcl library in your home directory by using --prefix=/path/to/your/home/dir switch of Tcl's configure script; then you'll need to recompile your bot against that library by using --with-tcllib and --with-tclinc switches of eggdrop's configure

but I wouldn't bother to install Tcl 8.5 just for the sake of using -nocase with [lsearch]
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Happolo2 wrote:
Sir_Fz wrote:
1) you can, but you'll have to remove the 1=,2=...etc from each line or alter the script to skip it (but removing them is better).
I try to explain why i was asking for using .ini file or .txt file but not modified.
Now with Mirc we have 3 mirc clients running this script on three different computers. So sometimes we have to check to have on each mirc the same list of nicks or a nick can be banned because it is only on 2 lists because the third client was out of the channel when the list has been modified.
Now i wanted to make this script running on the shell by the eggdrop and not on the computer... and with your precious help i think i can do it.
Just i thought to the Dcc send command ... so everyone (botmasters) can download the nick list from the shell and put it in his script on the mirc client on his computer.
The problem is that if i can't use the .ini file or if i've to modified the .txt file ... it becomes difficult to have a fast "upgrade" of all lists. (cause the list has more or less 600 nicks).
This is the reason for which i was asking if it was possible to use .ini file or .txt files "just changing .ini to .txt extension".
Use:

Code: Select all

# initialize empty nick list
set nlist {}
# try to read in the list from file
if ![catch {set f [open file.txt]}] {
 foreach nnick [split [read $f][close $f] \n] {
  if {$nnick != ""} {
   lappend nlist [string tolower [regsub {^[0-9]+=} $nnick ""]]
  }
 }
}
# save the list into file every minute
bind time - * save
proc save args {
 set f [open file.txt w]
 set count 0
 foreach n $::nlist {
  if {$n != ""} {
   puts $f "[incr count]=$n"
  }
 }
 close $f
}
bind join - {#yourchan %} foo
proc foo {n u h c} {
# don't check +o botusers
 if [matchattr $h o|o $c] return
 if {[lsearch -exact $::nlist [string tolower $n]] != -1} {
  newchanban $c $n!*@* $::nick badnick 5
  putkick $c $n badnick
 }
}
# allow commands from botmasters only
bind pub m !add bar
bind pub m !del bar
proc bar {n u h c t} {
 if {$::lastbind == "!add"} {
  if {[lsearch -exact $::nlist [string tolower $t]] == -1} {
   lappend ::nlist [string tolower $t]
  }
 } {
  if {[set i [lsearch -exact $::nlist [string tolower $t]]] != -1} {
   set ::nlist [lreplace $::nlist $i $i]
  }
 }
}
bind pub m !take moo
proc moo {n args} {
 if {[dccsend file.txt $n] != 0} {
  puthelp "notice $n :cannot send"
 }
}
This way you're able to use the file of list format like number=nick.

Edit2: Fixed bug in !add cmd.
Edit: Fixed Tcl error and edited the reading and writing.
Last edited by Sir_Fz on Thu Feb 08, 2007 6:58 am, edited 4 times in total.
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Post by Happolo2 »

Hi again.
Sorry if i haven't thank you before but i was busy in real life.
By the way i tried to config my first eggdrop (i thought it was easier) and to make the script as you wrote.

I've some problems with it.

Before starting the bot my nick list finishes with:

613=last nick in the list



As soon as i start the bot... the nick list becomes:

613=last nick in the list
614=
615=
616=


Then when i try to use:

!add nick

I can read this thing in the telnet:

Tcl error [bar]: wrong # args: no script following "{[set i [lsearch -exact $::nlist [string tolower $" argument


Can someone help me with this error?

I don't know if can be usefull to know, the nick.txt is in the main directory of the eggdrop and not in the one with tcl scripts.


Also the !del nick doesn't work.
The error is the same:

Tcl error [bar]: wrong # args: no script following "{[set i [lsearch -exact $::nlist [string tolower $" argument


Thank you again to everybody.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

For fixing the error, replace

Code: Select all

if {[set i [lsearch -exact $::nlist [string tolower $t]]] != -1}
with

Code: Select all

if {[set i [lsearch -exact $::nlist [string tolower $t]]] != -1} {
As for the nicks.txt format, make sure that the nicks are stored each on a new line because I don't see why it shouldn't read or write correctly.

Edit: I've edited the code above, try it now and see if the problem persists. (I've made some changes to reading and writing)
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Post by Happolo2 »

Now i had this error loading the eggdrop:
Tcl error in file 'killer.conf':
can not find channel named "file11"
while executing
"close $f "
(file "scripts/scriptfinale.tcl" line 21)
invoked from within
"source scripts/scriptfinale.tcl"
(file "killer.conf" line 323)
(killer.conf it's the config file, scriptfinale.tcl it's the tcl where i copied your script).


----

I tried to add a {

instead of
proc save args {
i wrote:
proc save args {{

---

now it loads but it gives me this error:
Tcl error [save]: invalid command name "
set f [open nick.txt w]
set count 0
foreach n $::nlist {
if {$n != ""} {
puts $f "[incr count]=$n"}
}
---

Maybe i put the { in the wrong place.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

puts $f "[incr count]=$n"}
should be

Code: Select all

puts $f "[incr count]=$n"
I fixed it.
H
Happolo2
Voice
Posts: 6
Joined: Sun Jan 15, 2006 7:08 pm

Post by Happolo2 »

Hi Sir_Fz and hi all again.
Now the eggdrop load without any problems but it doesn't works.
Sometimes it bans randomly a nick with the message: "badnick".
But as i said... it's a random ban. The nick can be or not be in the list.

The !add and the !del commands doesn't work as well.

Unfortunately i can't say anything else 'cause also in telnet no error appears.

I just know that it doesn't work. Can be a shell trouble? Can be a bad set in the .conf file? Can be a problem of the net? Have i to make any other commands before can use !add or !del ? Can be a list problem?
I don't know which info i can give you for helping you to help me :) Just ask pls.

Thank you.
Post Reply