kivibot-plugin-pictures
Version:
一个QQ机器人框架kivibot的插件
66 lines (63 loc) • 1.81 kB
JavaScript
const {
KiviPlugin, segment
} = require('@kivibot/core')
const ver=require('./package.json').version
const fs = require('fs');
const plugin = new KiviPlugin('来张图', ver)
function getImg(sort) {
if(sort=='cat'){
const length=2515
}
if(sort=='mp'){
const length=1828
}
if(sort=='pc'){
const length=1083
}
if(sort=='random'){
const length=3957
}
if(sort=='yin'){
const length=2071
}
// read contents of the file
const data = fs.readFileSync(__dirname+'/../data/'+sort+'.txt', 'UTF-8');
// split the contents by new line
const lines = data.split(/\r?\n/);
const picurl=lines[plugin.randInt(0,length)]
return picurl
}
plugin.onMounted(() => {
plugin.onMessage(event => {
const {
raw_message
} = event
const api = 'https://ap1.iw233.cn/api.php?sort='
if (raw_message == '来张图') {
const msg = [
'图到啦!',
segment.image(getImg('random'))]
event.reply(msg)
}
if (raw_message.indexOf('来张图 ') == 0) {
const message = raw_message.replace('壁纸 ', '')
if (message.includes('横屏')) {
const key = 'pc'
const msg = [
'图到啦!',
segment.image(getImg(key))]
event.reply(msg)
}
if (message.includes('竖屏')) {
const key = 'mp'
const msg = [
'图到啦!',
segment.image(getImg(key))]
event.reply(msg, true)
}
}
})
})
module.exports = {
plugin
}