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.

Request Help plz

Old posts that have not been replied to for several years.
X
XRTC

Request Help plz

Post by XRTC »

Hello all ...

If any1 could make a tcl that:
-- Any user with o|o flag can msg the bot like /msg botnick +url <url> to add a URL to a text file
--The same user could msg /msg botnick -url <url> to remove one URL
--Or something like that with DCC commands?

It would be very usefull for me, and I think that's not too hard for u masters :) Thanks, I wait replies with help about that.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set file "/path/to/the/file/file.txt"

bind msg o|o !add add_an_url
bind msg o|o !rem remove_an_url

proc add_an_url {nick host hand text} {
  global file
  set a [open $file a+]
  set b [read $a]
  if {[string match "$text*" $b]} { puthelp "PRIVMSG $nick :url already in the file"; return 0
  puts $a $text
  puthelp "PRIVMSG $nick :$text added to the file"
 }

proc remove_an_url {nick host hand text} {
  global file
  set a [open $file r]
  set f [read $a]
  if {![string match "$text*" $f]} { puthelp "PRIVMSG $nick :url not in the file"; return 0 }
  while {![eof $a]} {
    set b [gets $a]
    if {[string tolower [lindex $b 0]] != $text} { lappend z $b }
  }
  close $a
  set n [open $x w]
  foreach k $z {
    if {$k != ""} { puts $n $k }
  }
  close $n
  puthelp "PRIVMSG $nick :$text removed from the file"
 }
this is a very simple and untested script.. but it should do what u want.
Elen sila lúmenn' omentielvo
u
up^to^you

weird and also need help

Post by up^to^you »

i try to use !add url more and more, but the bot allowed it even the url has in the file, seem's this code didnt work 100%, but i dont know also where's the wrong

and is there any code to clear the file using !clearfile, so the file is empty with any text?
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

the bug:

Code: Select all

proc add_an_url {nick host hand text} { 
  global file 
  set a [open $file a+] 
  set b [read $a] 
  if {[string match "$text*" $b]} { puthelp "PRIVMSG $nick :url already in the file"; return 0 
  puts $a $text 
  puthelp "PRIVMSG $nick :$text added to the file" 
} 
should be:

Code: Select all

proc add_an_url {nick host hand text} { 
  global file 
  set a [open $file a+] 
  set b [read $a] 
  if {[string match "$text*" $b]} { puthelp "PRIVMSG $nick :url already in the file"; return 0 }
  puts $a $text 
  puthelp "PRIVMSG $nick :$text added to the file" 
} 
}
the clearfile you will have to make on your own, I don't want t5o make the whole script for you :)
Elen sila lúmenn' omentielvo
u
up^to^you

Post by up^to^you »

nope for the clear file tcl, i also dont need it anyway :P...but i just wanna tell u, if the code above cant detect if the url has been on the file, if you type !add url.bla.bla.bla and then you type it again, the bot still add that to the file, so it make your database file have double or even more the same url. If you dont believe me, just prove it by installing it to your bot, well....is there no one in this forum can help us to prevent this double url added to the file?? :(
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

With a quick look over it, I a few things.

Here is a edited portion, this should work. However, I havn't looked over the rest of the script.

Code: Select all

proc add_an_url {nick host hand text} {
  global file
  set a [open $file a+]
  set b [read $a]
  if {[string match -nocase "*$text*" $b]} {
    puthelp "PRIVMSG $nick :url already in the file"
    return 0
  }
  puts $a $text
  catch {close $a}
  puthelp "PRIVMSG $nick :$text added to the file"
}
u
up^to^you

Post by up^to^you »

well...i dont have an idea, but it's still not working anyway :P

<sfwfsf> add test
<RaIDeN> test added to the file
<sfwfsf> add test
<RaIDeN> test added to the file
<sfwfsf> add test
<RaIDeN> test added to the file
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Opening the file with a+ makes it start at the end of the file. Change it to r+ and it should work. Also to be safe add "seek $a 0 end" before you write to the file.
u
up^to^you

Post by up^to^you »

is this can check some file too? I mean bot can check url in some file (file1,file2,newfile) and if doesnt exist, then the bot add it to newfile

i try to write like this:

set files {
{/home/blah/blah/file1}
{/home/blah/blah/file2}
{/home/blah/blah/newfile}

set file "/home/blah/blah/newfile"

proc add_url {nick host hand text} {
global files file
set a [open $files r+]
set b [read $a]
set c [open $file r+]

if {[string match -nocase "*$text*" $b]} {
return 0
}
puts $c {text}
catch {close $a}

but it didnt work and an error message appear:

[14:41] Tcl error [add_url]: couldn't open "
{/home/blah/blah/file1}
{/home/blah/blah/file2}
{/home/blah/blah/newfile}
": no such file or directory

what's wrong? is there any missing code i put??
thx
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set a [open $files r+] 
u have to split up $files before u can read them
use:

Code: Select all

if {![file exist file]} { set f [open $file a+]; close $f }
to check if a file exsits
Elen sila lúmenn' omentielvo
u
up^to^you

Post by up^to^you »

:o ???
do you mean i must add
if {![file exist file]} { set f [open $file a+]; close $f }
above set a [open $files r+] line??

I try to put it but it still appear error message same with the last, then i try to put it bellow set b [read $a] line, but it show error [01:07] Tcl error [add_url]: invalid command name "files"



can u more specify where i must do?? i'm still really confuse :(

thx
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

do like this:

Code: Select all

set files(1) "/home/blah/blah/file1"
set files(2) "/home/blah/blah/file2"
set files(3) "/home/blah/blah/file3"
## etc.. add as many as u need

if {![file exist files(1)]} { set f [open $files(1) a+]; close $f }
if {![file exist files(2)]} { set f [open $files(1) a+]; close $f }
if {![file exist files(3)]} { set f [open $files(1) a+]; close $f }
## etc.. must match the number of files

proc add_url {nick host hand text} { 
global files
set a [open $files(1) r+] 
set b [read $a] 
set c [open $files(2) r+]
## etc... u have to open and read the files one by one
Elen sila lúmenn' omentielvo
u
up^to^you

Post by up^to^you »

hmm...i try to write like this:


set files(1) "/blah/blah/new.txt"
set files(2) "/blah/blah/file3.txt"
set files(3) "/blah/blah/file2.txt"
set files(4) "/blah/blah/file1.txt"

if {![file exist files(1)]} { set f [open $files(1) a+]; close $f }
if {![file exist files(2)]} { set f [open $files(2) a+]; close $f }
if {![file exist files(3)]} { set f [open $files(3) a+]; close $f }
if {![file exist files(4)]} { set f [open $files(4) a+]; close $f }

proc add_url {nick host hand text} {
global files
set a [open $files(1) r+]
set b [read $a]
set c [open $files(2) r+]
set d [read $c]
set e [open $files(3) r+]
set f [read $e]
if {[string match -nocase "*$text*" $b]||[string match -nocase "*$text*" $d]||[string match -nocase "*$text*" $f]} {
return 0
}
seek $a 0 end
seek $c 0 end
seek $e 0 end
puts $a {text}
catch {close $a}

but my bot only detect if the url already on new file, then i add a different url (that not exist in new file but already exist in file1) example http://bot.com, my bot cant detect it and then add it to new file, even if i add it again, the bot still add it to new file (so, http://bot.com becomes double in new file)

:cry:
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

may I ask why you are using 4 files?
Elen sila lúmenn' omentielvo
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

} 
seek $a 0 end 
seek $c 0 end 
seek $e 0 end 
puts $a {text} 
catch {close $a}
alot of bugs here :)
u are forgetting to close all the files..
and the only thing u are putting into the file are the string "text"
should be

Code: Select all

} 
seek $a 0 end 
seek $c 0 end 
seek $e 0 end 
puts $a $text
catch {close $a} 
catch {close $c} 
catch {close $e}
Elen sila lúmenn' omentielvo
Locked