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.

Public note script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
SignZ
Voice
Posts: 18
Joined: Thu Jun 17, 2010 3:52 pm

Public note script

Post by SignZ »

Hello ladies and gentlemen, today I come to you to request a public note script.
It should use channel commands (well, only one command -> .note $nick $text) and tell $nick the note as soon as he either joins the channel or says something.
The only note scripts I have found either use the partyline or a query-based system.
I'd like the output to be something like "$nick: $othernick left a note $time ago: $text" where $nick is the target and $othernick is the one who left the note. (for example: "SignZ: randomguy left a note 1 hour, 52 minutes ago: this is a note")
I hope you guys can help me with this request.
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Easy

Code: Select all

setudef str notes
bind pub - .note pub_note
bind join - pub_note_join
bind pubm - pub_note_bind

proc pub_note {n u h c a} {
    set notes [channel get $c notes]
    set m [lassign [split $a] t] 
    dict lappend notes $t [list message $m time [clock seconds] from $n]
    channel set $c notes $notes
    putnotc $n "Note was send."
}

proc pub_note_check {n c} {
    set notes [channel get $c notes]
    if {[dict exists $notes $n]} {
         foreach m [dict get $notes $n] {
            putmsg $c "$n: [dict get $m from] left a note [duration [expr {[clock seconds] - [dict get $m time]}]] ago: [dict get $m message]"
          }
          dict unset notes $n
          channel set $c notes $notes
    }
}

proc pub_note_bind {n u h c args} {pub_note_check $n $c}
Not tested.
Last edited by Johannes13 on Sat Jun 15, 2013 2:27 pm, edited 1 time in total.
S
SignZ
Voice
Posts: 18
Joined: Thu Jun 17, 2010 3:52 pm

Post by SignZ »

Thanks Johannes, but I get an error when I do .note anybody
[16:55:15] Tcl error [pub_note]: invalid command name "lassign"
I restarted the bot already, but that did nothing.
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Upgrade to at least Tcl 8.5

Tcl 8.4 is end of life.
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

SQLite version (not channel specific)

Code: Select all

package require sqlite3
sqlite3 notesdb pubnotes.db
notesdb eval {CREATE TABLE IF NOT EXISTS notes (from TEXT, time INTEGER, to TEXT, message TEXT}
bind pub - .note pub_note
bind join - pub_note_join
bind pubm - pub_note_bind

proc pub_note {n u h c a} {
    set m [join [lassign [split $a] t]]
    set time [clock seconds]
    notesdb eval {INSERT INTO notes VALUES ($n, $time, $t, $m)}
    putnotc $n "Note was send."
}

proc pub_note_check {n c} {
    set notes [channel get $c notes]
    notesdb eval {SELECT * FROM notes WHERE to = $n} {
        putmsg $c "$to: $from left a note [duration [expr {[clock seconds] - $time}]] ago: $message"
    }
    notesdb eval {DELETE FROM notes WHERE to = $n}
}

proc pub_note_bind {n u h c args} {pub_note_check $n $c}
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Ok, speechless was friendly enough to write a 8.4 version:

Code: Select all

setudef str notes
bind pub - .note pub_note
bind join - pub_note_check
bind pubm - pub_note_bind

proc pub_note {n u h c a} {
	set notes [channel get $c notes]
	set m [join [lrange [split $a] 1 end]]
	set t [lindex [split $a] 0]
	lappend notes $t\n$m\n[clock seconds]\n$n
	channel set $c notes $notes
	putnotc $n "Note was sent."
}

proc pub_note_check {n c} {
	set notes [channel get $c notes]
	set start 0
	while {[set idx [lsearch -start $start -glob [string tolower $notes] "[string tolower $n]\n*"]] > -1} {
		foreach {t m c f} [split [lindex $notes $idx] \n] { break }
		putmsg $c "$n: $f left a note [duration [expr {[clock seconds] - $c}]] $m"
		set notes [lreplace $notes $idx $idx]
		set start [incr idx -1]
	}
	channel set $c notes $notes
}

proc pub_note_bind {n u h c args} {pub_note_check $n $c}
To be clear: 8.4 is end-of-life, and I refuse it to change something so it can work with 8.4
Post Reply