Skip to content

Commit

Permalink
fix plugin/rand: limit max draw count
Browse files Browse the repository at this point in the history
  • Loading branch information
91khr committed Dec 4, 2023
1 parent 172422d commit a4ec4b1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/plugins/rand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ function randnoid(app: App, msg: Message, msgTxt?: string) {
function dice(app: App, msg: Message, txt?: string) {
const sub = txt?.trim().match(/^(\d+)d(\d+)$/);
if (!sub || sub.length < 3) return void app.bot.sendMessage(msg.chat.id, '只支持xdy的格式');
if (Number(sub[1]) >= 128) return void app.bot.sendMessage(msg.chat.id, '投掷次数不能超过128');
const res = Array.from({ length: Number(sub[1]) }, () =>
Math.floor(Math.random() * Number(sub[2]))
Math.ceil(Math.random() * Number(sub[2]))
);
const sum = res.reduce((a, b) => a + b);
const sum = res.reduce((a, b) => a + b, 0);
void app.bot.sendMessage(msg.chat.id, `${getName(msg.from)} 掷出了${sum}: ${res.join(', ')}`);
}

Expand Down

0 comments on commit a4ec4b1

Please sign in to comment.