mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: 提升优先级匹配小程序 & 增加算法方法
This commit is contained in:
parent
cc3804d85e
commit
c89cf27fa6
@ -27,7 +27,7 @@ export class tools extends plugin {
|
||||
name: "R插件工具和学习类",
|
||||
dsc: "R插件工具相关指令",
|
||||
event: "message.group",
|
||||
priority: 500,
|
||||
priority: 300,
|
||||
rule: [
|
||||
{
|
||||
reg: `^(翻|trans)[${tools.Constants.existsTransKey}]`,
|
||||
|
@ -7,6 +7,26 @@ export default class TokenBucket {
|
||||
this.lastTime = new Date().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗令牌-一个桶
|
||||
* @param count
|
||||
* @return {boolean}
|
||||
*/
|
||||
consumeSingle(count = 1) {
|
||||
const now = new Date().getTime();
|
||||
const elapsed = now - this.lastTime;
|
||||
const addedTokens = elapsed * (this.rate / 1000 / 60); // 修改为每分钟生成的令牌数量
|
||||
this.tokens = Math.min(this.tokens + addedTokens, this.capacity);
|
||||
this.lastTime = now;
|
||||
|
||||
if (count <= this.tokens) {
|
||||
this.tokens -= count;
|
||||
return true; // 返回 true 表示请求被处理
|
||||
} else {
|
||||
return false; // 返回 false 表示请求被限流
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗令牌
|
||||
* @param id 用户id
|
||||
|
Loading…
x
Reference in New Issue
Block a user