提交 202366db 编写于 作者: Q qq_21051503

Thu Feb 15 16:53:00 CST 2024 inscode

上级 34484e4b
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
//1、微信扫码(17年注册的微信可以直接扫,17年后注册的微信自己要绑定手机号和个人认证下,我记得还要开通收付款。) //1、微信扫码(17年注册的微信可以直接扫,17年后注册的微信自己要绑定手机号和个人认证下,我记得还要开通收付款。)
//2、本机器人只适用于微信群聊时触发,私聊无法触发 //2、本机器人只适用于微信群聊时触发,私聊无法触发
//3、扫码之后,在群里@小白+关键字(比如@小白抽签,或者小白厦门天气,所有关键字在) //3、扫码之后,在群里@小白+关键字(比如@小白抽签,或者小白厦门天气,所有关键字在)
process.on('uncaughtException', function(err) { process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err); console.log('Caught exception: ' + err);
}); });
import {FileBox} from 'file-box' import { FileBox } from 'file-box'
import QrcodeTerminal from 'qrcode-terminal' import QrcodeTerminal from 'qrcode-terminal'
import axios from "axios" import axios from "axios"
import {WechatyBuilder} from 'wechaty' import { WechatyBuilder } from 'wechaty'
const ajax = async (url, param, type) => { const ajax = async (url, param, type) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var axiosOption = { var axiosOption = {
...@@ -22,7 +22,7 @@ const ajax = async (url, param, type) => { ...@@ -22,7 +22,7 @@ const ajax = async (url, param, type) => {
'Content-Type': 'application/json;charset=utf-8' 'Content-Type': 'application/json;charset=utf-8'
} }
} }
axios(axiosOption).then(function(res) { axios(axiosOption).then(function (res) {
resolve(res) resolve(res)
}).catch(error => { }).catch(error => {
console.log(error) console.log(error)
...@@ -72,17 +72,17 @@ const page = { ...@@ -72,17 +72,17 @@ const page = {
console.log('登录成功:' + user) console.log('登录成功:' + user)
}) })
.on('message', async msg => { .on('message', async msg => {
page.methods.message(msg,false,1) page.methods.message(msg, false, 1)
}) })
.start() .start()
}, },
async message(msg, isTest,role) { async message(msg, isTest, role) {
// msg是 接收到的信息、 // msg是 接收到的信息、
//isTest其实原来有测试的PuppetMock 可以参考博主 博主写的这篇https://mp.weixin.qq.com/s/nhchTzEcxramFTS_0CyU1g //isTest其实原来有测试的PuppetMock 可以参考博主 博主写的这篇https://mp.weixin.qq.com/s/nhchTzEcxramFTS_0CyU1g
//role是为了你一次性启动多个机器人预留的 参考博主这篇https://mp.weixin.qq.com/s/r75D51GUXKgPSLCub38OfA //role是为了你一次性启动多个机器人预留的 参考博主这篇https://mp.weixin.qq.com/s/r75D51GUXKgPSLCub38OfA
let text = msg.text() //获取聊天内容 let text = msg.text() //获取聊天内容
let room = msg.room() //获取房间信息 let room = msg.room() //获取房间信息
let userNice=msg.talker(); let userNice = msg.talker();
let msgType = msg.type() //7 是文本 6是图片 8是视频 https://wechaty.js.org/zh/docs/api/message let msgType = msg.type() //7 是文本 6是图片 8是视频 https://wechaty.js.org/zh/docs/api/message
if (text.length == 0 || !room) { if (text.length == 0 || !room) {
return; return;
...@@ -96,9 +96,9 @@ const page = { ...@@ -96,9 +96,9 @@ const page = {
if (room && text.length > 0) { if (room && text.length > 0) {
var topic = await room.topic() //房间名 var topic = await room.topic() //房间名
// if (page.data.qunArr.indexOf(topic)!=-1 ) { // if (page.data.qunArr.indexOf(topic)!=-1 ) {
switch(role){ switch (role) {
case 1: case 1:
if(text.indexOf("@小白") != -1){//这里可以定义你的触发条件,比如 @小白你好啊 识别到小白,才触发机器人的自动回复 if (text.indexOf("@小白") != -1) {//这里可以定义你的触发条件,比如 @小白你好啊 识别到小白,才触发机器人的自动回复
text = text.replace(/\s*/g, '').replace(/@小白/g, '');//这里可以定义你的触发条件,比如 @小白你好啊 识别到小白,才触发机器人的自动回复 text = text.replace(/\s*/g, '').replace(/@小白/g, '');//这里可以定义你的触发条件,比如 @小白你好啊 识别到小白,才触发机器人的自动回复
userEvent.init(room, text)//注意,每次有接收到群消息都会回复 userEvent.init(room, text)//注意,每次有接收到群消息都会回复
} }
...@@ -170,7 +170,7 @@ const userEvent = { ...@@ -170,7 +170,7 @@ const userEvent = {
async hli(room, text) { async hli(room, text) {
let m = this; let m = this;
let msg = await m.ajax(`https://api.lolimi.cn/API/huang/api.php`, {}, "get") let msg = await m.ajax(`https://api.lolimi.cn/API/huang/api.php`, {}, "get")
await room.say(msg.data.text+m.sayEnd) await room.say(msg.data.text + m.sayEnd)
}, },
//微信机器人人 //微信机器人人
async weixinChatbot(room, text) { async weixinChatbot(room, text) {
...@@ -193,7 +193,7 @@ const userEvent = { ...@@ -193,7 +193,7 @@ const userEvent = {
if (text.indexOf("解第") != -1) { if (text.indexOf("解第") != -1) {
answer = JSON.parse(answer).multimsg[0] answer = JSON.parse(answer).multimsg[0]
} }
await room.say(answer+m.sayEnd) await room.say(answer + m.sayEnd)
}, },
//取名 //取名
async naming(room, text) { async naming(room, text) {
...@@ -215,7 +215,7 @@ const userEvent = { ...@@ -215,7 +215,7 @@ const userEvent = {
str += v.naming + "" str += v.naming + ""
}) })
str = str.substr(0, str.length - 1) str = str.substr(0, str.length - 1)
await room.say(str+m.sayEnd) await room.say(str + m.sayEnd)
}, },
//转语言 //转语言
async toVoice(room, text) { async toVoice(room, text) {
...@@ -248,7 +248,7 @@ const userEvent = { ...@@ -248,7 +248,7 @@ const userEvent = {
var radomArr = res.data.result var radomArr = res.data.result
var randomIndex = Math.floor(Math.random() * radomArr.length) var randomIndex = Math.floor(Math.random() * radomArr.length)
var obj = radomArr[randomIndex]; var obj = radomArr[randomIndex];
await room.say(obj.date + ":" + obj.title+m.sayEnd) await room.say(obj.date + ":" + obj.title + m.sayEnd)
}, },
//去水印 1 //去水印 1
...@@ -258,7 +258,7 @@ const userEvent = { ...@@ -258,7 +258,7 @@ const userEvent = {
// await room.say(url) // await room.say(url)
let res = await this.ajax("http://api.xn--7gqa009h.top/api/dy_jx?a=" + text, {}, "get") let res = await this.ajax("http://api.xn--7gqa009h.top/api/dy_jx?a=" + text, {}, "get")
console.log(res.data.url) console.log(res.data.url)
await room.say(text + "解析后下载地址:" + res.data.url+m.sayEnd) await room.say(text + "解析后下载地址:" + res.data.url + m.sayEnd)
} }
}, },
...@@ -285,5 +285,5 @@ const userEvent = { ...@@ -285,5 +285,5 @@ const userEvent = {
await room.say(fileBox) await room.say(fileBox)
await room.say(m.sayEnd) await room.say(m.sayEnd)
}, },
sayEnd:"\n----------------\n来至公众号:'程序员野区'的作者雪狼之夜的开源项目,\n公众号地址\nhttps://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI1NjAxODkzMg== \n开源项目地址:https://inscode.csdn.net/@xuelang532777032/NodeJS" sayEnd: "\n----------------\n来至公众号:'程序员野区'的作者雪狼之夜的开源项目,\n公众号地址\nhttps://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI1NjAxODkzMg== \n开源项目地址:https://inscode.csdn.net/@xuelang532777032/NodeJS"
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册