Skip to content

Commit

Permalink
feat: 提取ban方法文本设置
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktunes committed Jan 16, 2022
1 parent 6dc958d commit 577c0af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/Bot/modules/Admin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { magenta } from 'colors'
import { cancelJob, scheduleJob } from 'node-schedule'
import { Bot } from '../Bot'
import { magenta } from 'colors'

/**
* 管理员相关
*/
/** 管理员相关 */
export class Admin {
constructor(bot: Bot) {
this.Bot = bot
Expand All @@ -20,9 +18,7 @@ export class Admin {
return this.adminList.has(id)
}

/**
* 被ban名单
*/
/** 被ban名单 */
banlist: Set<number> = new Set<number>()
/**
* 禁用所有功能
Expand All @@ -34,23 +30,23 @@ export class Admin {
if (!user_id || this.adminList.has(user_id)) {
return
}
const msg = `无路赛,禁用你所有功能${time}分钟`
const msg = this.Bot.Data.config.admin.ban.replace('[time]', time.toString())
if (group_id) {
this.Bot.Api.sendGroupMsg(group_id, `${this.Bot.CQCode.at(user_id)}${msg}`)
} else {
this.Bot.Api.sendPrivateMsg(user_id, msg)
}
this.banlist.add(user_id)
const user = group_id ? `(${group_id}) - (${user_id})` : `(${user_id})`
this.Bot.Log.logWarning(`${user}被禁用${time}分钟`, 'BAN')
this.Bot.Log.logWarning(`${user} 被禁用 ${time} 分钟`, 'BAN')
scheduleJob('ban' + user_id.toString(), new Date(Date.now() + time * 60 * 1000), () => {
if (this.banlist.has(user_id)) {
this.banlist.delete(user_id)
this.Bot.Log.logWarning(`${user}已解除禁用`, 'BAN')
this.Bot.Log.logWarning(`${user} 已解除禁用`, 'BAN')
if (group_id) {
this.Bot.Api.sendGroupMsg(group_id, `${this.Bot.CQCode.at(user_id)}放过你了,下次别这样了`)
this.Bot.Api.sendGroupMsg(group_id, this.Bot.Data.config.admin.group_lift_ban.replace('[id]', this.Bot.CQCode.at(user_id)))
} else {
this.Bot.Api.sendPrivateMsg(user_id, '放过你了,下次别这样了')
this.Bot.Api.sendPrivateMsg(user_id, this.Bot.Data.config.admin.private_lift_ban)
}
}
})
Expand All @@ -60,14 +56,15 @@ export class Admin {
cancelJob('ban' + user_id.toString())
if (this.banlist.has(user_id)) {
this.banlist.delete(user_id)
this.Bot.Log.logWarning(`${user_id}已解除禁用`, 'BAN')
this.Bot.Log.logWarning(`${user_id} 已解除禁用`, 'BAN')
}
}

isBan(user_id: number | null) {
return this.banlist.has(user_id)
}

/** 增加白名单列表,请勿和黑名单同时使用 */
addWhitelist(group_list: number[]) {
if (group_list.length < 1) return
if (this.Bot.Conn.blacklist.size > 0) {
Expand All @@ -77,9 +74,7 @@ export class Admin {
this.Bot.Conn.whitelist = new Set(([...this.Bot.Conn.whitelist, ...group_list]))
}

/**
* 增加黑名单列表,请勿和白名单同时使用
*/
/** 增加黑名单列表,请勿和白名单同时使用 */
addBlacklist(group_list: number[]) {
if (group_list.length < 1) return
if (this.Bot.Conn.whitelist.size > 0) {
Expand Down
11 changes: 11 additions & 0 deletions src/Bot/modules/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export class Data {
*/
userId: number = -1

/**
* Bot的配置
*/
config = {
admin: {
ban: '无路赛,禁用你所有功能[time]分钟',
group_lift_ban: '[id]放过你了,下次别这样了',
private_lift_ban: '放过你了,下次别这样了'
}
}

/**
* 群名缓存
*/
Expand Down

0 comments on commit 577c0af

Please sign in to comment.