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 

add information to a txt

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


Joined: 14 Jan 2011
Posts: 4

PostPosted: Fri Jan 14, 2011 10:55 pm    Post subject: add information to a txt Reply with quote

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

Quote:
<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
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sat Jan 15, 2011 6:51 am    Post subject: Reply with quote

Test this:
Quote:
<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:

#
# 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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
andrestavara
Voice


Joined: 14 Jan 2011
Posts: 4

PostPosted: Sat Jan 15, 2011 8:44 pm    Post subject: Reply with quote

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


Quote:
In Txt database:
AAAAA1|model argetina|Link


in irc:

Quote:
<user> !search aaaaa1
<bot> nothing found for aaaaa1


one could ignore the differences case sensitive?
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sun Jan 16, 2011 4:26 pm    Post subject: Reply with quote

Change
Code:
if {[string match *$searchstring* [join $line]]} {
to
Code:
if {[string match -nocase *$searchstring* [join $line]]} {

_________________
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ORATEGOD
Voice


Joined: 08 Jun 2020
Posts: 32

PostPosted: Thu Jan 28, 2021 10:46 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message AIM Address
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Fri Jan 29, 2021 3:26 am    Post subject: Reply with quote

+wr. should be sufficient, take a look here

https://www.linux.com/training-tutorials/understanding-linux-file-permissions/
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ORATEGOD
Voice


Joined: 08 Jun 2020
Posts: 32

PostPosted: Fri Jan 29, 2021 11:23 pm    Post subject: Reply with quote

thank you very much
Back to top
View user's profile Send private message AIM Address
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