Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
1.修正了部分事件函数的描述
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Jul 15, 2019
1 parent 940a966 commit 222dc53
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 22 deletions.
34 changes: 33 additions & 1 deletion dist/app/ltd.cmyr.demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,55 @@ class App extends cq_robot_1.CQApp {
constructor() {
super('ltd.cmyr.demo', __dirname);
this.CQ.setDebug(false);
this.isEnable = true; //注意,只有isEnable为true的插件才会载入,可以将isEnable置为false不载入某插件
}
debug() {
// console.log('debug()方法只会在debug模式下执行')
this.privateMsg('test', 1, 996881204, '这是一条私聊消息', 1);
this.groupMsg('test', 1, 947983200, 996881204, '', '这是一条群消息', 1);
this.discussMsg('test', 1, 580771123, 996881204, '这是一条讨论组消息', 1);
}
/**
* 本函数会在连接建立前执行,可以在此执行初始化代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
startup() {
return 0;
}
/**
*本函数会在连接断开后执行,请在此执行插件退出代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
exit() {
return 0;
}
/**
* 本函数会在连接建立后立刻执行,可以在此执行初始化代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
enable() {
this.isEnable = true;
return 0;
}
/**
* 本函数会在连接断开前执行,可以在此执行插件退出代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
disable() {
this.isEnable = false;
return 0;
Expand Down
16 changes: 9 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const path = require("path");
const help_1 = require("./utils/help");
const bot = cq_robot_1.CQWebSocketInit(help_1.getCQWebSocketOption(__dirname));
const app = help_1.loadApp(path.join(__dirname, 'app')); //载入全体插件
// app.forEach((key) => {
//
// })
app.forEach((key) => {
key.startup();
cq_robot_1.printTime(`[应用] ${key.APP_ID}已载入`, cq_robot_1.CQLog.LOG_INFO_SUCCESS);
});
bot.on('ready', () => {
cq_robot_1.printTime('[WebSocket] 连接成功!', cq_robot_1.CQLog.LOG_INFO);
app.forEach((key) => {
Expand Down Expand Up @@ -168,12 +169,13 @@ bot.on('socket.closing', (attempts) => {
app.forEach((key) => {
if (key.isEnable) {
key.disable();
cq_robot_1.printTime(`[应用] ${key.APP_ID}已关闭`, cq_robot_1.CQLog.LOG_INFO);
cq_robot_1.printTime(`[应用] ${key.APP_ID}已停用`, cq_robot_1.CQLog.LOG_INFO);
}
});
});
bot.on('socket.close', (socketType, attempts) => {
app.forEach((key) => {
key.exit();
cq_robot_1.printTime(`[应用] ${key.APP_ID}已关闭`, cq_robot_1.CQLog.LOG_INFO);
});
});
// setTimeout(() => {
// bot.disconnect()
// }, 10000)
3 changes: 3 additions & 0 deletions dist/utils/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,8 @@ function checkApp(app) {
cq_robot_1.printTime(`[应用]${app.APP_ID}的HTTP_API版本不为4`, cq_robot_1.CQLog.LOG_ERROR);
return false;
}
if (!app.isEnable) { //应用未启用
return false;
}
return true;
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "CaoMeiYouRen",
"license": "ISC",
"dependencies": {
"cq-robot": "^0.7.0",
"cq-robot": "^0.7.2",
"cq-websocket": "^2.0.1",
"got": "^9.6.0",
"json5": "^2.1.0",
Expand Down
34 changes: 33 additions & 1 deletion src/app/ltd.cmyr.demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,55 @@ class App extends CQApp {
constructor() {
super('ltd.cmyr.demo', __dirname)
this.CQ.setDebug(false)
this.isEnable = true//注意,只有isEnable为true的插件才会载入,可以将isEnable置为false不载入某插件
}
debug(): void {
// console.log('debug()方法只会在debug模式下执行')
this.privateMsg('test', 1, 996881204, '这是一条私聊消息', 1)
this.groupMsg('test', 1, 947983200, 996881204, '', '这是一条群消息', 1)
this.discussMsg('test', 1, 580771123, 996881204, '这是一条讨论组消息', 1)
}
/**
* 本函数会在连接建立前执行,可以在此执行初始化代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
startup(): 0 {
return 0
}
/**
*本函数会在连接断开后执行,请在此执行插件退出代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
exit(): 0 {
return 0
}
/**
* 本函数会在连接建立后立刻执行,可以在此执行初始化代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
enable(): 0 {
this.isEnable = true
return 0
}
/**
* 本函数会在连接断开前执行,可以在此执行插件退出代码
*
* @author CaoMeiYouRen
* @date 2019-07-15
* @returns {0}
* @memberof App
*/
disable(): 0 {
this.isEnable = false
return 0
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CQWebSocketInit, printTime, CQLog } from 'cq-robot'
/* eslint-disable guard-for-in */
import fs = require('fs')
import path = require('path')
import JSON5 = require('json5')
import { CQWebSocket } from 'cq-websocket'
import { getCQWebSocketOption, loadApp, sortApp } from './utils/help'
const bot: CQWebSocket = CQWebSocketInit(getCQWebSocketOption(__dirname))
const app = loadApp(path.join(__dirname, 'app'))//载入全体插件
// app.forEach((key) => {
//
// })
app.forEach((key) => {
key.startup()
printTime(`[应用] ${key.APP_ID}已载入`, CQLog.LOG_INFO_SUCCESS)
})
bot.on('ready', () => {
printTime('[WebSocket] 连接成功!', CQLog.LOG_INFO)
app.forEach((key) => {
Expand Down Expand Up @@ -142,14 +142,14 @@ bot.on('socket.closing', (attempts) => {
app.forEach((key) => {
if (key.isEnable) {
key.disable()
printTime(`[应用] ${key.APP_ID}已关闭`, CQLog.LOG_INFO)
printTime(`[应用] ${key.APP_ID}已停用`, CQLog.LOG_INFO)
}
})
})
bot.on('socket.close', (socketType, attempts) => {

app.forEach((key) => {
key.exit()
printTime(`[应用] ${key.APP_ID}已关闭`, CQLog.LOG_INFO)
})
})
// setTimeout(() => {
// bot.disconnect()
// }, 10000)

3 changes: 3 additions & 0 deletions src/utils/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ function checkApp(app: CQApp): boolean {
printTime(`[应用]${app.APP_ID}的HTTP_API版本不为4`, CQLog.LOG_ERROR)
return false
}
if (!app.isEnable) {//应用未启用
return false
}
return true
}

0 comments on commit 222dc53

Please sign in to comment.