
set file "reqs.txt"

bind pub m|m .add pub:add
bind pub m|m .del pub:del
bind pub - ?? pub:check
bind pub m|m .list pub:list
bind pub m|- .globadd pub:globaladd
bind pub m|- .globdel pub:globaldel
bind time - "* * * * *" start:save

### so the words will be saved into the arrays
proc start:read {} {
global cwd file
  if {[file exist $file]} {
    set fs [open $file r] 
    while {![eof $fs]} { 
       gets $fs line; set $line [join $line]
         if {[llength $line] >= 2 } {
            set wchan [lrange $line 0 0]
            if {![info exist cwd($wchan)]} { set disc [lrange $line 1 end]; set cwd($wchan) "$disc" }
         }
    }  
    close $fs 
  }
}
### Every minute the arrays will be saved into the file with the name $file
proc start:save {mi ho da mo ye} {
global cwd file
set fs [open $file w+]
set total "[llength [array names cwd]]"
    foreach array_id [array names cwd] {
       if {$cwd($array_id) != ""} {
          set disc "$cwd($array_id)";
          puts $fs "$array_id $disc"
       }
    }
close $fs
putcmdlog "UPDATE: \002$total\002 words saved in the file \002$file\002."
}

proc pub:add { nick username handle channel args } {
global chan_ign
set args [join $args]
set word [lrange $args 0 0]
set disc [join [lrange $args 1 end]]
set channel [string tolower $channel]; set chan_ign [string tolower $chan_ign]
 if {[lsearch $chan_ign $channel] < "0" } {
  if {$word == ""} {
     putserv "NOTICE $nick :You forgot the word! \037Syntax: \002.add <word> <discription>\002\037"
  } elseif {$disc == ""} {
     putserv "NOTICE $nick :You forgot the discription! \037Syntax: \002.add <word> <discription>\002\037"
  } else {
     global cwd
     set cwd($word$channel) "$disc"
     putserv "NOTICE $nick :Added succesfully the word \002$word\002 in the channel \002$channel\002 with the discription: \002$disc\002"
  }
 } else { putserv "NOTICE $nick :This channel is ignored for using the DictionarySystem. Please take contact with the owner of this bot." }
}

