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.

add information to a txt

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
a
andrestavara
Voice
Posts: 4
Joined: Fri Jan 14, 2011 10:36 pm

add information to a txt

Post by andrestavara »

Hi I am new to this forum, I wish someone please help me please.
I want my bot do the following
read and add information

do not know if I could be in a xml, sql or txt

in the database txt, sql or xml:

date 1
----------------------------------------
model: VFAv1
description: VFAv1 router spain
tutorial link: http//link

date2
---------------------------------------
model: AAA1
description: AAA1 router mexico TELMEx
tutorial link: http://link

date3
----------------------------------------
model: FSDFD2v
description: FSDFD2v modem usb mexico
tutorial link: http://link
date4
----------------------------------------
model: FFF132v
description: FFF132v modem usb mexico
tutorial link: http://link

in channel #helprouters
<user>!search AAA1
<bot> I found one results:
<bot> router: AAA1 description: AAA1 router mexico TELMEx Link manual: http:link
<user2>!search modem mexico
<bot>I found two results:
<bot> model: FFF132v, model: FSDFD2v
<user2> !search FSDFD2v
<bot> router: FSDFD2v description: FSDFD2v modem usb mexicox Link manual: http:link
<admin>!addtuto F11111 | F1111 modem peruvian | http://link
<bot> was added successfully
I would greatly appreciate please help me
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Test this:
<tvrsh> !addtuto AAA1|AAA1 router mexico TELMEx|http://link
<@bionic> Router: AAA1, Description: AAA1 router mexico TELMEx, Link manual: http://link. Added successfully!
<tvrsh> !search 1111
<@bionic> I found one result:
<@bionic> Router: F11111, Description: F1111 modem peruvian, Link manual: http://link.
<tvrsh> !search modem
<@bionic> I found 2 results:
<@bionic> Models: F11111, FSDFD2v.
I use this manual to work with file: http://forum.egghelp.org/viewtopic.php?t=6885

Code: Select all

#
# Add new models like this: !addtuto Name|Description|Link
# !addtuto command works only for chan operators.
#
#

bind pub o|o !addtuto modemadd
bind pub -|- !search modemsearch

proc modemadd {nck uhost hand chan text} {
	# The new line.
	set line_to_add "$text"

	# Name of file to append to.
	set fname "yourfile.txt"

	# Open the file in append mode.
	set fp [open $fname "a"]

	# Add the line.
	puts $fp $line_to_add

	# We're done!
	close $fp

	putserv "PRIVMSG $chan :\00314Router: \002\00310[lindex [split $text "|"] 0]\002\00314, Description: \00310[lindex [split $text "|"] 1]\00314, Link manual: \00312\037[lindex [split $text "|"] 2]\037\00314. Added successfully!\003"
} 

proc modemsearch {nick uhost hand chan text} {
	set searchstring $text

	# File name to read.
	set fname "yourfile.txt"

	# Open file for read access (note we're not catching errors, you might
	# want to use catch {} if the file might not exist.
	set fp [open $fname "r"]

	# Here we read in all of the data.
	set data [read -nonewline $fp]

	# Close the file, since we're done reading.
	close $fp

	# Now we split the data into lines.
	set lines [split $data "\n"]

	set searchresult ""
	foreach line $lines {
		if {[string match *$searchstring* [join $line]]} {
			lappend searchresult $line
		}
	}
	if {$searchresult == ""} {
		putserv "PRIVMSG $chan :\00310$nick\00314, nothing found for \00310\002$searchstring\002\00314..."
		return 0
	}
	if {[llength $searchresult] < "2"} {
		putserv "PRIVMSG $chan :\00314I found one result:\003"
		putserv "PRIVMSG $chan :\00314Router: \002\00310[lindex [split [join $searchresult] "|"] 0]\002\00314, Description: \00310[lindex [split [join $searchresult] "|"] 1]\00314, Link manual: \00312\037[lindex [split [join $searchresult] "|"] 2]\037\003."
		return 0
	} else {
		putserv "PRIVMSG $chan :\00314I found \00310[llength $searchresult] \00314results:\003"
		foreach line $searchresult {
			lappend models \00310[lindex [split $line "|"] 0]
		}
		putserv "PRIVMSG $chan :\00314Models: [join $models "\00314, "]\00314.\003"
	}
}
putlog "modem.tcl loaded..."
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
a
andrestavara
Voice
Posts: 4
Joined: Fri Jan 14, 2011 10:36 pm

Post by andrestavara »

thank you very much friend, I have the following problem with this script:

In Txt database:
AAAAA1|model argetina|Link
in irc:
<user> !search aaaaa1
<bot> nothing found for aaaaa1
one could ignore the differences case sensitive?
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Change

Code: Select all

if {[string match *$searchstring* [join $line]]} { 
to

Code: Select all

if {[string match -nocase *$searchstring* [join $line]]} { 
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
O
ORATEGOD
Voice
Posts: 39
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

I have a question from newbies .... the yourfile.txt file what permissions it should have ... since I preobe this code ... but I don't add anything to the txt
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

+wr. should be sufficient, take a look here

https://www.linux.com/training-tutorial ... rmissions/
ComputerTech
O
ORATEGOD
Voice
Posts: 39
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

thank you very much
Post Reply