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 

File operations

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
loulou7593
Voice


Joined: 08 Apr 2008
Posts: 12

PostPosted: Wed Oct 30, 2013 2:26 pm    Post subject: File operations Reply with quote

Good evening, I do not know how to replace a precise line, either by his number of line, or by detecting a word which appears on this line.
I explain: I have a script of jokes which can send the jokes all X minutes but which it is necessary to adjust in the blague.tcl file
I wanted for example to create a command with a bind pub that when I bang !Addtemp X (X being a figure in minutes) that replaces me in the blague.tcl file the following line

Code:
set blagues(time) 5


For the moment I put him 5 minutes, but afterward to be able to modify her by banging the chan !Addtemp 10 and what that changes in the file 5 there 10.

If somebody had an idea, I am interested.
Thank you in advance.

___________

Here is the code

Code:
#####################################################################
## Configuration du Script ##########################################
#####################################################################

# Anti flood sur les commandes du Bot x:y (x=nombre de fois, y=secondes) :
set fun(flood) 5:10

# Ignorer l'utilisateur après son flood (0=non, 1=oui) :
set fun(ignore) 0

# Si oui, combien de temps (en minutes) :
set fun(ignoretime) 0

# Laisser faire les utilisateurs ayant certains flags :
set fun(ignflags) "-|-"

## Blagues ##########################################################
#####################################################################

# Channels où seront envoyés les blagues :
set blagues(chans) "#chan"

# Intervalle de temps entre chaque blague en minutes (0=désactivé) :
set blagues(time) 5

# Editer ici les blagues :
set blagues(msgs) {
   "Citation : C'est parce que la vitesse de la lumière est supérieure à celle du son, que beaucoup de gens paraissent brillants avant d'avoir l'air con."
   "Citation : La main droite c'est celle où tu as le pouce à gauche."
   "Citation : Je marche pieds nus pour ne plus péter plus haut que mon cul."
   "Citation : La dictature, c'est ferme ta gueule, et la démocatie, c'est cause toujours (Woody Allen)."
   "Citation : Avec les capotes Nestor, t'es pas né, t'es pas mort (Coluche)."
   "Citation : Je ne parle pas aux cons, ça les instruit (Audiard)."
   "Citation : Les hommes préfèrent les blondes parce que les blondes savent ce que les hommes préfèrent (Marilyn Monroe)"
   "Citation : Le travail est l'opium du peuple et je ne veux pas mourir drogue (Boris Vian)"
   "Citation : Les meilleurs moments de la vie à deux, c'est quand on est tout seul (Pierre Dac)"
   
}

#####################################################################
#####################################################################
#####################################################################

proc fun:flood:init {} {
global fun funflood
set fun(floodnum) [lindex [split $fun(flood) :] 0]
set fun(floodtime) [lindex [split $fun(flood) :] 1]
set i [expr $fun(floodnum) - 1]
while {$i >= 0} {
   set funflood($i) 0
   incr i -1
}
}
fun:flood:init

proc fun:flood {nick uhost} {
global fun funflood botnick
if {$fun(floodnum) == 0} {
   return 0
}
set i [expr $fun(floodnum) - 1]
while {$i >= 1} {
   set funflood($i) $funflood([expr $i - 1])
   incr i -1
}
set funflood(0) [unixtime]
if {[expr [unixtime] - $funflood([expr $fun(floodnum) - 1])] <= $fun(floodtime)} {
   if {$fun(ignore)} {
      newignore [join [maskhost *!*[string trimleft $uhost ~]]] $botnick "Flood" $fun(ignoretime)
   }
   return 1
} {
   return 0
}
}

proc fun:pub:bot {nick uhost hand channel arg} {
global fun bot botnick
if ![matchattr $nick $fun(ignflags) $channel] {
   if {[fun:flood $nick $uhost]} {
      return 0
   }
}
if {(([lsearch -exact [string tolower $bot(chans)] [string tolower $channel]] != -1) || ($bot(chans) == "*")) && (![matchattr $hand b]) && ($nick != $botnick)} {
   putserv "PRIVMSG $channel :[lindex $bot(msgs) [rand [llength $bot(msgs)]]]"
   return 1
}
}

