From b6c5258b0fafc289b7f71f47737f96f4c3f124f0 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:16:44 +0900 Subject: [PATCH] =?UTF-8?q?=E8=89=B2=E6=B1=BA=E3=82=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/modules/color/index.ts diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts new file mode 100644 index 0000000..ecd8904 --- /dev/null +++ b/src/modules/color/index.ts @@ -0,0 +1,33 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; + +export default class extends Module { + public readonly name = 'color'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + if (msg.text && msg.text.includes('色決めて')) { + // rgbをそれぞれ乱数で生成する + const r = Math.floor(Math.random() * 256); + const g = Math.floor(Math.random() * 256); + const b = Math.floor(Math.random() * 256); + // rgbをhexに変換する + const hex = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`; + const message = `RGB: ${r}, ${g}, ${b} (#${hex})とかどう? [参考](https://www.colorhexa.com/${hex})` + msg.reply(message, { + immediate: true + }); + return true; + } else { + return false; + } + } +}