Created
March 31, 2016 21:55
-
-
Save khobbits/7fb8d9557256443a4277d1881caf8942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setctx lains | |
bind pub - |listcmd listcmd | |
bind pub - |setcmd setcmd | |
bind pub - .listcmd listcmd | |
bind pub - .setcmd setcmd | |
bind pubm - "*" show_fct | |
global "dirname" | |
set dirname "custcmd" | |
proc create_db { chan cmd definfo } { | |
global dirname | |
if {[file exists $dirname] == 0} { | |
file mkdir $dirname | |
} | |
if {[file exists $dirname/$chan] == 0} { | |
file mkdir $dirname/$chan | |
} | |
if {[file exists $dirname/$chan/$cmd] == 0} { | |
set crtdb [open $dirname/$chan/$cmd a+] | |
puts $crtdb "$definfo" | |
close $crtdb | |
} | |
} | |
proc readdb { rdb } { | |
set fs_open [open $rdb r] | |
gets $fs_open dbout | |
close $fs_open | |
return $dbout | |
} | |
proc setcmd { nick userhost handle chan arg } { | |
global dirname | |
if {[isop $nick $chan] == 0 && [matchattr $handle o] == 0 } { | |
putnotc $nick "You need to be an op to create/edit custom channel commands" | |
return 0 | |
} | |
set txt [split $arg] | |
set cmd [string tolower [lindex $txt 0]] | |
set cmd [string trimleft $cmd "./"] | |
set cmdf "${cmd}.cmd" | |
set msg [join [lrange $txt 1 end]] | |
if {$msg != ""} { | |
if {[file exists $dirname/$chan/${cmd}.alias] == 1} { | |
file delete $dirname/$chan/${cmd}.alias | |
putnotc $nick "Deleting alias with the name '${cmd}'" | |
} | |
if {[file exists $dirname/$chan/$cmdf] == 0} { | |
create_db "$chan" "$cmdf" "$msg" | |
putnotc $nick "Created custom command '.${cmd}' for channel $chan. Use .addalias <alias> <cmd> to create an alias." | |
} else { | |
set readdb [readdb $dirname/$chan/$cmdf] | |
file delete $dirname/$chan/$cmdf | |
create_db "$chan" "$cmdf" "$msg" | |
putnotc $nick "Modified custom command '.${cmd}' for channel $chan, remember .appcmd can pre/suffix existing commands. Old content:" | |
putnotc $nick "Custcmd '.${cmd}': $readdb" | |
} | |
} else { | |
if {[file exists $dirname/$chan/$cmdf] == 1 && $cmd != ""} { | |
set readdb [readdb $dirname/$chan/$cmdf] | |
file delete $dirname/$chan/$cmdf | |
putnotc $nick "Deleted custom command '.${cmd}' for channel $chan. Old content:" | |
putnotc $nick "Custcmd '.${cmd}': $readdb" | |
} else { | |
putnotc $nick "Custcmd '.${cmd}' doesn't currently exist, use .setcmd <cmd> <text>, to add it, or .custcmd to list existing commands." | |
} | |
} | |
} | |
proc bncnotc {text} { putclient ":-sBNC!core@shroudbnc.info PRIVMSG $::botnick :$text"; putmainlog "Debug: $text" } | |
proc show_fct { nick userhost handle chan text } { | |
set text [concat $text] | |
set command [lindex [split [string tolower $text] { }] 0] | |
set text [lrange [split $text { }] 1 end] | |
set method putchan | |
set target $chan | |
set prefix "" | |
if {([string index $command 0] == "|") || ([khfloodc $nick] >= 1)} { | |
set method putnotc | |
set target $nick | |
} elseif {([string index $command 0] != ".") && ([string index $command 0] != "+")} { | |
return | |
} | |
set tail [lindex $text end] | |
#If the last param begins with a @ then the message should be directed at that 'string' | |
if {[string index $tail 0] == "@"} { | |
set text [lrange $text 0 end-1] | |
set tail [string range $tail 1 end] | |
#If the last param began with @@ then the reply should be messaged to a player | |
if {[string index $tail 0] == "@"} { | |
set tail [string range $tail 1 end] | |
set validtarget [llength [split $tail {,}]] | |
foreach postarget [split $tail {,}] { | |
if {![onchan $postarget $chan]} { | |
set validtarget 0 | |
} | |
} | |
set tail [join [split $tail {,}] {,}] | |
if {($validtarget > 0) && ([khfloodc $nick] < 1)} { | |
set method putnotc | |
set target "${nick},${tail}" | |
} | |
} | |
set prefix "${tail}: " | |
} elseif {[string index $tail end] == "@"} { | |
set text [lrange $text 0 end-1] | |
set tail [string range $tail 0 end-1] | |
#If the last param began with @@ then the reply should be messaged to a player | |
if {[string index $tail end] == "@"} { | |
set tail [string range $tail 0 end-1] | |
set validtarget [llength [split $tail {,}]] | |
foreach postarget [split $tail {,}] { | |
if {![onchan $postarget $chan]} { | |
set validtarget 0 | |
} | |
} | |
set tail [join [split $tail {,}] {,}] | |
if {($validtarget > 0) && ($validtarget < 4) && ([khfloodc $nick] < 1)} { | |
set method putnotc | |
set target "${nick},${tail}" | |
} | |
} | |
set prefix "${tail}: " | |
} | |
set count 0 | |
set return [showcmd $nick $userhost $handle $chan $chan $command [join $text { }]] | |
foreach line [split $return "\n"] { | |
incr count | |
if {[string length $line] > 1} { | |
$method $target "${prefix}${line}" | |
} | |
if {$count >= 3} { return } | |
} | |
} | |
proc listcmd { nick userhost handle chan arg } { | |
global dirname | |
set cmd [glob -tails -directory $dirname/$chan -nocomplain -type f *.cmd] | |
set proc [glob -tails -directory $dirname/$chan -nocomplain -type f *.proc] | |
set cmd [lsort [string map {{.alias} {} {.cmd} {} {.proc} {}} $cmd]] | |
set proc [lsort [string map {{.alias} {} {.cmd} {} {.proc} {}} $proc]] | |
set i 0 | |
if {[llength $cmd] < 90} { | |
while {$i < [llength $cmd]} { | |
putnotc $nick "\00304CustCmds for ${chan}:\003 [lrange $cmd $i [expr {$i + 45}]]" | |
incr i 46 | |
} | |
} else { | |
putnotc $nick "\00304CustCmds for ${chan}:\003 http://sbnc.khobbits.co.uk/setcmd/commands/%23[string tolower [string trim $chan {#}]]" | |
} | |
putnotc $nick "\00304CustProc for ${chan}:\003 $proc \00304PublicCmds:\003 url log tail stats" | |
} | |
return "KHobbits magical custom commands, reloaded!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment