egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Sun Jan 15, 2006 7:45 pm    Post subject: Script for banning on join if the nick isn't in a list Reply with quote

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 Smile 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).


Quote:

;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 4Smile }
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.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Jan 16, 2006 12:31 am    Post subject: Re: Script for banning on join if the nick isn't in a list Reply with quote

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:

# 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] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
metroid
Owner


Joined: 16 Jun 2004
Posts: 771

PostPosted: Mon Jan 16, 2006 3:34 am    Post subject: Reply with quote

Code:
if {$::lastbind == "add"} {


should be

Code:
if {$::lastbind == "!add"} {


if the bind is !add (if i'm not mistaken :p)
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jan 16, 2006 6:16 am    Post subject: Reply with quote

You might also want to avoid duplicates, instead of
Code:
if {$::lastbind == "add"} {
   lappend ::nlist $t
} else {

use
Code:
if {$::lastbind == "!add"} {
   if {[lsearch -noc $::nlist $t] == -1} {
      lappend ::nlist $t
   }
} else {

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Mon Jan 16, 2006 8:24 am    Post subject: Reply with quote

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

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

1)
Quote:
# 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
Quote:
# 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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jan 16, 2006 9:08 am    Post subject: Reply with quote

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

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

1)
Quote:
# 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
Quote:
# 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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Mon Jan 16, 2006 2:40 pm    Post subject: Reply with quote

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".

Quote:

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 Smile

Quote:

3) !del nick is enough for deleting.

[/quote]

Thanks Smile

---

I add another question if i can.

Quote:
# 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 Smile
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Jan 17, 2006 12:41 am    Post subject: Reply with quote

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] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Jan 18, 2006 7:20 am    Post subject: Reply with quote

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:
# 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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts


Last edited by Sir_Fz on Thu Feb 08, 2007 6:58 am; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Wed Jan 25, 2006 6:33 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Jan 25, 2006 7:00 pm    Post subject: Reply with quote

For fixing the error, replace
Code:
if {[set i [lsearch -exact $::nlist [string tolower $t]]] != -1}

with
Code:
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)
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Wed Jan 25, 2006 8:01 pm    Post subject: Reply with quote

Now i had this error loading the eggdrop:

Quote:

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

Quote:

proc save args {


i wrote:

Quote:
proc save args {{



---

now it loads but it gives me this error:

Quote:

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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Jan 25, 2006 8:19 pm    Post subject: Reply with quote

Code:
puts $f "[incr count]=$n"}

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

I fixed it.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Happolo2
Voice


Joined: 15 Jan 2006
Posts: 6

PostPosted: Sat Jan 28, 2006 10:03 am    Post subject: Reply with quote

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 Smile Just ask pls.

Thank you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber