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.

ByRequest.tcl Version 1.0 (6 Feb 2013)

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ByRequest.tcl Version 1.0 (6 Feb 2013)

Post by SpiKe^^ »

Hey fyre, here's that requests script you were looking for.
Still completely untested, so please let us know how it works out for you:)

Code: Select all

# ByRequest.tcl Version 1.0 (6 Feb 2013) #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #


########### General Text File Settings ###########

# Set the full route & file name of the file to edit #
# Note: The !req <message> command will attempt to make this file if needed.
set byReq(file) {/usr/home/spike/eggdrop/scripts/byreq.txt}


########### Public 'Add Request' Command Settings ###########
## settings for the public !req <message> command ##

# Set the listen channel(s) for !req <message> command #
set byReq(achan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the !req <message> command #
set byReq(aflags) {R|R}

# Set the public trigger for the !req <message> command #
# to add a request at the end of the file:
#    example:  !req I want coke.
set byReq(add) {!req}


########### Public 'Read Requests' Commands Settings ###########
## settings for the public !reqview <req#> and !reqlist commands ##

# Set the listen channel(s) for the public Read Requests commands #
set byReq(rchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read Requests commands #
set byReq(rflags) {o|o}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(rhow) "1"

# Set the public trigger for the !reqview <req#> / !reqview <handle> command #
# to read a specific request (by line number) from the text file
#    example:  !reqview 4
#    note: use to check for correct line before doing !reqedit or !reqdone
# to read all requests by <handle> from the text file
#    example:  !reqview spike
set byReq(read) {!reqview}

# Set the public trigger for the !reqlist command #
# to read all requests from the text file
#    example:  !reqlist
set byReq(readf) {!reqlist}


########### Public 'Edit/Delete Requests' Commands Settings ###########
## settings for the public !reqedit <req#> and !reqdone <req#> commands ##

# Set the listen channel(s) for the public Edit/Delete Requests commands #
set byReq(echan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Edit/Delete Requests commands #
set byReq(eflags) {m|m}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(ehow) "1"

# Set the public trigger for the !reqedit <req#> <new text> command # 
# to edit a specific request (by line number) in the text file 
#    example:  !reqedit 4 coke is not good for health. 
set byReq(edit) {!reqedit} 

# Set the public trigger for the !reqdone <req#> command # 
# to delete a specific request (by line number) from the text file 
#    example:  !reqdone 4 
#    note: this will renumber all requests after request 4! 
set byReq(del) {!reqdone} 


########### Public 'Delete All Requests' Command Settings ###########
## settings for the public !reqpurge command ##

# Set the listen channel(s) for the public Delete All Requests command #
set byReq(dchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Delete All Requests command #
set byReq(dflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(dhow) "1"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(delf) {!reqpurge}


########### Public 'Read User Comment' Command Settings ###########
## settings for the public !requser command ##

# Set the listen channel(s) for the public Read User Comment command #
set byReq(uchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read User Comment command #
set byReq(uflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(uhow) "2"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(user) {!requser}


################ End Settings ################

bind pub $byReq(aflags) $byReq(add) bReqProcAdd
bind pub $byReq(rflags) $byReq(read) bReqProcRead
bind pub $byReq(rflags) $byReq(readf) bReqProcReadF
bind pub $byReq(eflags) $byReq(del) bReqProcDel
bind pub $byReq(eflags) $byReq(edit) bReqProcEdit
bind pub $byReq(dflags) $byReq(delf) bReqProcDelF
bind pub $byReq(uflags) $byReq(user) bReqProcUser
set byReq(achan) [split [string tolower $byReq(achan)]]
set byReq(rchan) [split [string tolower $byReq(rchan)]]
set byReq(echan) [split [string tolower $byReq(echan)]]
set byReq(dchan) [split [string tolower $byReq(dchan)]]
set byReq(uchan) [split [string tolower $byReq(uchan)]]
if {$byReq(rhow) ne "2"} {  set byReq(rhow) 1  }
if {$byReq(ehow) ne "2"} {  set byReq(ehow) 1  }
if {$byReq(dhow) ne "2"} {  set byReq(dhow) 1  }
if {$byReq(uhow) ne "2"} {  set byReq(uhow) 1  }

proc bReqProcAdd {nk uh hn ch tx} {
  set ch [string tolower $ch]  ;  set tx [string trim $tx]
  if {[lsearch -exact $::byReq(achan) $ch]=="-1"} {  return 0  }
  if {$tx eq ""} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::byReq(add) <your-message-here>"
    puthelp "PRIVMSG $ch :Example: $::byReq(add) I want coke."  ;  return 0
  }
  set tf $::byReq(file)  ;  set ftime [clock format [unixtime] -format %D@%R]
  set id [open $tf a]  ;  puts $id "\[$hn\] $tx ($ftime)"  ;  close $id
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Unable to find or make text file: $tf"
  } else {  puthelp "PRIVMSG $ch :$nk: Request Accepted."  } 
  return 0
}

proc bReqProcReadF {nk uh hn ch tx} {
  bReqProcRead $nk $uh $hn $ch $tx file  ;  return 0
} 

proc bReqProcRead {nk uh hn ch tx {do line} } {
  set ch [string tolower $ch]  ;  set tx [string trim $tx]
  if {[lsearch -exact $::byReq(rchan) $ch]=="-1"} {  return 0  }
  if {$byReq(rhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
  if {$do eq "line" && $tx eq ""} {
    puthelp "$pre :Correct syntax is: $::byReq(read) <line# or handle>"
    puthelp "$pre :Example: $::byReq(read) 4"
    puthelp "$pre :Example: $::byReq(read) spike"
    puthelp "$pre :Or type $::byReq(readf) to see all pending requests."  ;  return 0
  } 
  set tf $::byReq(file)
  if {![file exists $tf]} {
    puthelp "$pre :$nk: There are no pending requests."  ;  return 0
  }
  if {$do eq "line"} {  set tx [lindex [split $tx] 0]  ;  set scnt 0
    if {[string is digit -strict $tx]} {  set fline $tx  } else {  set fhand "\\\[$tx\\\] *"  }
  }
  set tid [open $tf]  ;  set lnum 0
  while {![eof $tid]} {  set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$do eq "file"} {  puthelp "$pre :$lnum - $line"
      } elseif {[info exists fline] && $lnum==$fline} {
        puthelp "$pre :$lnum - $line"  ;  break
      } elseif {[info exists fhand] && [string match -nocase $fhand $line]} {
        puthelp "$pre :$lnum - $line"  ;  incr scnt
      }
    }
  }
  close $tid
  if {$lnum=="0"} {  puthelp "$pre :$nk: There are no pending requests."  ;  return 0  }
  if {$do eq "file"} {  puthelp "$pre :List Completed – Total Pending Requests ($lnum)."
  } elseif {[info exists fhand] && $scnt=="0"} {  puthelp "$pre :$tx has no pending requests."
  } elseif {[info exists fline] && $fline>$lnum} {  set tl request
    if {$lnum>"1"} {  set tl requests  }
    puthelp "$pre :$nk: Request number $fline doesn't exist ($lnum pending $tl)."
  }
  return 0
}

proc bReqProcDel {nk uh hn ch tx} {
  bReqProcEdit $nk $uh $hn $ch $tx del  ;  return 0
}

proc bReqProcEdit {nk uh hn ch tx {do edit} } {
  set ch [string tolower $ch]  ;  set tx [split [string trim $tx]]
  if {[lsearch -exact $::byReq(echan) $ch]=="-1"} {  return 0  }
  if {$byReq(ehow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
  if {$do eq "edit"} {
    if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
      puthelp "$pre :Correct syntax is: $::byReq(edit) <req#> <new-message>"
      puthelp "$pre :Example: $::byReq(edit) 4 coke is not good for health."  ;  return 0
    }
  } elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
    puthelp "$pre :Correct syntax is: $::byReq(del) <req#>"
    puthelp "$pre :Example: $::byReq(del) 4"  ;  return 0
  }
  set tf $::byReq(file)
  if {![file exists $tf]} {
    puthelp "$pre :$nk: There are no pending requests."  ;  return 0
  }
  set find [lindex $tx 0]  ;  set tx [string trim [join [lrange $tx 1 end]]]
  set new [file dirname $tf]/newfile.tmp  ;  set nid [open $new w]
  set tid [open $tf]  ;  set lnum 0
  while {![eof $tid]} {  set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$lnum==$find} {
        if {$do eq "edit"} {  set line [split $line]
          set date [lindex $line end]  ;  set hand [lindex $line 0]
          puthelp "$pre :$nk: Requests List Updated successfully."
          puts $nid "$hand $tx $date"
        } elseif {$do eq "del"} {
          puthelp "$pre :$nk: Request Done – Deleted from the list."
        }
      } else {  puts $nid $line  }
    }
  }
  close $tid
  if {$find>$lnum} {
    if {$lnum>"0"} {  set tl request
      if {$lnum>"1"} {  set tl requests  }
      puthelp "$pre :$nk: Request number $find doesn't exist ($lnum pending $tl)."
    } else {  puthelp "$pre :$nk: There are no pending requests."  }
    close $nid  ;  file delete $new
  } else {  close $nid  ;  file rename -force $new $tf  }
  return 0
}

proc bReqProcDelF {nk uh hn ch tx} {
  set ch [string tolower $ch]
  if {[lsearch -exact $::byReq(dchan) $ch]=="-1"} {  return 0  }
  if {$byReq(dhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
  set tf $::byReq(file)
  if {![file exists $tf]} {
    puthelp "$pre :$nk: There are no pending requests."  ;  return 0
  }
  puthelp "$pre :$nk: All pending requests deleted successfully!"
  file delete $tf  ;  return 0
}

proc bReqProcUser {nk uh hn ch tx} {
  set ch [string tolower $ch]  ;  set tx [string trim $tx]
  if {[lsearch -exact $::byReq(uchan) $ch]=="-1"} {  return 0  }
  if {$byReq(uhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
  if {$tx eq ""} {
    puthelp "$pre :Correct syntax is: $::byReq(user) <handle>"
    puthelp "$pre :Example: $::byReq(user) spike"  ;  return 0
  }
  set tx [lindex [split $tx] 0]
  if {![validuser $tx]} {
    puthelp "$pre :$nk: $tx is not a valid user handle."  ;  return 0
  }

  if {[set cmt [getuser $tx COMMENT]] eq ""} {
    puthelp "$pre :$nk: There is no comment for $tx."  ;  return 0
  }
  puthelp "$pre :$nk: $tx - $cmt"  ;  return 0
}

putlog "ByRequest.tcl Ver. 1.0 by SpiKe^^ loaded."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

Thank you so much Spike!!
But have a look below when I tried to test this script...

In Public:
<fyre> !reqview
<fyre> !reqedit
<fyre> !requser
<fyre> !reqlist
In Partyline:
<(Bot> [05:49] Tcl error [bReqProcRead]: can't read "byReq(rhow)": no such variable
<(Bot> [05:49] Tcl error [bReqProcEdit]: can't read "byReq(ehow)": no such variable
<(Bot> [05:49] Tcl error [bReqProcUser]: can't read "byReq(uhow)": no such variable
<(Bot> [05:50] Tcl error [bReqProcReadF]: can't read "byReq(rhow)": no such variable
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Modifyed it.. it should work now
If that error was the only one.

Code: Select all

# ByRequest.tcl Version 1.0 (6 Feb 2013) #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #


########### General Text File Settings ###########

# Set the full route & file name of the file to edit #
# Note: The !req <message> command will attempt to make this file if needed.
set byReq(file) {/usr/home/spike/eggdrop/scripts/byreq.txt}


########### Public 'Add Request' Command Settings ###########
## settings for the public !req <message> command ##

# Set the listen channel(s) for !req <message> command #
set byReq(achan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the !req <message> command #
set byReq(aflags) {R|R}

# Set the public trigger for the !req <message> command #
# to add a request at the end of the file:
#    example:  !req I want coke.
set byReq(add) {!req}


########### Public 'Read Requests' Commands Settings ###########
## settings for the public !reqview <req#> and !reqlist commands ##

# Set the listen channel(s) for the public Read Requests commands #
set byReq(rchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read Requests commands #
set byReq(rflags) {o|o}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(rhow) "1"

# Set the public trigger for the !reqview <req#> / !reqview <handle> command #
# to read a specific request (by line number) from the text file
#    example:  !reqview 4
#    note: use to check for correct line before doing !reqedit or !reqdone
# to read all requests by <handle> from the text file
#    example:  !reqview spike
set byReq(read) {!reqview}

# Set the public trigger for the !reqlist command #
# to read all requests from the text file
#    example:  !reqlist
set byReq(readf) {!reqlist}


########### Public 'Edit/Delete Requests' Commands Settings ###########
## settings for the public !reqedit <req#> and !reqdone <req#> commands ##

# Set the listen channel(s) for the public Edit/Delete Requests commands #
set byReq(echan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Edit/Delete Requests commands #
set byReq(eflags) {m|m}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(ehow) "1"

# Set the public trigger for the !reqedit <req#> <new text> command #
# to edit a specific request (by line number) in the text file
#    example:  !reqedit 4 coke is not good for health.
set byReq(edit) {!reqedit}

# Set the public trigger for the !reqdone <req#> command #
# to delete a specific request (by line number) from the text file
#    example:  !reqdone 4
#    note: this will renumber all requests after request 4!
set byReq(del) {!reqdone}


########### Public 'Delete All Requests' Command Settings ###########
## settings for the public !reqpurge command ##

# Set the listen channel(s) for the public Delete All Requests command #
set byReq(dchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Delete All Requests command #
set byReq(dflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(dhow) "1"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(delf) {!reqpurge}


########### Public 'Read User Comment' Command Settings ###########
## settings for the public !requser command ##

# Set the listen channel(s) for the public Read User Comment command #
set byReq(uchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read User Comment command #
set byReq(uflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(uhow) "2"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(user) {!requser}


################ End Settings ################

bind pub $byReq(aflags) $byReq(add) bReqProcAdd
bind pub $byReq(rflags) $byReq(read) bReqProcRead
bind pub $byReq(rflags) $byReq(readf) bReqProcReadF
bind pub $byReq(eflags) $byReq(del) bReqProcDel
bind pub $byReq(eflags) $byReq(edit) bReqProcEdit
bind pub $byReq(dflags) $byReq(delf) bReqProcDelF
bind pub $byReq(uflags) $byReq(user) bReqProcUser
set byReq(achan) [split [string tolower $byReq(achan)]]
set byReq(rchan) [split [string tolower $byReq(rchan)]]
set byReq(echan) [split [string tolower $byReq(echan)]]
set byReq(dchan) [split [string tolower $byReq(dchan)]]
set byReq(uchan) [split [string tolower $byReq(uchan)]]
if {$byReq(rhow) ne "2"} {  set byReq(rhow) 1  }
if {$byReq(ehow) ne "2"} {  set byReq(ehow) 1  }
if {$byReq(dhow) ne "2"} {  set byReq(dhow) 1  }
if {$byReq(uhow) ne "2"} {  set byReq(uhow) 1  }

proc bReqProcAdd {nk uh hn ch tx} {
	set ch [string tolower $ch]  ;  set tx [string trim $tx]
	if {[lsearch -exact $::byReq(achan) $ch]=="-1"} {  return 0  }
	if {$tx eq ""} {
		puthelp "PRIVMSG $ch :Correct syntax is: $::byReq(add) <your-message-here>"
		puthelp "PRIVMSG $ch :Example: $::byReq(add) I want coke."  ;  return 0
	}
	set tf $::byReq(file)  ;  set ftime [clock format [unixtime] -format %D@%R]
	set id [open $tf a]  ;  puts $id "\[$hn\] $tx ($ftime)"  ;  close $id
	if {![file exists $tf]} {
		puthelp "PRIVMSG $ch :Unable to find or make text file: $tf"
	} else {  puthelp "PRIVMSG $ch :$nk: Request Accepted."  }
	return 0
}

proc bReqProcReadF {nk uh hn ch tx} {
	bReqProcRead $nk $uh $hn $ch $tx file  ;  return 0
}

proc bReqProcRead {nk uh hn ch tx {do line} } {
	set ch [string tolower $ch]  ;  set tx [string trim $tx]
	if {[lsearch -exact $::byReq(rchan) $ch]=="-1"} {  return 0  }
	if {$::byReq(rhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
	if {$do eq "line" && $tx eq ""} {
		puthelp "$pre :Correct syntax is: $::byReq(read) <line# or handle>"
		puthelp "$pre :Example: $::byReq(read) 4"
		puthelp "$pre :Example: $::byReq(read) spike"
		puthelp "$pre :Or type $::byReq(readf) to see all pending requests."  ;  return 0
	}
	set tf $::byReq(file)
	if {![file exists $tf]} {
		puthelp "$pre :$nk: There are no pending requests."  ;  return 0
	}
	if {$do eq "line"} {  set tx [lindex [split $tx] 0]  ;  set scnt 0
		if {[string is digit -strict $tx]} {  set fline $tx  } else {  set fhand "\\\[$tx\\\] *"  }
	}
	set tid [open $tf]  ;  set lnum 0
	while {![eof $tid]} {  set line [gets $tid]
		if {$line ne ""} {  incr lnum
			if {$do eq "file"} {  puthelp "$pre :$lnum - $line"
			} elseif {[info exists fline] && $lnum==$fline} {
				puthelp "$pre :$lnum - $line"  ;  break
			} elseif {[info exists fhand] && [string match -nocase $fhand $line]} {
				puthelp "$pre :$lnum - $line"  ;  incr scnt
			}
		}
	}
	close $tid
	if {$lnum=="0"} {  puthelp "$pre :$nk: There are no pending requests."  ;  return 0  }
	if {$do eq "file"} {  puthelp "$pre :List Completed – Total Pending Requests ($lnum)."
	} elseif {[info exists fhand] && $scnt=="0"} {  puthelp "$pre :$tx has no pending requests."
	} elseif {[info exists fline] && $fline>$lnum} {  set tl request
		if {$lnum>"1"} {  set tl requests  }
		puthelp "$pre :$nk: Request number $fline doesn't exist ($lnum pending $tl)."
	}
	return 0
}

proc bReqProcDel {nk uh hn ch tx} {
	bReqProcEdit $nk $uh $hn $ch $tx del  ;  return 0
}

proc bReqProcEdit {nk uh hn ch tx {do edit} } {
	set ch [string tolower $ch]  ;  set tx [split [string trim $tx]]
	if {[lsearch -exact $::byReq(echan) $ch]=="-1"} {  return 0  }
	if {$::byReq(ehow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
	if {$do eq "edit"} {
		if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
			puthelp "$pre :Correct syntax is: $::byReq(edit) <req#> <new-message>"
			puthelp "$pre :Example: $::byReq(edit) 4 coke is not good for health."  ;  return 0
		}
	} elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
		puthelp "$pre :Correct syntax is: $::byReq(del) <req#>"
		puthelp "$pre :Example: $::byReq(del) 4"  ;  return 0
	}
	set tf $::byReq(file)
	if {![file exists $tf]} {
		puthelp "$pre :$nk: There are no pending requests."  ;  return 0
	}
	set find [lindex $tx 0]  ;  set tx [string trim [join [lrange $tx 1 end]]]
	set new [file dirname $tf]/newfile.tmp  ;  set nid [open $new w]
	set tid [open $tf]  ;  set lnum 0
	while {![eof $tid]} {  set line [gets $tid]
		if {$line ne ""} {  incr lnum
			if {$lnum==$find} {
				if {$do eq "edit"} {  set line [split $line]
					set date [lindex $line end]  ;  set hand [lindex $line 0]
					puthelp "$pre :$nk: Requests List Updated successfully."
					puts $nid "$hand $tx $date"
				} elseif {$do eq "del"} {
					puthelp "$pre :$nk: Request Done – Deleted from the list."
				}
			} else {  puts $nid $line  }
		}
	}
	close $tid
	if {$find>$lnum} {
		if {$lnum>"0"} {  set tl request
			if {$lnum>"1"} {  set tl requests  }
			puthelp "$pre :$nk: Request number $find doesn't exist ($lnum pending $tl)."
		} else {  puthelp "$pre :$nk: There are no pending requests."  }
		close $nid  ;  file delete $new
	} else {  close $nid  ;  file rename -force $new $tf  }
	return 0
}

proc bReqProcDelF {nk uh hn ch tx} {
	set ch [string tolower $ch]
	if {[lsearch -exact $::byReq(dchan) $ch]=="-1"} {  return 0  }
	if {$::byReq(dhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
	set tf $::byReq(file)
	if {![file exists $tf]} {
		puthelp "$pre :$nk: There are no pending requests."  ;  return 0
	}
	puthelp "$pre :$nk: All pending requests deleted successfully!"
	file delete $tf  ;  return 0
}

proc bReqProcUser {nk uh hn ch tx} {
	set ch [string tolower $ch]  ;  set tx [string trim $tx]
	if {[lsearch -exact $::byReq(uchan) $ch]=="-1"} {  return 0  }
	if {$::byReq(uhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
	if {$tx eq ""} {
		puthelp "$pre :Correct syntax is: $::byReq(user) <handle>"
		puthelp "$pre :Example: $::byReq(user) spike"  ;  return 0
	}
	set tx [lindex [split $tx] 0]
	if {![validuser $tx]} {
		puthelp "$pre :$nk: $tx is not a valid user handle."  ;  return 0
	}

	if {[set cmt [getuser $tx COMMENT]] eq ""} {
		puthelp "$pre :$nk: There is no comment for $tx."  ;  return 0
	}
	puthelp "$pre :$nk: $tx - $cmt"  ;  return 0
}

putlog "ByRequest.tcl Ver. 1.0 by SpiKe^^ loaded."
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

fyre wrote:In Partyline:
<(Bot> [05:49] Tcl error [bReqProcRead]: can't read "byReq(rhow)": no such variable
<(Bot> [05:49] Tcl error [bReqProcEdit]: can't read "byReq(ehow)": no such variable
<(Bot> [05:49] Tcl error [bReqProcUser]: can't read "byReq(uhow)": no such variable
<(Bot> [05:50] Tcl error [bReqProcReadF]: can't read "byReq(rhow)": no such variable
Q) When to use the "global var" statement versus referencing the variable directly in global space using $::var ?

A) When you reference it more than twice using $:: a global would've been the better choice. Yes! Because the more you reference your var with $::, you may forget once and simply use $. It's a headache and a chore to keep in check. As well as, it's slower to copy vars from the same array 3x, than to have just copied the entire array at once.

Anyways, here is a correction and yes, this version chose to global. Enjoy. All credit to Spike^^. Long live eggdrop. Dance like an robot. Beep boop beep...

Code: Select all

# ByRequest.tcl Version 1.0 (6 Feb 2013) #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #


########### General Text File Settings ###########

# Set the full route & file name of the file to edit #
# Note: The !req <message> command will attempt to make this file if needed.
set byReq(file) {/usr/home/spike/eggdrop/scripts/byreq.txt}


########### Public 'Add Request' Command Settings ###########
## settings for the public !req <message> command ##

# Set the listen channel(s) for !req <message> command #
set byReq(achan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the !req <message> command #
set byReq(aflags) {R|R}

# Set the public trigger for the !req <message> command #
# to add a request at the end of the file:
#    example:  !req I want coke.
set byReq(add) {!req}


########### Public 'Read Requests' Commands Settings ###########
## settings for the public !reqview <req#> and !reqlist commands ##

# Set the listen channel(s) for the public Read Requests commands #
set byReq(rchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read Requests commands #
set byReq(rflags) {o|o}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(rhow) "1"

# Set the public trigger for the !reqview <req#> / !reqview <handle> command #
# to read a specific request (by line number) from the text file
#    example:  !reqview 4
#    note: use to check for correct line before doing !reqedit or !reqdone
# to read all requests by <handle> from the text file
#    example:  !reqview spike
set byReq(read) {!reqview}

# Set the public trigger for the !reqlist command #
# to read all requests from the text file
#    example:  !reqlist
set byReq(readf) {!reqlist}


########### Public 'Edit/Delete Requests' Commands Settings ###########
## settings for the public !reqedit <req#> and !reqdone <req#> commands ##

# Set the listen channel(s) for the public Edit/Delete Requests commands #
set byReq(echan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Edit/Delete Requests commands #
set byReq(eflags) {m|m}

# Should these 2 commands reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(ehow) "1"

# Set the public trigger for the !reqedit <req#> <new text> command #
# to edit a specific request (by line number) in the text file
#    example:  !reqedit 4 coke is not good for health.
set byReq(edit) {!reqedit}

# Set the public trigger for the !reqdone <req#> command #
# to delete a specific request (by line number) from the text file
#    example:  !reqdone 4
#    note: this will renumber all requests after request 4!
set byReq(del) {!reqdone}


########### Public 'Delete All Requests' Command Settings ###########
## settings for the public !reqpurge command ##

# Set the listen channel(s) for the public Delete All Requests command #
set byReq(dchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Delete All Requests command #
set byReq(dflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(dhow) "1"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(delf) {!reqpurge}


########### Public 'Read User Comment' Command Settings ###########
## settings for the public !requser command ##

# Set the listen channel(s) for the public Read User Comment command #
set byReq(uchan) {#yourchannel #anotherchannel #someotherchan}

# Set the access flags to use the public Read User Comment command #
set byReq(uflags) {n|n}

# Should this command reply by Public or User Notice ?? #
#   1 = reply by public to the channel
#   2 = reply by user notice
set byReq(uhow) "2"

# Set the public trigger for the !reqpurge command #
# to delete all requests from the text file
#    example:  !reqpurge
set byReq(user) {!requser}


################ End Settings ################

bind pub $byReq(aflags) $byReq(add) bReqProcAdd
bind pub $byReq(rflags) $byReq(read) bReqProcRead
bind pub $byReq(rflags) $byReq(readf) bReqProcReadF
bind pub $byReq(eflags) $byReq(del) bReqProcDel
bind pub $byReq(eflags) $byReq(edit) bReqProcEdit
bind pub $byReq(dflags) $byReq(delf) bReqProcDelF
bind pub $byReq(uflags) $byReq(user) bReqProcUser
set byReq(achan) [split [string tolower $byReq(achan)]]
set byReq(rchan) [split [string tolower $byReq(rchan)]]
set byReq(echan) [split [string tolower $byReq(echan)]]
set byReq(dchan) [split [string tolower $byReq(dchan)]]
set byReq(uchan) [split [string tolower $byReq(uchan)]]
if {$byReq(rhow) ne "2"} {  set byReq(rhow) 1  }
if {$byReq(ehow) ne "2"} {  set byReq(ehow) 1  }
if {$byReq(dhow) ne "2"} {  set byReq(dhow) 1  }
if {$byReq(uhow) ne "2"} {  set byReq(uhow) 1  }

proc bReqProcAdd {nk uh hn ch tx} {
   global byReq
   set ch [string tolower $ch]  ;  set tx [string trim $tx]
   if {[lsearch -exact $byReq(achan) $ch]=="-1"} {  return 0  }
   if {$tx eq ""} {
      puthelp "PRIVMSG $ch :Correct syntax is: $byReq(add) <your-message-here>"
      puthelp "PRIVMSG $ch :Example: $byReq(add) I want coke."  ;  return 0
   }
   set tf $byReq(file)  ;  set ftime [clock format [unixtime] -format %D@%R]
   set id [open $tf a]  ;  puts $id "\[$hn\] $tx ($ftime)"  ;  close $id
   if {![file exists $tf]} {
      puthelp "PRIVMSG $ch :Unable to find or make text file: $tf"
   } else {  puthelp "PRIVMSG $ch :$nk: Request Accepted."  }
   return 0
}

proc bReqProcReadF {nk uh hn ch tx} {
   bReqProcRead $nk $uh $hn $ch $tx file  ;  return 0
}

proc bReqProcRead {nk uh hn ch tx {do line} } {
   global byReq
   set ch [string tolower $ch]  ;  set tx [string trim $tx]
   if {[lsearch -exact $byReq(rchan) $ch]=="-1"} {  return 0  }
   if {$byReq(rhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
   if {$do eq "line" && $tx eq ""} {
      puthelp "$pre :Correct syntax is: $byReq(read) <line# or handle>"
      puthelp "$pre :Example: $byReq(read) 4"
      puthelp "$pre :Example: $byReq(read) spike"
      puthelp "$pre :Or type $byReq(readf) to see all pending requests."  ;  return 0
   }
   set tf $byReq(file)
   if {![file exists $tf]} {
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0
   }
   if {$do eq "line"} {  set tx [lindex [split $tx] 0]  ;  set scnt 0
      if {[string is digit -strict $tx]} {  set fline $tx  } else {  set fhand "\\\[$tx\\\] *"  }
   }
   set tid [open $tf]  ;  set lnum 0
   while {![eof $tid]} {  set line [gets $tid]
      if {$line ne ""} {  incr lnum
         if {$do eq "file"} {  puthelp "$pre :$lnum - $line"
         } elseif {[info exists fline] && $lnum==$fline} {
            puthelp "$pre :$lnum - $line"  ;  break
         } elseif {[info exists fhand] && [string match -nocase $fhand $line]} {
            puthelp "$pre :$lnum - $line"  ;  incr scnt
         }
      }
   }
   close $tid
   if {$lnum=="0"} {  puthelp "$pre :$nk: There are no pending requests."  ;  return 0  }
   if {$do eq "file"} {  puthelp "$pre :List Completed - Total Pending Requests ($lnum)."
   } elseif {[info exists fhand] && $scnt=="0"} {  puthelp "$pre :$tx has no pending requests."
   } elseif {[info exists fline] && $fline>$lnum} {  set tl request
      if {$lnum>"1"} {  set tl requests  }
      puthelp "$pre :$nk: Request number $fline doesn't exist ($lnum pending $tl)."
   }
   return 0
}

proc bReqProcDel {nk uh hn ch tx} {
   bReqProcEdit $nk $uh $hn $ch $tx del  ;  return 0
}

proc bReqProcEdit {nk uh hn ch tx {do edit} } {
   global byReq
   set ch [string tolower $ch]  ;  set tx [split [string trim $tx]]
   if {[lsearch -exact $byReq(echan) $ch]=="-1"} {  return 0  }
   if {$byReq(ehow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
   if {$do eq "edit"} {
      if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
         puthelp "$pre :Correct syntax is: $byReq(edit) <req#> <new-message>"
         puthelp "$pre :Example: $byReq(edit) 4 coke is not good for health."  ;  return 0
      }
   } elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
      puthelp "$pre :Correct syntax is: $byReq(del) <req#>"
      puthelp "$pre :Example: $byReq(del) 4"  ;  return 0
   }
   set tf $byReq(file)
   if {![file exists $tf]} {
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0
   }
   set find [lindex $tx 0]  ;  set tx [string trim [join [lrange $tx 1 end]]]
   set new [file dirname $tf]/newfile.tmp  ;  set nid [open $new w]
   set tid [open $tf]  ;  set lnum 0
   while {![eof $tid]} {  set line [gets $tid]
      if {$line ne ""} {  incr lnum
         if {$lnum==$find} {
            if {$do eq "edit"} {  set line [split $line]
               set date [lindex $line end]  ;  set hand [lindex $line 0]
               puthelp "$pre :$nk: Requests List Updated successfully."
               puts $nid "$hand $tx $date"
            } elseif {$do eq "del"} {
               puthelp "$pre :$nk: Request Done - Deleted from the list."
            }
         } else {  puts $nid $line  }
      }
   }
   close $tid
   if {$find>$lnum} {
      if {$lnum>"0"} {  set tl request
         if {$lnum>"1"} {  set tl requests  }
         puthelp "$pre :$nk: Request number $find doesn't exist ($lnum pending $tl)."
      } else {  puthelp "$pre :$nk: There are no pending requests."  }
      close $nid  ;  file delete $new
   } else {  close $nid  ;  file rename -force $new $tf  }
   return 0
}

proc bReqProcDelF {nk uh hn ch tx} {
   global byReq
   set ch [string tolower $ch]
   if {[lsearch -exact $byReq(dchan) $ch]=="-1"} {  return 0  }
   if {$byReq(dhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
   set tf $byReq(file)
   if {![file exists $tf]} {
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0
   }
   puthelp "$pre :$nk: All pending requests deleted successfully!"
   file delete $tf  ;  return 0
}

proc bReqProcUser {nk uh hn ch tx} {
   global byReq
   set ch [string tolower $ch]  ;  set tx [string trim $tx]
   if {[lsearch -exact $byReq(uchan) $ch]=="-1"} {  return 0  }
   if {$byReq(uhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  }
   if {$tx eq ""} {
      puthelp "$pre :Correct syntax is: $byReq(user) <handle>"
      puthelp "$pre :Example: $byReq(user) spike"  ;  return 0
   }
   set tx [lindex [split $tx] 0]
   if {![validuser $tx]} {
      puthelp "$pre :$nk: $tx is not a valid user handle."  ;  return 0
   }

   if {[set cmt [getuser $tx COMMENT]] eq ""} {
      puthelp "$pre :$nk: There is no comment for $tx."  ;  return 0
   }
   puthelp "$pre :$nk: $tx - $cmt"  ;  return 0
}

putlog "ByRequest.tcl Ver. 1.0 by SpiKe^^ loaded." 
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

Thanks to all for helping me, and sorry for my late reply as I am traveling now a days still not at home but I've checked this one and it works awesome... :)
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

I facing some strange problem which I observed couple of days ago.
Using this script bot does not respond to pub commands unless I do partyline access.

Second thing How it respond to pub command without partyline?

I've added 2 channels #abc & #xyz on the bot, but when I tried to use !req on #abc so it doesnt respond and after that when I tried to use !req in #xyz it respond to it and eventually it start responding on channel #abc again, why?

When both the channels are added and it its responding to 1 channel, why not responding to 2 channel?

Note: If you are connected to partyline, then no issues.. its working fine, and I am using the latest version of eggdrop.

Thanks.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

The script has no code that would tie any of it's commands to anything having to do with partyline access at all!!

Replying (or not) to any of the commands created by the script are controlled only by the userfile flags for a user.

Seems to me the bot isn't replying to a user because they either don't have the required flags,
or they don't match any of the current masks for an allowed user in the bot's userfile.

Each command in the script has it's own allowed flags setting,
make sure each user you wish to use the commands has the correct user file flags for those commands.
They will also need a host mask that will match their current nick!user@host info, or the bot will not respond to them.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

Bro,
You didn't get my point.
Bot respond to #channel1 but after pub command triggered in #channel2

If flags are not properly added then bot shouldn't respond in any channel either #channel1 or #channel2

Just have a test at your end and see if it works.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I will load the script and do some testing but...
Each command in the script also has a 'listen channel(s)' setting,
to control what channels are active for each command.
You MUST set the active 'listen channel(s)' for EACH of the commands in the script!
There are 5 different 'listen channel(s)' settings in the script set up,
All of them need to be set to the channels you wish the script to monitor for the corresponding commands.

Are you setting the userfile flags for users as global or channel specific?
If setting channel specific flags for users,
maybe they don't have the channel specific flag required to use the command in #channel2.

I will load and test the script to see how it works from here, and make another post with my results.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

Sure, load the script and join 3/4 channels and leave the bot idle for aprox 20-30mins. Then try using pub commands without doing partyline.

PS: I also sent you PM, have a look.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I loaded and fully tested the script, again.
The script is fully working as expected, no problems encountered, in any of the set channels.

Your problems with the script have to be related to your bot's uesrfile.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Here's an updated version of the script with "Public 'Set User Comment' Command" added...

Code: Select all

# ByRequest.tcl Version 1.1 (24 Mar 2013) # 

# author:  SpiKe^^ # 
# e-mail:  spike<at>mytclscripts<dot>com # 
# webpage: http://mytclscripts.com/ # 

# This file is Copyrighted under the GNU Public License. # 
# http://www.gnu.org/copyleft/gpl.html # 


########### General Text File Settings ########### 

# Set the full route & file name of the file to edit # 
# Note: The !req <message> command will attempt to make this file if needed. 
set byReq(file) {/usr/home/spike/eggdrop/scripts/byreq.txt} 


########### Public 'Add Request' Command Settings ########### 
## settings for the public !req <message> command ## 

# Set the listen channel(s) for !req <message> command # 
set byReq(achan) {#yourchannel #anotherchannel #someotherchan} 

# Set the access flags to use the !req <message> command # 
set byReq(aflags) {R|R} 

# Set the public trigger for the !req <message> command # 
# to add a request at the end of the file: 
#    example:  !req I want coke. 
set byReq(add) {!req} 


########### Public 'Read Requests' Commands Settings ########### 
## settings for the public !reqview <req#> and !reqlist commands ## 

# Set the listen channel(s) for the public Read Requests commands # 
set byReq(rchan) {#yourchannel #anotherchannel #someotherchan} 

# Set the access flags to use the public Read Requests commands # 
set byReq(rflags) {o|o} 

# Should these 2 commands reply by Public or User Notice ?? # 
#   1 = reply by public to the channel 
#   2 = reply by user notice 
set byReq(rhow) "1" 

# Set the public trigger for the !reqview <req#> / !reqview <handle> command # 
# to read a specific request (by line number) from the text file 
#    example:  !reqview 4 
#    note: use to check for correct line before doing !reqedit or !reqdone 
# to read all requests by <handle> from the text file 
#    example:  !reqview spike 
set byReq(read) {!reqview} 

# Set the public trigger for the !reqlist command # 
# to read all requests from the text file 
#    example:  !reqlist 
set byReq(readf) {!reqlist} 


########### Public 'Edit/Delete Requests' Commands Settings ########### 
## settings for the public !reqedit <req#> and !reqdone <req#> commands ## 

# Set the listen channel(s) for the public Edit/Delete Requests commands # 
set byReq(echan) {#yourchannel #anotherchannel #someotherchan} 

# Set the access flags to use the public Edit/Delete Requests commands # 
set byReq(eflags) {m|m} 

# Should these 2 commands reply by Public or User Notice ?? # 
#   1 = reply by public to the channel 
#   2 = reply by user notice 
set byReq(ehow) "1" 

# Set the public trigger for the !reqedit <req#> <new text> command # 
# to edit a specific request (by line number) in the text file 
#    example:  !reqedit 4 coke is not good for health. 
set byReq(edit) {!reqedit} 

# Set the public trigger for the !reqdone <req#> command # 
# to delete a specific request (by line number) from the text file 
#    example:  !reqdone 4 
#    note: this will renumber all requests after request 4! 
set byReq(del) {!reqdone} 


########### Public 'Delete All Requests' Command Settings ########### 
## settings for the public !reqpurge command ## 

# Set the listen channel(s) for the public Delete All Requests command # 
set byReq(dchan) {#yourchannel #anotherchannel #someotherchan} 

# Set the access flags to use the public Delete All Requests command # 
set byReq(dflags) {n|n} 

# Should this command reply by Public or User Notice ?? # 
#   1 = reply by public to the channel 
#   2 = reply by user notice 
set byReq(dhow) "1" 

# Set the public trigger for the !reqpurge command # 
# to delete all requests from the text file 
#    example:  !reqpurge 
set byReq(delf) {!reqpurge} 


########### Public 'Set/Read User Comment' Commands Settings ########### 
## settings for the public !userlink and !requser commands ## 

# Set the listen channel(s) for the public Set/Read User Comment commands # 
set byReq(uchan) {#yourchannel #anotherchannel #someotherchan} 

# Set the access flags to use the public Set/Read User Comment commands # 
set byReq(uflags) {n|n} 

# Should these 2 commands reply by Public or User Notice ?? # 
#   1 = reply by public to the channel 
#   2 = reply by user notice 
set byReq(uhow) "2" 

# Set the public trigger for the !userlink command # 
# to set the comment field for a handle in the bot's user file 
#    example:  !userlink spike www.mytclscripts.com
set byReq(setc) {!userlink} 

# Set the public trigger for the !requser command # 
# to read the comment field for a handle in the bot's user file 
#    example:  !requser spike 
set byReq(user) {!requser} 


################ End Settings ################ 

bind pub $byReq(aflags) $byReq(add) bReqProcAdd 
bind pub $byReq(rflags) $byReq(read) bReqProcRead 
bind pub $byReq(rflags) $byReq(readf) bReqProcReadF 
bind pub $byReq(eflags) $byReq(del) bReqProcDel 
bind pub $byReq(eflags) $byReq(edit) bReqProcEdit 
bind pub $byReq(dflags) $byReq(delf) bReqProcDelF 
bind pub $byReq(uflags) $byReq(setc) bReqProcUserS 
bind pub $byReq(uflags) $byReq(user) bReqProcUser 
set byReq(achan) [split [string tolower $byReq(achan)]] 
set byReq(rchan) [split [string tolower $byReq(rchan)]] 
set byReq(echan) [split [string tolower $byReq(echan)]] 
set byReq(dchan) [split [string tolower $byReq(dchan)]] 
set byReq(uchan) [split [string tolower $byReq(uchan)]] 
if {$byReq(rhow) ne "2"} {  set byReq(rhow) 1  } 
if {$byReq(ehow) ne "2"} {  set byReq(ehow) 1  } 
if {$byReq(dhow) ne "2"} {  set byReq(dhow) 1  } 
if {$byReq(uhow) ne "2"} {  set byReq(uhow) 1  } 

proc bReqProcAdd {nk uh hn ch tx} { 
   global byReq 
   set ch [string tolower $ch]  ;  set tx [string trim $tx] 
   if {[lsearch -exact $byReq(achan) $ch]=="-1"} {  return 0  } 
   if {$tx eq ""} { 
      puthelp "PRIVMSG $ch :Correct syntax is: $byReq(add) <your-message-here>" 
      puthelp "PRIVMSG $ch :Example: $byReq(add) I want coke."  ;  return 0 
   } 
   set tf $byReq(file)  ;  set ftime [clock format [unixtime] -format %D@%R] 
   set id [open $tf a]  ;  puts $id "\[$hn\] $tx ($ftime)"  ;  close $id 
   if {![file exists $tf]} { 
      puthelp "PRIVMSG $ch :Unable to find or make text file: $tf" 
   } else {  puthelp "PRIVMSG $ch :$nk: Request Accepted."  } 
   return 0 
} 

proc bReqProcReadF {nk uh hn ch tx} { 
   bReqProcRead $nk $uh $hn $ch $tx file  ;  return 0 
} 

proc bReqProcRead {nk uh hn ch tx {do line} } { 
   global byReq 
   set ch [string tolower $ch]  ;  set tx [string trim $tx] 
   if {[lsearch -exact $byReq(rchan) $ch]=="-1"} {  return 0  } 
   if {$byReq(rhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  } 
   if {$do eq "line" && $tx eq ""} { 
      puthelp "$pre :Correct syntax is: $byReq(read) <line# or handle>" 
      puthelp "$pre :Example: $byReq(read) 4" 
      puthelp "$pre :Example: $byReq(read) spike" 
      puthelp "$pre :Or type $byReq(readf) to see all pending requests."  ;  return 0 
   } 
   set tf $byReq(file) 
   if {![file exists $tf]} { 
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0 
   } 
   if {$do eq "line"} {  set tx [lindex [split $tx] 0]  ;  set scnt 0 
      if {[string is digit -strict $tx]} {  set fline $tx  } else {  set fhand "\\\[$tx\\\] *"  } 
   } 
   set tid [open $tf]  ;  set lnum 0 
   while {![eof $tid]} {  set line [gets $tid] 
      if {$line ne ""} {  incr lnum 
         if {$do eq "file"} {  puthelp "$pre :$lnum - $line" 
         } elseif {[info exists fline] && $lnum==$fline} { 
            puthelp "$pre :$lnum - $line"  ;  break 
         } elseif {[info exists fhand] && [string match -nocase $fhand $line]} { 
            puthelp "$pre :$lnum - $line"  ;  incr scnt 
         } 
      } 
   } 
   close $tid 
   if {$lnum=="0"} {  puthelp "$pre :$nk: There are no pending requests."  ;  return 0  } 
   if {$do eq "file"} {  puthelp "$pre :List Completed - Total Pending Requests ($lnum)." 
   } elseif {[info exists fhand] && $scnt=="0"} {  puthelp "$pre :$tx has no pending requests." 
   } elseif {[info exists fline] && $fline>$lnum} {  set tl request 
      if {$lnum>"1"} {  set tl requests  } 
      puthelp "$pre :$nk: Request number $fline doesn't exist ($lnum pending $tl)." 
   } 
   return 0 
} 

proc bReqProcDel {nk uh hn ch tx} { 
   bReqProcEdit $nk $uh $hn $ch $tx del  ;  return 0 
} 

proc bReqProcEdit {nk uh hn ch tx {do edit} } { 
   global byReq 
   set ch [string tolower $ch]  ;  set tx [split [string trim $tx]] 
   if {[lsearch -exact $byReq(echan) $ch]=="-1"} {  return 0  } 
   if {$byReq(ehow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  } 
   if {$do eq "edit"} { 
      if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} { 
         puthelp "$pre :Correct syntax is: $byReq(edit) <req#> <new-message>" 
         puthelp "$pre :Example: $byReq(edit) 4 coke is not good for health."  ;  return 0 
      } 
   } elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} { 
      puthelp "$pre :Correct syntax is: $byReq(del) <req#>" 
      puthelp "$pre :Example: $byReq(del) 4"  ;  return 0 
   } 
   set tf $byReq(file) 
   if {![file exists $tf]} { 
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0 
   } 
   set find [lindex $tx 0]  ;  set tx [string trim [join [lrange $tx 1 end]]] 
   set new [file dirname $tf]/newfile.tmp  ;  set nid [open $new w] 
   set tid [open $tf]  ;  set lnum 0 
   while {![eof $tid]} {  set line [gets $tid] 
      if {$line ne ""} {  incr lnum 
         if {$lnum==$find} { 
            if {$do eq "edit"} {  set line [split $line] 
               set date [lindex $line end]  ;  set hand [lindex $line 0] 
               puthelp "$pre :$nk: Requests List Updated successfully." 
               puts $nid "$hand $tx $date" 
            } elseif {$do eq "del"} { 
               puthelp "$pre :$nk: Request Done - Deleted from the list." 
            } 
         } else {  puts $nid $line  } 
      } 
   } 
   close $tid 
   if {$find>$lnum} { 
      if {$lnum>"0"} {  set tl request 
         if {$lnum>"1"} {  set tl requests  } 
         puthelp "$pre :$nk: Request number $find doesn't exist ($lnum pending $tl)." 
      } else {  puthelp "$pre :$nk: There are no pending requests."  } 
      close $nid  ;  file delete $new 
   } else {  close $nid  ;  file rename -force $new $tf  } 
   return 0 
} 

proc bReqProcDelF {nk uh hn ch tx} { 
   global byReq 
   set ch [string tolower $ch] 
   if {[lsearch -exact $byReq(dchan) $ch]=="-1"} {  return 0  } 
   if {$byReq(dhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  } 
   set tf $byReq(file) 
   if {![file exists $tf]} { 
      puthelp "$pre :$nk: There are no pending requests."  ;  return 0 
   } 
   puthelp "$pre :$nk: All pending requests deleted successfully!" 
   file delete $tf  ;  return 0 
} 

proc bReqProcUserS {nk uh hn ch tx} { 
   bReqProcUser $nk $uh $hn $ch $tx setc  ;  return 0 
} 

proc bReqProcUser {nk uh hn ch tx {do getc} } { 
   global byReq 
   set ch [string tolower $ch]  ;  set tx [string trim $tx] 
   if {[lsearch -exact $byReq(uchan) $ch]=="-1"} {  return 0  } 
   if {$byReq(uhow)=="2"} {  set pre "NOTICE $nk"  } else {  set pre "PRIVMSG $ch"  } 
   if {$tx eq ""} { 
      if {$do eq "getc"} {  set cmd $byReq(user)  ;  set mor ""  ;  set mo2 ""
      } else { set cmd $byReq(setc) ;set mor " <new-comment>" ;set mo2 " www.mytclscripts.com" }
      puthelp "$pre :Correct syntax is: $cmd <handle>$mor" 
      puthelp "$pre :Example: $cmd spike$mo2"  ;  return 0 
   }
   set rest [join [lrange [split $tx] 1 end]]
   set tx [lindex [split $tx] 0] 
   if {![validuser $tx]} { 
      puthelp "$pre :$nk: $tx is not a valid user handle."  ;  return 0 
   } 
   if {$do eq "setc"} {
      setuser $tx COMMENT $rest
      puthelp "$pre :$nk: Comment for $tx set to: $rest"  ;  return 0 
   } 
   if {[set cmt [getuser $tx COMMENT]] eq ""} { 
      puthelp "$pre :$nk: There is no comment for $tx."  ;  return 0 
   } 
   puthelp "$pre :$nk: $tx - $cmt"  ;  return 0 
} 

putlog "ByRequest.tcl Ver. 1.1 by SpiKe^^ loaded." 

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply