「 记录一次修改yunzai示例插件达到查询学校寝室电量的目的 」
2023-02-19 12:20:33 时间
因为学校查询剩余电费需要打开专用的校园app,但很麻烦使用起来,所以依托于原神查询机器人yunzaibot的示例插件做了修改
大概命令为寝室电量xxxxx
下面附上代码
import plugin from '../../lib/plugins/plugin.js'
import fetch from 'node-fetch'
export class example extends plugin {
constructor () {
super({
/** 功能名称 */
name: '寝室电量',
/** 功能描述 */
dsc: '简单开发示例',
/** https://oicqjs.github.io/oicq/#events */
event: 'message',
/** 优先级,数字越小等级越高 */
priority: 5000,
rule: [
{
/** 命令正则匹配 */
reg: '^#*寝室电量(.*)$',
/** 执行方法 */
fnc: 'hitokoto'
}
]
})
}
/**
* #一言
* @param e oicq传递的事件参数e
*/
async hitokoto(e) {
/** e.msg 用户的命令消息 */
logger.info('[用户命令]', e.msg)
let webkeywd = e.msg.replace(/#|寝室电量/gm, '');
/** 一言接口地址 */
let url = `https://学校的查询地址${webkeywd}`
/** 调用接口获取数据 */
let res = await fetch(url).catch((err) => logger.error(err))
/** 判断接口是否请求成功 */
if (!res) {
logger.error('[电量] 接口请求失败')
return await this.reply('电量接口请求失败')
}
/** 接口结果,json字符串转对象 */
res = await res.json()
/** 输入日志 */
logger.info(`[接口结果] 电量:${res.data}`)
/** 最后回复消息 */
await this.reply(`寝室${webkeywd}电量为: ${res.data} 度`)
await this.reply(`请节约用电哦, 人人有责!`)
}
}
2022.11.9 学校更换了接口,这里采用axios以post请求获取值
import plugin from '../../lib/plugins/plugin.js'
import fetch from 'node-fetch'
import fs from 'node:fs'
import axios from 'axios'
// const fs = require('fs');
export class example extends plugin {
constructor () {
super({
/** 功能名称 */
name: '寝室电量',
/** 功能描述 */
dsc: '简单开发示例',
/** https://oicqjs.github.io/oicq/#events */
event: 'message',
/** 优先级,数字越小等级越高 */
priority: 5000,
rule: [
{
/** 命令正则匹配 */
reg: '^#*寝室电量(.*)$',
/** 执行方法 */
fnc: 'hitokoto'
}
]
})
}
/**
* #一言
* @param e oicq传递的事件参数e
*/
async hitokoto(e) {
/** e.msg 用户的命令消息 */
logger.info('[用户命令]', e.msg)
let webkeywd = e.msg.replace(/#|寝室电量/gm, '');
/** 一言接口地址 */
/** 用接口获取数据 */
// const app_input = { school_code: '01240', rqType: 'electric', roomCode: "${webkeywd}" }
// 文档 https://axios-http.com/docs/post_example
// 文档 https://axios-http.com/docs/post_example
const res = await axios.post('查询地址', {
school_code: '01240',
rqType: 'electric',
roomCode: `${webkeywd}`,
});
// res = await res.json()
logger.info(res.data)
let deco = res.data
// logger.info(`[接口结果] 电量:${res}`) ;
// let testres = ${res} ;
// res = await fetch(res).catch((err) => logger.error(err))
// const jsonres = JSON.stringify(res);
/** 输入日志 */
// logger.info(`[接口结果] 电量:${res.data}`);
/** 最后回复消息 */
await this.reply(`寝室${webkeywd}电量为${res.data.data.balance}度 `)
await this.reply(`请节约用电哦!`)
}
}
我没想到以这种方式更新此文章....挺快的就
相关文章
- 万万没想到,go的数据库操作,也能像php一样溜了
- Typora+PicGo+GitHub实现图片快速上传
- Linux计划任务服务程序
- 2022 如何在 GitHub 上搭建个人网站(github.io)
- 虚拟机安装linux无法访问外网解决办法
- 用过 mongodb 吧, 这三个大坑踩过吗?
- 教你配置windows上的windbg,linux上的lldb,打入clr内部这一篇就够了
- MongoDB 在评论中台的实践
- 使用mongodb作为Quartz.Net下的JobStore实现底层的持久化机制
- mongodb之使用explain和hint性能分析和优化
- mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理
- mongodb 3.x 之实用新功能窥看[1] ——使用TTLIndex做Cache处理
- 双十一来了,别让你的mongodb宕机了
- GO语言开发环境搭建笔记
- PHP判断网络连通
- 开启phpMyAdmin的远程登录
- PHP_cURL初始化和执行方法
- PHP经典函数收集
- PHP所有函数列表
- php bbcode过滤