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.

Todo-list

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
m
maniak
Voice
Posts: 3
Joined: Fri Jul 24, 2015 4:19 pm

Todo-list

Post by maniak »

Hello people,

I have been looking for a simple todo-list script. But havent found anything.

Im thinking commands should be something like this:

!todo add
!todo del
!todo

!todo add Upgrade server to 1.1 (adds this to the todo-list)
!todo del Upgrade server to 1.1 (removes this from the todo-list)
!todo (announces all things added to the todo-list with what date its added)

Examples:

!todo add Updgrade server to 1.1
<Botnick> Upgrade server to 1.1 added to list

!todo del Upgrade server to 1.1
<Botnick> Upgrade server to 1.1 removed from list

!todo
<Botnick> --- Things to do ---
<Botnick> [2015-05-22] Upgrade server to 1.1
<Botnick> [2015-06-10] Fix auto-op
<Botnick> [2015-07-24] Fix new cool script
--- End of List ---

Something like that. Is there any script you know about that works similar to this? Or is this maybe something you could create?

Please tell me if anything is unclear or if you have any good ideas for this.

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

Post by SpiKe^^ »

Untested modification of my script at: http://forum.egghelp.org/viewtopic.php?t=19179

Please test and see what we have so far:)

Code: Select all

# EditTextFile (ToDo-List ver) Version 0.4 #

# 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 Script Settings ###########

# Set the channel(s) for this script to run in #
set eTxFile(chan) {#yourchannel #anotherchannel #someotherchan}

# Set the full route & file name of the ToDo-List file #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}

# Set the access flags to use the ToDo-List public commands #
set eTxFile(flags) {o|o}

########### Public Command Trigger ###########

# Set the public trigger for all the ToDo-List commands #
#    note: All ToDo-List commands start with this one word!
set eTxFile(cmd) {!todo}

########### Public Command Options ###########

# Set the command option for the add line command #
# to add a line at the end of the file: 
#    example:  !todo add The text to add at file end.
#    example:  !todo add end The text to add at file end.
# to add a line at a specific line position in the file:
#    example:  !todo add 4 The text to add at file line 4.
#    note: this will renumber the original line 4 & all lines after it!
set eTxFile(add) {add}

# Set the command option for the delete line command #
# to delete a specific line (by line number) from the text file
#    example:  !todo del 4
#    note: this will renumber all lines after line 4!
set eTxFile(del) {del}


# Set the command option for the list file command #
# to list all lines from the text file
#    example:  !todo list
# note: list is also the default if no command option is given!
#    example:  !todo
set eTxFile(list) {list}

########### Extended Command Options ###########

# Set the command option for the read line command #
# to read a specific line (by line number) from the text file
#    example:  !todo read 4
#    note: use to check for correct line before doing !todo del or edit
set eTxFile(read) {read}

# Set the command option for the edit line command #
# to edit a specific line (by line number) in the text file
#    example:  !todo edit 4 New text to replace file line 4.
set eTxFile(edit) {edit}

# Set the command option to get help with this script #
# to see all valid ToDo-List command options
#    example:  !todo help
set eTxFile(help) {help}


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


bind pub $eTxFile(flags) $eTxFile(cmd) etfProcCmd

set eTxFile(chan) [split $eTxFile(chan)]

proc etfProcCmd {nk uh hn ch tx} {
  global eTxFile
  if {[lsearch -nocase $eTxFile(chan) $ch]=="-1"} {  return 0  }

  set tx [split [string trim $tx]]
  set opt [lindex $tx 0]
  set tx [string trim [join [lrange $tx 1 end]]]

  if {$opt eq $eTxFile(add)} {
    etfProcAdd $nk $ch $tx
  } elseif {$opt eq $eTxFile(del)} {
    etfProcEdit $nk $ch $tx del
  } elseif {$opt eq "" || $opt eq $eTxFile(list)} {
    etfProcRead $nk $ch $tx file
  } elseif {$opt eq $eTxFile(read)} {
    etfProcRead $nk $ch $tx
  } elseif {$opt eq $eTxFile(edit)} {
    etfProcEdit $nk $ch $tx

  } else {
    if {$opt eq $eTxFile(help)} {
      puthelp "PRIVMSG $ch :--- ToDo-List script help ---"
    } else {
      puthelp "PRIVMSG $ch :Invalid ToDo-List command option: $opt"
    }

    puthelp "PRIVMSG $ch :Valid options for $eTxFile(cmd): \
             $eTxFile(add), $eTxFile(del), $eTxFile(list),\
             $eTxFile(read), $eTxFile(edit), $eTxFile(help)"

    puthelp "PRIVMSG $ch :To get help for an option, use it without arguments."
    puthelp "PRIVMSG $ch :Example: $eTxFile(cmd) $eTxFile(add)"
    puthelp "PRIVMSG $ch :Example: $eTxFile(cmd) $eTxFile(del)"
  }

  return 0

}

proc etfProcAdd {nk ch tx} {

  set tx [split $tx]

  if {[lindex $tx 0] eq "end" || [string is digit -strict [lindex $tx 0]]} {
    set addat [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
  } else {  set addat end  ;  set tx [join $tx]  }

  if {$tx eq ""} {  set add "$::eTxFile(cmd) $::eTxFile(add)"
    puthelp "PRIVMSG $ch :Correct syntax is: $add \[position\] <text to add>"
    puthelp "PRIVMSG $ch :Example: $add Text to add at end of the list."
    puthelp "PRIVMSG $ch :Example: $add end Text to add at end of the list."
    puthelp "PRIVMSG $ch :Example: $add 4 Text to add at list line 4."
    return
  }

  set tf $::eTxFile(file)
  if {![file exists $tf]} {  set addat end  ;  set nofile 1  }
  if {$addat ne "end"} {  set tx "$addat $tx"
    etfProcEdit $nk $ch $tx add  ;  return
  }
  set id [open $tf a]  ;  puts $id $tx  ;  close $id
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Unable to find or make ToDo text file: $tf"
  } elseif {[info exists nofile]} {
    puthelp "PRIVMSG $ch :Added line to new ToDo-List: $tx"
  } else {
    puthelp "PRIVMSG $ch :Added line at end of ToDo-List: $tx"
  }
  return
}


proc etfProcRead {nk ch tx {do line} } {

  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :ToDo-List is currently empty."  ;  return
  }

  if {$do eq "line" && ![string is digit -strict $tx]} {
    set read "$::eTxFile(cmd) $::eTxFile(read)"
    puthelp "PRIVMSG $ch :Correct syntax is: $read <line#>"
    puthelp "PRIVMSG $ch :Example: $read 4"
    return
  }

  set tid [open $tf]  ;  set lnum 0
  while {![eof $tid]} {  set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$do eq "file"} {  puthelp "PRIVMSG $ch :\[$lnum\]  $line"
      } elseif {$lnum==$tx} {
        puthelp "PRIVMSG $ch :\[$lnum\]  $line"  ;  break
      }
    }
  }
  close $tid
  if {$lnum=="0"} {
    puthelp "PRIVMSG $ch :ToDo-List is currently empty." ;  return
  }
  if {$do eq "line" && $tx>$lnum} {  set tl line
    if {$lnum>"1"} {  set tl lines  }
    puthelp "PRIVMSG $ch :List line $tx doesn't exist ($lnum $tl in the list)"
  }
  return
}


proc etfProcEdit {nk ch tx {do edit} } {

  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :ToDo-List is currently empty."  ;  return
  }

  set tx [split $tx]
  if {$do eq "edit"} {
    if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
      set edit "$::eTxFile(cmd) $::eTxFile(edit)"
      puthelp "PRIVMSG $ch :Correct syntax is: $edit <line#> <new edited text>"
      puthelp "PRIVMSG $ch :Example: $edit 4 New text to replace list line 4."
      return
    }
  } elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
    set del "$::eTxFile(cmd) $::eTxFile(del)"
    puthelp "PRIVMSG $ch :Correct syntax is: $del <line#>"
    puthelp "PRIVMSG $ch :Example: $del 4"  ;  return
  }

  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"} {
          puthelp "PRIVMSG $ch :Replaced line $lnum text: $line"
          puthelp "PRIVMSG $ch :with the new text line: $tx"
          puts $nid $tx
        } elseif {$do eq "del"} {
          puthelp "PRIVMSG $ch :Deleted line $lnum text: $line"
        } elseif {$do eq "add"} {
          puthelp "PRIVMSG $ch :Added new line $lnum text: $tx"
          puts $nid $tx  ;  puts $nid $line
        }
      } else {  puts $nid $line  }
    }
  }
  close $tid
  if {$find>$lnum} {
    if {$do eq "add"} {  incr lnum
      puthelp "PRIVMSG $ch :Added new line $lnum text: $tx"
      puts $nid $tx  ;  close $nid  ;  file rename -force $new $tf
    } else {
      if {$lnum>"0"} {  set tl line
        if {$lnum>"1"} {  set tl lines  }
        puthelp "PRIVMSG $ch :List line $find doesn't exist ($lnum $tl in the list)"
      } else {  puthelp "PRIVMSG $ch :ToDo-List is currently empty."  }
      close $nid  ;  file delete $new
    }
  } else {  close $nid  ;  file rename -force $new $tf  }
  return
}

putlog "EditTextFile (ToDo-List ver) Ver. 0.4 by SpiKe^^ loaded."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
m
maniak
Voice
Posts: 3
Joined: Fri Jul 24, 2015 4:19 pm

Post by maniak »

Alright, thanks! Ill check it out!
c
crymsun
Voice
Posts: 33
Joined: Tue Nov 13, 2018 8:24 pm

Post by crymsun »

This is a fantastic script...

One question... it indicates o as the access flag - but on testing, looks like just the owner can activate the todo commands. None of the other Ops can.

How do I change that so all Ops can activate the list?
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You mean channel operators that may not have access to your bot?
Once the game is over, the king and the pawn go back in the same box.
c
crymsun
Voice
Posts: 33
Joined: Tue Nov 13, 2018 8:24 pm

Post by crymsun »

Yes - in terms of IRC chan Ops, of which there are several different types, depending on the network.
Post Reply