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.

Help with writing and checking files

Old posts that have not been replied to for several years.
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Help with writing and checking files

Post by Dizzle »

hi, im writing myself a request script for a friend of mine, the idea is like this.

!request #channel

then the bot is going too check a lot of things i want in a channel,
when the request is approved then i like too make the bot write the name off the channel too a file

ive read suninet.nl

and have managed too do this,

Code: Select all

set chanfile "scripts/channel/chanfile.txt"

set changood [open $chanfile w] 
puts $changood "$setting(chan)" 
close $changood
that's working out well, the bot writes the channel too the file, butt when another channel is requested, its writing over the existing channel name, well i know the script is made is not enough so i ask you guys, can you help me a little with making a little script that makes this feature possible.

And when a channel is requested again i like too check the chanfile.txt if the channel is already in there.

Can you guys help me with this, thx in advance.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

set f [open $chanfile a]
puts $f "$chan: $setting($chan)"
close $f
i.e. open the file for appending, and output the channel name along settings
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

$setting(chan) is the channel name of the requested channel. is see that your using a for opening

my discription says :

a Open the file for writing only. The file must already exist,
and the file is positioned so that new data is appended to the file.

So that is possible

then the Code should be

Code: Select all

set f [open $chanfile a] 
puts $f "$setting($chan)" 
close $f 
butt how i will be able too check the if $settingchan doest match a channel written in $chanfile

this is the part i coded, butt that aint working

Code: Select all

set chanrequest [open $chanfile r]
set info [read $chanrequest]
if {([string match "$info"  $setting(chan)])} {
putserv "NOTICE $setting(nick) : This channel already excist"
What am i doing wrong ??
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

i know this is not enough, can anybody give me some advice
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

what are you trying to accomplish? save channel names in a file and check if a channel name is already there? explain in details
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

well, there is one bot : the Mainbot, who does the requests off ppl, if he finds it ok in the channel. He will send a relaybot in there.

Butt in my old script ppl can request as many relaybots as they want, just too make it idle bots. So i want too make a general request file where all approved channels are written in, so if ppl request an relaybot twice for a channel the bot can cancel the request. That's what i like too acomplish. I know there is a good way too make it work, butt i didnt found it yet.

So help will be very welcome :)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

write (append) channel name to file:

Code: Select all

set f [open filename a]
puts $f $channel
close $f
check if it's already there:

Code: Select all

set f [open filename]
set chan [string tolower $channel]
set chans [string tolower [split [read $f] \n]]
if {[lsearch -exact $chans $chan] == -1} {
# not found
} else {
# found
}
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

Very much thx for the code, i tried too put it in but its giving an error
This is wat i placed

Code: Select all

set f [open $requestchan] 
set chan [string tolower $setting(chan)] 
set chans [string tolower [split [read $f] \n]] 
if {[lsearch -exact $chan $chans] == -1} { 
He cant read $setting(chan) "can't read "settings(chan)": no such variable"

Why cant he read this, cant he put a variable between []

setting(chan) = the channel wich is requested by the user

Help plz :oops:
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if you defined settings in another procedure, did you make it global in both?
if he is claming there is no such var, then there isnt (which is valid for the current procedure) ^-^.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

well i have put it in both global proc's

here is the whole code, its an ajusted code from metroid

Code: Select all


# Configuration 

# .txt file for channel saving 

set requestchan "scripts/pcwbe/requestchan.txt"

# homechannel where they can request 
set setting(home) "#Preatorians" 
# users the channel needs atleast 
set setting(needed) "1" 
# deny request if there is no Q or L? 
set setting(service) "1" 
# deny request if S is on chan
set setting(spamscan) "1"
# the flags he wants 
set setting(flags) "+av" 

# end of config 

# don't touch this setting! 
set setting(busy) 0 

bind pub -|- !request request:pub 

proc request:pub {nick host hand chan arg} { 
global setting
# ignore the request because it isn't the request channel 
if {![string equal $chan $setting(home)]} { 
return 0 
}
if {$setting(busy)} { 
putquick "NOTICE $nick : 4REQUEST DENIED 1 There is currently already an request in progress, plz wait a minute" 
return 0 
} 
set channel [lindex [split $arg] 0] 
# tell him he needs to input a channel first 
if {$channel == ""} { 
putquick "NOTICE $nick : Use !request #channel too make the right request, change #channel in your channel name (example !request #pcw.be)" 
return 0 
} 
if {[validchan $channel]} { 
return 0; 
}
# activate the busy signal so no other requests can be done 
bind RAW -|- 315 request:endofwho 
set setting(busy) 1 
set setting(chan) "$channel" 
set setting(nick) "$nick" 
channel add $channel 
} 

proc request:endofwho {from key arg} { 
global setting requestchan chanrequest
if {$setting(busy)} { 
if {![onchan $setting(nick) $setting(chan)]} { 
set setting(busy) 0 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : You aren't on $setting(chan)"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, not on $setting(chan)"
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
} 
}
set f [open $requestchan] 
set chan [string tolower $setting(chan)] 
set chans [string tolower [split [read $f] \n]] 
if {[lsearch -exact $chan $chans] == -1} { 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : $settings(chan) is already in channel database, if this is not the case contact Dizzle"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick)was denied, $setting(chan)already has a relaybot from #pcw.be"
unset $channel
channel remove $setting(chan) 
close f 
unbind RAW -|- 315 request:endofwho 
return 0 
} 
if {![isop $setting(nick) $setting(chan)]} { 
set setting(busy) 0 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : You aren`t opped on $setting(chan)"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, not opped in $setting(chan)"
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
} 
if {$setting(service)} { 
if {![onchan L $setting(chan)] && ![onchan Q $setting(chan)]} { 
set setting(busy) 0 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : Q or L was not found on $setting(chan)"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, no service bots L or Q in $setting(chan)"
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
} 
} 
if {$setting(spamscan)} { 
if {[onchan S $setting(chan)]} { 
set setting(busy) 0 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : S (Quakenet spamscan) was found on $setting(chan)"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, quakenet service bot S was found on $setting(chan)"
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
}
}
if {[llength [chanlist $setting(chan)]] < $setting(needed)} { 
set setting(busy) 0 
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : Not enough users" 
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, $setting(needed) users needed. $setting(chan) had [llength [chanlist $setting(chan)]] users" 
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
} 
if {![validuser [nick2hand $setting(nick)]]} { 
adduser $setting(nick) *!*@[lindex [split [getchanhost $setting(nick) $setting(chan)] @] 1] 
} 
chattr [nick2hand $setting(nick)] |+n $setting(chan) 
putquick "PRIVMSG $setting(nick) : 3REQUEST ACCEPTED 1 . A bot will join soon . Please give the bot $setting(flags) on [request:service $setting(chan)] for better results (+m), READ THIS : the bot will leave if your below 15 users" 
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) is accepted, $setting(nick) requested me for $setting(chan). The channel has [llength [chanlist $setting(chan)]] users. And they have the service bot : [request:service $setting(chan)]. Hafe fun with our system"
set changood [open $requestchan a] 
puts $changood "$setting(chan)" 
close $changood
channel remove $setting(chan) 
unset setting(chan); unset setting(nick) 
set setting(busy) 0 
unbind RAW -|- 315 request:endofwho 
return 1 
} 

proc request:service {channel} { 
if {[onchan L $channel]} { 
return "L" 
} elseif {[onchan Q $channel]} { 
return "Q" 
} 
}

proc request:spamscan {channel} {
if {[onchan S $channel]} {
return "S"
}
}



Whos can see the problem :oops:
User avatar
Jil Larner
Voice
Posts: 14
Joined: Fri Aug 20, 2004 8:28 am
Location: France

Post by Jil Larner »

Look at you error and variable name, you used settings instead of setting.
The error occurs in the notice text when the channel is already in the bot database ;)
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

thx didt saw that error, learned something today.

butt when i request, he saying with every channel, already in bot database, but my bot isnt in that channel.

why is that ?
D
Dizzle
Op
Posts: 109
Joined: Thu Apr 28, 2005 11:21 am
Contact:

Post by Dizzle »

Well my script, is not givin any more errors, butt one thing is not working
When is do a request (testing) he saying at every channel its already in its database
I cant see what im doing wrong, here's the piece of code where it al happends

Code: Select all

set f [open $requestchan] 
set chan [string tolower $setting(chan)] 
set chans [string tolower [split [read $f] \n]] 
if {![lsearch -exact $chan $chans] == -1} { 
dccbroadcast "$chan was not found in chanfile"
set f [open $requestchan a] 
puts $f "$setting(chan)" 
close $f
} else {
set setting(busy) 0 
dccbroadcast "$chan was found in chanfile"
putquick "NOTICE $setting(nick) : 4REQUEST DENIED 1 : $setting(chan) is already in channel database, if this is not the case contact Dizzle"
putquick "PRIVMSG $setting(home) : #pcw.be :: The request from $setting(nick) was denied, $setting(chan) already has a relaybot from #pcw.be"
channel remove $setting(chan) 
unbind RAW -|- 315 request:endofwho 
return 0 
}
$setting(nick) = the nick of the one requesting
$setting(chan) = the channel givin in the request (request #channel)
$requestchan = the file where channels should be saved

What's going wrong ?
User avatar
Jil Larner
Voice
Posts: 14
Joined: Fri Aug 20, 2004 8:28 am
Location: France

Post by Jil Larner »

well, try to change the if statement for

if {[lsearch -exact $chan $chans] != -1}

i don't know the real behaviour with ![cmd] == smth. The line above might work better
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

if {[lsearch -exact $chans $chan] != -1}
where $chans is the list of channels and $chan is the channel you're searching for in the list (note that case matters).
Locked