Appearance
插件示例
逐步完善中,可先参考
Plugin API
。
请注意
请不要把示例插件发布到 npm。
随机一言
js
const { Plugin, http } = require('keli')
const plugin = new Plugin('一言', '1.0.0')
const api = 'https://v1.hitokoto.cn'
plugin.onMounted((bot, admins) => {
plugin.onMatch('一言', async event => {
const { data } = await http.get(api)
const { hitokoto, from } = data
plugin.log(hitokoto)
event.reply(hitokoto, true)
})
})
module.exports = { plugin }
扔骰子
js
const { Plugin, segment, randomItem, randomInt } = require('keli')
const plugin = new Plugin('骰子', '1.0.0')
const nums = [1, 2, 3, 4, 5, 6]
plugin.onMounted((bot, admins) => {
plugin.onMatch('扔骰子', event => {
// 或使用 const n = randomInt(1, 6)
const n = randomItem(nums)
const msg = segment.dice(n)
event.reply(msg, true)
})
})
module.exports = { plugin }