if {(($blagues(time) != 0) && (![string match "*fun:blagues*" [timers]]))} {
 timer $blagues(time) fun:blagues
}

proc fun:blagues {} {
global blagues
foreach channel $blagues(chans) {
   puthelp "PRIVMSG $channel :[lindex $blagues(msgs) [rand [llength $blagues(msgs)]]]"
}
if {(($blagues(time) != 0) && (![string match "*fun:blagues*" [timers]]))} {
   timer $blagues(time) fun:blagues
}
return 1
}



I would like to create a command !addtemp X ( X= temp ) And what it modifies the time which is situated on the line.

Example : At present the line is
Code:
set blagues(time) 5

I would want that when I write on the channel !addtemp 10
the line becomes
Code:
set blagues(time) 10


Last edited by loulou7593 on Wed Oct 30, 2013 7:25 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Oct 30, 2013 2:34 pm    Post subject: Reply with quote

Please avoid reviving old topics. Just create your own and link to the old one if you really need to.

Edit: What exactly you want to to? Adjust the time the bot parses the jokes file or want to read a line with a certain line number?

If you could paste the script you want to adjust, we have a lot of members that are more than willing to help out.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Wed Oct 30, 2013 2:39 pm; edited 2 times in total
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Oct 30, 2013 7:38 pm    Post subject: Re: File operations Reply with quote

loulou7593 wrote:
Good evening, I do not know how to replace a precise line,
...



Perhaps some of the info found here:
http://forum.egghelp.org/viewtopic.php?t=6885
would be helpful.
Back to top
View user's profile Send private message
loulou7593
Voice


Joined: 08 Apr 2008
Posts: 12

PostPosted: Thu Oct 31, 2013 1:11 pm    Post subject: Reply with quote

Thx Willyw

I tested this
Code:
set chanback "#chan"
bind pub n !addtemp addtemp
proc addtemp {nick host hand chan arg} {
global botnick
# File name to read.
set fname "scripts/blagues.tcl"

# 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


# Use the code from above (1.) to read in all the lines from the file.
# We continue right after:
set lines [split $data "\n"]

# For the beginning, use line 0, since tcl starts counting at 0. If you want
# to append the line to the end, see the next question for a better way.
set temp [lindex [split $arg " "] 0]
   if {$temp == ""} {
      puthelp "PRIVMSG $::chanback :Time Please specify the time."
      return 0
   }
   

# delete ALL lines ending with " user8"
set match "*set*blagues(time)*"
while {[set i [lsearch -glob $lines $match]]>-1} {
   set set "set"
   set bla "blagues(time)"
   set lines "[lreplace $lines $i $i $set $bla $temp]"
}

 

# Now we insert the line into our list in memory.
#set lines [linsert $lines $where_to_insert $var $arq $temp]

# And now we re-write the file, just like in 3.
set fp [open $fname "w"]
puts $fp [join $lines "\n"]
close $fp }


It deletes me well the line which I want but that writes it to me on several lines

Code:
# Intervalle de temps entre chaque blague en minutes (0=désactivé) :
set
blagues(time)
10


I do not manage to have all on the same line
Back to top
View user's profile Send private message Send e-mail
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Nov 06, 2013 7:56 pm    Post subject: Reply with quote

As replyed to your french similar post, modifying the source of the script is dummy. It'll not takes effect until you rehash or restart the eggdrop.
Doing a set ::blagues(time) XX is better.

btw, here is a small modification of your (silly) script:
Code:
set chanback "#chan"
bind pub n !addtemp addtemp
proc addtemp {nick host hand chan arg} {
   if {[llength $arg]!=1} { return 0; }
   # File name to read.
   set fname "scripts/blagues.tcl"
   # 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

   set fo [open $fname "w"]
   set match "*set*blagues\(time\)*"
   foreach line [split $data "\n"]
      if {[string match $match $line]} {
         set line "set blagues(time) $arg"
      }
      puts $fo $line
   }
   close $fo
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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