| View previous topic :: View next topic |
| Author |
Message |
SignZ Voice
Joined: 17 Jun 2010 Posts: 18
|
Posted: Mon Jun 10, 2013 7:02 am Post subject: Public note script |
|
|
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. |
|
| Back to top |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Tue Jun 11, 2013 3:38 pm Post subject: |
|
|
Easy
| Code: | 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 |
|
| Back to top |
|
 |
SignZ Voice
Joined: 17 Jun 2010 Posts: 18
|
Posted: Thu Jun 13, 2013 10:57 am Post subject: |
|
|
Thanks Johannes, but I get an error when I do .note anybody
| Quote: | | [16:55:15] Tcl error [pub_note]: invalid command name "lassign" |
I restarted the bot already, but that did nothing. |
|
| Back to top |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Thu Jun 13, 2013 5:26 pm Post subject: |
|
|
Upgrade to at least Tcl 8.5
Tcl 8.4 is end of life. |
|
| Back to top |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Sat Jun 15, 2013 2:37 pm Post subject: |
|
|
SQLite version (not channel specific)
| Code: |
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}
|
|
|
| Back to top |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Sat Jun 15, 2013 4:40 pm Post subject: |
|
|
Ok, speechless was friendly enough to write a 8.4 version:
| Code: | 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 |
|
| Back to top |
|
 |
|