Commit 7668dfbf authored by nanahira's avatar nanahira

ban kill switch

parent 8c3057e5
......@@ -5813,6 +5813,11 @@
"minimist": "^1.2.5"
}
},
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
......
......@@ -19,6 +19,7 @@ import { DefaultTemplate } from './entities/DefaultTemplate';
import { defaultTemplateMap } from './DefaultTemplate';
import Mustache from 'mustache';
import { GroupUserProfile } from './entities/GroupUserProfile';
import moment from 'moment';
export interface CommonResult {
name: string;
......@@ -550,4 +551,29 @@ export class AppService {
await this.db.getRepository(Group).save(group);
return await this.renderTemplate('group_allow_set', { groupId, value });
}
async banForKicked(groupId: string, operatorId: string) {
if (!this.config.killSwitch) {
return false;
}
const group = await this.botService.findOrCreateGroup(groupId);
const operator = await this.botService.findOrCreateUser(operatorId);
const dateString = moment().format('YYYY-MM-DD HH:mm:ss');
group.banReason = `于 ${dateString} 被用户 ${operatorId} 踢出了群。`;
operator.banReason = `于 ${dateString} 把我踢出了群 ${groupId}。`;
await Promise.all([
this.db.getRepository(Group).save(group),
this.db.getRepository(User).save(operator),
]);
return true;
}
async banForMuted(groupId: string) {
if (!this.config.killSwitch) {
return false;
}
const group = await this.botService.findOrCreateGroup(groupId);
const dateString = moment().format('YYYY-MM-DD HH:mm:ss');
group.banReason = `于 ${dateString} 在群 ${groupId} 把我禁言。`;
await this.db.getRepository(Group).save(group);
return true;
}
}
......@@ -74,6 +74,18 @@ export class BotController {
);
}
});
groupCtx.on('group-member-deleted/passive', async (session) => {
if (
session.userId !== this.botConfig.selfId ||
session.operatorId === this.botConfig.selfId
) {
return;
}
this.botService.log.error(
`Got kicked by ${session.operatorId} in group ${session.groupId}`,
);
await this.appService.banForKicked(session.groupId, session.operatorId);
});
globalCtx
.command('rolldice', '投掷骰子')
.option('count', '-c <count:posint> 骰子数量', { fallback: 1 })
......
......@@ -26,11 +26,13 @@ export function typeormConfig(): TypeOrmModuleOptions {
export interface DiceConfig {
maxDiceCount: number;
maxDiceSize: number;
killSwitch: boolean;
}
export function diceConfig(): DiceConfig {
return {
maxDiceCount: parseInt(process.env.DICE_MAX_COUNT) || 1000,
maxDiceSize: parseInt(process.env.DICE_MAX_SIZE) || 1000,
killSwitch: !process.env.NO_KILL_SWITCH,
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment