Add simple limit enforcing
For now it is 25 messages in the last 24 horus.
This commit is contained in:
parent
a66115c3b8
commit
1c49e8b730
1 changed files with 35 additions and 0 deletions
35
src/index.ts
35
src/index.ts
|
@ -30,6 +30,41 @@ discord.on("messageCreate", async message => {
|
|||
if (message.author.bot) return;
|
||||
if (!message.mentions.has(message.client.user)) return;
|
||||
|
||||
const userLimits = await database.limits.findUnique({
|
||||
where: {
|
||||
user: BigInt(message.author.id)
|
||||
}
|
||||
});
|
||||
|
||||
let limit = 25;
|
||||
|
||||
if (userLimits?.limit) {
|
||||
limit = userLimits.limit;
|
||||
}
|
||||
|
||||
if (!userLimits?.vip) {
|
||||
const usedLimit = await database.usage.count({
|
||||
select: { _all: true },
|
||||
where: {
|
||||
user: BigInt(message.author.id),
|
||||
timestamp: {
|
||||
gte: new Date(message.createdTimestamp - 1000*60*60*24 /*24 hours */)
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
if (usedLimit._all >= limit) {
|
||||
message.react("🛑");
|
||||
message.author.dmChannel?.send({
|
||||
embeds: [{
|
||||
color: 0xff0000,
|
||||
description: `You've used up your message limit for today, ${limit} requrests in last 24 hours`
|
||||
}]
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const messagesForChannel = channelsRunning.ensure(message.channelId, () => {return [] as DiscordApi.Message[];} );
|
||||
const shouldStart = messagesForChannel.length == 0;
|
||||
messagesForChannel.push(message);
|
||||
|
|
Loading…
Reference in a new issue