Skip to content

Commit

Permalink
Feat: 可以增加管理员了
Browse files Browse the repository at this point in the history
Change: 原Logger仅作为复读计数使用,其他功能移动到userManagement
  • Loading branch information
Ninzore committed Apr 13, 2021
1 parent c62e18c commit 2cbe17b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 2021

### 04/13 v1.7.7
* main:
* Feat: 可以使用指令增加管理员了
* Change: 原Logger仅作为复读计数使用,其他功能移动到userManagement

### 04/12 v1.7.6
* utils/userManagement:
* Feat: 增加SU用户列表(在data/userControl.json)
Expand Down
21 changes: 14 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config from './utils/config';
import {initialise} from "./utils/initilise";
import CQ from './utils/CQcode';
import userManagement from "./utils/userManagement";
import Logger from './utils/Logger';
import RptLogger from './utils/rptLogger';
import RandomSeed from 'random-seed';
import minimist from 'minimist';
import weibo from './plugin/weibo';
Expand All @@ -24,13 +24,13 @@ import telephone from './plugin/telephone';
const setting = config.bot;
const bot = new CQWebSocket(config.cqws);
const rand = RandomSeed.create();
const logger = new Logger();
const rptLog = new RptLogger();

initialise({bot, "replyFunc": replyMsg});

bilibili.bilibiliReply(replyMsg);
twitter.twitterReply(replyMsg);
pretendLearn.learnReply(replyMsg, logger);
pretendLearn.learnReply(replyMsg, rptLog);
nbnhhsh.reply(replyMsg);
telephone.init(replyMsg, bot);

Expand Down Expand Up @@ -111,14 +111,21 @@ bot.on('message.private', (e, context) => {
//Ban
const { 'ban-u': bu, 'ban-g': bg } = args;
if (bu && typeof bu == 'number') {
Logger.ban('u', bu);
userManagement.ban('u', bu);
replyMsg(context, `已封禁用户${bu}`);
}
if (bg && typeof bg == 'number') {
Logger.ban('g', bg);
userManagement.ban('g', bg);
replyMsg(context, `已封禁群组${bg}`);
}

//addSuperuser
const {'su': su} = args;
if (su && typeof su == 'number') {
userManagement.addSu(su);
replyMsg(context, `已设置管理员${su}`);
}

//停止程序(利用pm2重启)
if (args.shutdown) process.exit();
});
Expand Down Expand Up @@ -284,8 +291,8 @@ function groupMsg(e, context) {
context.message = text_bak;
//复读(
//随机复读,rptLog得到当前复读次数
if (logger.rptLog(group_id, user_id, context.message) >= setting.repeat.times && getRand() <= setting.repeat.probability) {
logger.rptDone(group_id);
if (rptLog.rptLog(group_id, user_id, context.message) >= setting.repeat.times && getRand() <= setting.repeat.probability) {
rptLog.rptDone(group_id);
//延迟2s后复读
setTimeout(() => {
replyMsg(context, context.message);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wecab",
"version": "1.7.6",
"version": "1.7.7",
"description": "QQ上最好的订阅制bot",
"main": "index.js",
"dependencies": {
Expand Down
48 changes: 4 additions & 44 deletions utils/Logger.js → utils/rptLogger.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,22 @@
import Fs from 'fs';
import Path from 'path';
import config from './config';

const banListFile = Path.resolve(__dirname, '../data/ban.json');

if (!Fs.existsSync(banListFile)) {
Fs.writeFileSync(
banListFile,
JSON.stringify({
u: [],
g: [],
})
);
}

let banList = require(banListFile);

function updateBanListFile() {
Fs.writeFileSync(banListFile, JSON.stringify(banList));
}

/**
* 各种记录
*
* @class Logger
*/
class Logger {
class RptLogger {
constructor() {
this.repeater = []; //复读
this.date = new Date().getDate();
}

static ban(type, id) {
switch (type) {
case 'u':
banList.u.push(id);
break;
case 'g':
banList.g.push(id);
break;
}
updateBanListFile();
}

static checkBan(u, g = 0) {
if (banList.u.includes(u)) return true;
if (g != 0 && banList.g.includes(g)) return true;
return false;
}

/**
* 记录复读情况
*
* @param {number} g 群号
* @param {number} u QQ号
* @param {string} msg 消息
* @returns 如果已经复读则返回0,否则返回当前复读次数
* @memberof Logger
* @memberof RptLogger
*/
rptLog(g, u, msg) {
let t = this.repeater[g];
Expand All @@ -81,11 +41,11 @@ class Logger {
* 标记该群已复读
*
* @param {number} g 群号
* @memberof Logger
* @memberof RptLogger
*/
rptDone(g) {
this.repeater[g].done = true;
}
}

export default Logger;
export default RptLogger;

0 comments on commit 2cbe17b

Please sign in to comment.