/// @ 0.17.0
### {
name: "ダイスを振る"
version: "3"
author: "@uru_S3@oekakiskey.com"
description: "ノート投稿時、特定の文字列をランダムな数字に置換する"
config: {
target_mark: {
type: "string"
label: "置換する文字列の頭につける記号(1字)"
description: ""
default: "%"
},
target_word: {
type: "string"
label: "置換する文字列"
description: ""
default: "dice"
},
min_num: {
type: "number"
label: "最小の数"
description: ""
default: 0
},
max_num: {
type: "number"
label: "最大の数"
description: ""
default: 100
},
fg_color: {
type: "string"
label: "文字色"
description: "16進数(6字)"
default: "ff0000"
}
}
}
var mark = Plugin:config.target_mark
var word = Plugin:config.target_word
var min = Plugin:config.min_num
var max = Plugin:config.max_num
var color = Plugin:config.fg_color
@remove_null_property(object) {
if Core:type(object) != 'obj' {
return object
}
let new_obj = {}
each let kv Obj:kvs(object) {
let v = remove_null_property(kv[1])
if Core:type(v) != 'null' {
Obj:set(new_obj kv[0] v)
}
}
return new_obj
}
@rnd_num() {
return Math:rnd(min max)
}
Plugin:register_note_post_interruptor(@(note) {
var result = []
if (note.text.incl([mark word].join()) == true) {
each let txt note.text.split(mark) {
var tmp = txt
var num = `$[fg.color={color} {rnd_num().to_str()}]`
tmp = tmp.replace(word num)
result.push(tmp)
}
note.text = result.join()
}
let new_note = remove_null_property(note)
return new_note
})