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 

Dinfo script. Latest version v1.1.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
lee8oi
Halfop


Joined: 04 Jun 2011
Posts: 63
Location: Michigan,United States.

PostPosted: Mon Jun 27, 2011 10:08 pm    Post subject: Dinfo script. Latest version v1.1. Reply with quote

Dinfo script is the first 'graduate' from the dukescripts volatile experiment. This script is simply an info script. Similar to what 'factoids' are in supybot or 'egglearn' for eggdrop. The public '.info' command has list and retrieval capabilities while the dcc/partyline command '.dinfo' allows owners to add, remove, list info entries as well as backup and restore the info database to/from file.

Latest version available from github at: https://github.com/lee8oi/dinfo/blob/master/dinfo.tcl

Code for v1.0:
_________________
https://github.com/lee8oi
https://code.google.com/u/lee8oi/


Last edited by lee8oi on Tue Sep 27, 2011 12:32 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
lee8oi
Halfop


Joined: 04 Jun 2011
Posts: 63
Location: Michigan,United States.

PostPosted: Wed Jun 29, 2011 1:11 pm    Post subject: Dinfo script. Update release v1.1 Reply with quote

Heres v1.1 with a couple minor updates.
Code:

namespace eval dinfo {
################################################################################
#   Copyright ©2011 lee8oi@gmail.com
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   http://www.gnu.org/licenses/
#
################################################################################
#
#   Dinfo script v1.1 (6-27-11)
#   by: <lee8oi@github><lee8oiOnfreenode>
#   github link: https://github.com/lee8oi/eggdrop/blob/master/dinfo.tcl
#
#   Dinfo script is the first 'graduate' from the dukescript volatile
#   experiment. This script is simply an info script. Similar to what 'factoids'
#   are in supybot or 'egglearn' for eggdrop. The public '.info' command has
#   list and retrieval capabilities while the dcc/partyline command '.dinfo'
#   allows owners to add, remove, list info entries as well as backup and
#   restore the info database to/from file.
#
#   Initial channel setup:
#   (enables use of public info command in specified channel)
#    .chanset #channel +dinfo
#
#   Public command syntax:
#    .info ?list|help|<text>?
#
#   DCC (partyline) command syntax:
#    .dinfo ?backup|restore|add|remove|list? ?args?
#
#   Example Usage:
#    (public)
#        <lee8oi> .info
#    <dukelovett> Usage: .info ?list|help|<text>?
#        <lee8oi> .info version
#    <dukelovett> version: dinfo 1.0 by lee8oi@github.
#        <lee8oi> .info list
#    <dukelovett> Info Available: help, version, lee8oi
#        <lee8oi> .info lee8oi
#    <dukelovett> lee8oi: The king of dukelovett.org.
#
#    (console)
#        lee8oi .dinfo
#    dukelovett ~dinfo~ Usage: .dinfo ?backup|restore|add|remove? ?text?
#        lee8oi .dinfo backup
#    dukelovett dinfodb saved.
#        lee8oi .dinfo restore
#    dukelovett dinfodb restored.
#        lee8oi .dinfo add test Just a test info entry.
#    dukelovett ~dinfo~ Info item added.
#        lee8oi .dinfo test
#    dukelovett test: Just a test info entry.
#
#
# Updates:
#   v1.1
#       1. Removed lingering '.hi' command that was left in the code when script
#       graduated from Dukescript Volatile Experiment.
#       2. Added ::dinfo:: namespace.
#       3. Fixed script version references to use variable.
#
################################################################################
#   Experts only below this line.
################################################################################
    variable ver "1.1"
    set ::dinfo::dinfodb(version) "Dinfo $ver by lee8oi@github."
    if {[file exist "scripts/dinfodb.tcl"]} {
        source scripts/dinfodb.tcl
    }
}
bind pubm - * ::dinfo::pub_handler
bind dcc n dinfo ::dinfo::dcc_proc
setudef flag dinfo
namespace eval dinfo {   
    proc restoredb {args} {
        # restore from file
        variable ::dinfo::dinfodb
        source scripts/dinfodb.tcl
    }
    proc backupdb {args} {
        # backup dinfodb to file.
        variable ::dinfo::dinfodb
        set fs [open "scripts/dinfodb.tcl" w+]
        # write variable lines for loading namespace vars.
        # create 'array set' lines using array data.
        puts $fs "variable ::dinfo::dinfodb"
        puts $fs "array set dinfodb [list [array get dinfodb]]"
        close $fs;
    }
    proc dcc_proc {handle idx text} {
        # dcc/partyline command
        variable ::dinfo::dinfodb
        variable ::dinfo::ver
        set textarr [split $text]
        set text [string tolower [lindex $textarr 0]]
        switch $text {
            "" {
                # show help.
                putdcc $idx "~dinfo $ver~ Usage: .dinfo ?backup|restore|add|remove? ?args?"
            }
            "backup" {
                # run backup procedure.
                ::dinfo::backupdb
                putdcc $idx "dinfodb saved."
            }
            "restore" {
                # run restore procedure.
                ::dinfo::restoredb
                putdcc $idx "dinfodb restored."
            }
            "add" {
                # add a new info entry.
                set second [lindex $textarr 1]
                set value [lrange $textarr 2 end]
                if {$second != "" && $value != ""} {
                    set dinfodb($second) $value
                    ::dinfo::backupdb
                    putdcc $idx "~dinfo~ Info item added."
                } else {
                    putdcc $idx "~dinfo $ver~ Usage: .dinfo add <name> <text>"
                }
            }
            "remove" {
                # remove info entry
                set second [lindex $textarr 1]
                if {$second != ""} {
                    if {[info exists dinfodb($second)]} {
                        unset dinfodb($second)
                        ::dinfo::backupdb
                        putdcc $idx "~dinfo~ Info item removed."
                    }
                } else {
                    putdcc $idx "~dinfo $ver~ Usage: .dinfo remove <name>"
                } 
            }
            "list" {
                # list existing info entries names.
                set arrayvar ""
                foreach {name value} [array get dinfodb] {
                    lappend arrayvar $name
                }
                #set stringvar [join $arrayvar]
                set cleanvar [regsub -all {[ \t]+} $arrayvar {, }]
                putdcc $idx "Info Available: $cleanvar"
            }
            default {
                # value isn't part of command. Do search.
                set first [lindex $textarr 0]
                if {[info exists dinfodb($first)]} {
                    putdcc $idx "$first: $dinfodb($first)"
                } else {
                    putdcc $idx "Info not available."
                }
            }
        }   
    }
    proc pub_handler {nick userhost handle channel text} {
        if {[channel get $channel dinfo]} {
            variable ::dinfo::ver
            set textarr [split $text]
            set first [string tolower [lindex $textarr 0]]
            switch $first {
                ".info" {
                    variable ::dinfo::dinfodb
                    set second [lindex $textarr 1]
                    if {$second != ""} {
                        switch $second {
                            "list" {
                                # list existing info entries names.
                                set arrayvar ""
                                foreach {name value} [array get dinfodb] {
                                    lappend arrayvar $name
                                }
                                #set stringvar [join $arrayvar]
                                set cleanvar [regsub -all {[ \t]+} $arrayvar {, }]
                                putserv "PRIVMSG $channel :Info Available: $cleanvar"
                            }
                            default {
                                # value isn't part of command. Do search.
                                if {[info exists dinfodb($second)]} {
                                    putserv "PRIVMSG $channel :${second}: $dinfodb($second)"
                                } else {
                                    putserv "PRIVMSG $channel :Info not available."
                                }
                            }
                        }
                    } else {
                        putserv "PRIVMSG $channel :~dinfo $ver~ Usage: .info ?list|help|<text>?"
                    }
                }
            }
        }
    }
}
putlog "Dinfo script [set ::dinfo::ver] Loaded."

_________________
https://github.com/lee8oi
https://code.google.com/u/lee8oi/
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
lee8oi
Halfop


Joined: 04 Jun 2011
Posts: 63
Location: Michigan,United States.

PostPosted: Tue Sep 27, 2011 12:33 pm    Post subject: minor update Reply with quote

Script has been moved to its own repository. New github link is: https://github.com/lee8oi/dinfo/blob/master/dinfo.tcl
_________________
https://github.com/lee8oi
https://code.google.com/u/lee8oi/
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases 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