| View previous topic :: View next topic |
| Author |
Message |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Jan 04, 2013 8:32 am Post subject: Need some help plz |
|
|
Im writing a script which adds bans to a text file tht part works fine its the output to channel i cant get right atm it outputs like this
CN - (BaNNeD LiST) - GROUP1GROUP2
but i'd like it to output like this
CN - (BaNNeD LiST) - GROUP1 GROUP2 (with the space in between)
here's what i have so far
| Code: | # set the location of the banned.txt file
set banned_(txt) "/*****/*****/***/scripts/banned.txt"
#set the sitename
set site_(name) "CN"
#set the trigger
bind pub - !banned get:banned
bind pub - !addban get:addban
proc get:addban {nick uhost handle chan text} {
global banned_
if {$text == ""} {
return 0
}
set line_to_add $text
set fname $banned_(txt)
set fp [open $fname "a"]
puts $fp $line_to_add
close $fp
putquick "PRIVMSG $chan : \0034Ban Added Sucessfully\003"
}
proc get:banned {nick uhost handle chan arg} {
global banned_ site_
foreach line [split [exec cat $banned_(txt)] " "] {
putquick "PRIVMSG $chan :\00314$site_(name)\003 - \0034(BaNNeD LiST)\003 - $line"
}
}
putlog "COBRa Banned Script V1.0 Sucsesfully loaded" |
|
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri Jan 04, 2013 10:38 am Post subject: |
|
|
| Code: |
### reference:
### http://forum.egghelp.org/viewtopic.php?t=6885
proc get:banned {nick uhost handle chan arg} {
global banned_ site_
set fp [open $banned_(txt) "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
foreach ban $lines {
putserv "privmsg $chan :$ban"
}
}
|
Substitute that and try it.
Else:
| Code: |
### reference:
### http://forum.egghelp.org/viewtopic.php?t=6885
proc get:banned {nick uhost handle chan arg} {
global banned_ site_
set fp [open $banned_(txt) "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
putserv "privmsg $chan :$lines"
}
|
Try that.
The second example may be what you are looking for.
(You'll have to edit in the other text and color codes that you desire later)
I have not tested the above, so I'm hoping for no typos.
I hope this helps. |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Jan 04, 2013 1:06 pm Post subject: |
|
|
Works great ty very much
Just one more question if i wanted to del a single entry would tht be possible plz |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Jan 04, 2013 1:42 pm Post subject: |
|
|
Ty looked at tht earlier and couldnt understand the code  |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Fri Jan 04, 2013 1:56 pm Post subject: |
|
|
Sorry, that actually wasn't the right string, doesn't even include the delete line function:) This string does...
http://forum.egghelp.org/viewtopic.php?t=19179
Basicly, you have to open a new file, and write all the lines except the line you wish to delete, to the new file.
then delete the original file, and rename the new file:)
See this help string for how to code this yourself... http://forum.egghelp.org/viewtopic.php?t=6885 _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Last edited by SpiKe^^ on Sat Jan 05, 2013 2:17 am; edited 1 time in total |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Jan 04, 2013 2:26 pm Post subject: |
|
|
ive come up with this but it seems to del everything where am i going wrong plz
| Code: | proc get:delban {nick uhost handle chan text} {
global banned_
if {$text == ""} {
return 0
}
set line_to_delete $text
set fname $banned_(txt)
set fp [open $fname "w"]
puts $fp $line_to_delete
close $fp
putquick "PRIVMSG $chan : \0034Ban Removed Sucessfully\003"
} |
|
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Fri Jan 04, 2013 3:31 pm Post subject: |
|
|
In that process, you are overwriting the entire file, with the line you wish to delete.
Basicly, you have to open a new file, and write all the lines EXCEPT the line you wish to delete, to the new file.
then delete the original file, and rename the new file.
http://forum.egghelp.org/viewtopic.php?t=6885
This help string has all the file functions layed out in their simplest forms, if you want to try writing this yourself.
Do you really want help, or do you want someone to write you a process? If you just want someone to write you a process,
this forum post string http://forum.egghelp.org/viewtopic.php?t=19179 has the delete/edit/add functions included.
Simply rem out the binds you don't wish to use. Or just cut out the parts you need... but that route seems a waste though,
because it also includes all the other file functions you will want next:) _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Last edited by SpiKe^^ on Sat Jan 05, 2013 2:22 am; edited 2 times in total |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Fri Jan 04, 2013 4:10 pm Post subject: |
|
|
| tbh i think im gonna need someone to write the code in its entirity it seems very involved can u help plz ? |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Fri Jan 04, 2013 5:41 pm Post subject: EditTextFile+TimedReadLine Version 1.0 |
|
|
I would, but I just wrote the same thing a few weeks ago... please just use the last script in this string -> http://forum.egghelp.org/viewtopic.php?t=19179
Disable the timed part -> set eTxFile(timed) "0"
All the included commands will come in handy when working with the information in your text file, you can change the triggers to suit your needs, and disable the commands you wont use...
Has help in the script file for all the included commands, and help available by public trigger for every command... you can read the whole file or any line in the file, edit any line in the file, delete any line in the file, even add a line to the beginning of the file or the end of the file or anywhere in between:)
Script even checks for if the file exists, and will make it when needed, if it does not exist.
If I thought this script wasn't what you needed, I would write another, but it is what you are needing, so I won't be rewriting it again any time soon:)
You can run this script, and yours too. Yours to do the things you have so far, and mine to do the other file work.
Please just try the script as it is now, I'm sure you will come to like it.
If after you have run it, there are things you would like it to do differently, we may be able to address those issues. _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Sat Jan 12, 2013 7:33 am Post subject: |
|
|
After much help from the guys in this thread here is the final draught
| Code: | # set the location of the banned.txt file
set banned_(txt) "**************"
#set the sitename
set site_(name) "*******"
#set the trigger
bind pub - !banned get:banned
bind pub - !addban get:addban
bind pub - !delban get:delban
proc get:banned {nick uhost handle chan arg} {
global banned_ site_
set fp [open $banned_(txt) "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
putserv "privmsg $chan :\00314$site_(name)\003 - \0034(AFFiLs BaNNeD LiST)\003 - $lines"
}
proc get:addban {nick uhost handle chan text} {
global banned_
if {$text == ""} {
putserv "PRIVMSG $chan :Usage: !addban <grpname>"
return 0
}
set line_to_add $text
set fname $banned_(txt)
set fp [open $fname "a"]
puts $fp $line_to_add
close $fp
putquick "PRIVMSG $chan : \0034Ban Added Sucessfully\003"
}
proc get:delban {nick uhost handle chan text} {
global banned_
## putserv "privmsg $chan :text is: $text"
set fp [open $banned_(txt) "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
## putserv "privmsg $chan :lines is: $lines"
set el_num [lsearch -nocase $lines $text]
## putserv "privmsg $chan :el_num is: $el_num"
if {$el_num != -1} {
set lines [lreplace $lines $el_num $el_num]
}
## putserv "privmsg $chan :lines is now: $lines"
putquick "PRIVMSG $chan : \0034Ban Removed Sucessfully\003"
set fp [open $banned_(txt) "w"]
foreach element $lines {
puts $fp $element
}
close $fp
}
putlog "COBRa Banned Script V1.2 Sucsesfully loaded" |
works for me once big thx to SpiKe^^/willyw for their help |
|
| Back to top |
|
 |
|