【Misskey】ノート投稿時、特定の文字列をランダムな数字に置換するプラグイン

  1. /// @ 0.17.0
  2. ### {
  3. name: "ダイスを振る"
  4. version: "3"
  5. author: "@uru_S3@oekakiskey.com"
  6. description: "ノート投稿時、特定の文字列をランダムな数字に置換する"
  7. config: {
  8. target_mark: {
  9. type: "string"
  10. label: "置換する文字列の頭につける記号(1字)"
  11. description: ""
  12. default: "%"
  13. },
  14. target_word: {
  15. type: "string"
  16. label: "置換する文字列"
  17. description: ""
  18. default: "dice"
  19. },
  20. min_num: {
  21. type: "number"
  22. label: "最小の数"
  23. description: ""
  24. default: 0
  25. },
  26. max_num: {
  27. type: "number"
  28. label: "最大の数"
  29. description: ""
  30. default: 100
  31. },
  32. fg_color: {
  33. type: "string"
  34. label: "文字色"
  35. description: "16進数(6字)"
  36. default: "ff0000"
  37. }
  38. }
  39. }
  40.  
  41. var mark = Plugin:config.target_mark
  42. var word = Plugin:config.target_word
  43. var min = Plugin:config.min_num
  44. var max = Plugin:config.max_num
  45. var color = Plugin:config.fg_color
  46. @remove_null_property(object) {
  47. if Core:type(object) != 'obj' {
  48. return object
  49. }
  50. let new_obj = {}
  51. each let kv Obj:kvs(object) {
  52. let v = remove_null_property(kv[1])
  53. if Core:type(v) != 'null' {
  54. Obj:set(new_obj kv[0] v)
  55. }
  56. }
  57. return new_obj
  58. }
  59.  
  60. @rnd_num() {
  61. return Math:rnd(min max)
  62. }
  63.  
  64. Plugin:register_note_post_interruptor(@(note) {
  65. var result = []
  66. if (note.text.incl([mark word].join()) == true) {
  67. each let txt note.text.split(mark) {
  68. var tmp = txt
  69. var num = `$[fg.color={color} {rnd_num().to_str()}]`
  70. tmp = tmp.replace(word num)
  71. result.push(tmp)
  72. }
  73. note.text = result.join()
  74. }
  75. let new_note = remove_null_property(note)
  76. return new_note
  77. })