add roll command

main
Sebastian Korotkiewicz 10 months ago
parent a084196c0e
commit 1d1a05d4ff
Signed by: grizzly
GPG Key ID: 5BDC557B496BDB0D

@ -3,7 +3,11 @@ const Help = (event) => {
let cmd = msg.match(/^,help (\w+)?$/);
if (!cmd || !cmd[1]) {
event.reply(",help commands - show all avalible commands");
event.reply(",help [command] for details, /? optional/");
event.reply("avalible commands:");
event.reply(" - ,w [set]? [location]? weather");
event.reply(" - ,r [min]? [max]? - roll a number");
event.reply(",help w");
return;
}
@ -14,10 +18,10 @@ const Help = (event) => {
event.reply(",w - after your save your location you can use ,w");
break;
case "commands":
event.reply(",help [command] for details");
event.reply("avalible commands: w");
event.reply(" ,help w");
case "r":
event.reply(",r - roll from 1 to 100");
event.reply(",r [max] - roll from 1 to {max}");
event.reply(",r [min] [max] - roll from {min} to {max}");
break;
default:

@ -0,0 +1,31 @@
const Roll = (event) => {
let msg = event.message;
let cmd1 = msg.match(/^,r (-?[0-9]+)$/);
let cmd2 = msg.match(/^,r (-?[0-9]+) (-?[0-9]+)$/);
const random = (min, max) => {
return Math.floor(
Math.random() * (Number(max) - Number(min) + 1) + Number(min)
);
};
if (/^,r$/.test(msg)) {
event.reply(`Roll from 1 to 100 => [ ${random(1, 100)} ]`);
//
} else if (/^,r (-?[0-9]+)$/.test(msg)) {
event.reply(
`Roll from 1 to ${cmd1[1].trim()} => [ ${random(1, cmd1[1].trim())} ]`
);
//
} else if (/^,r (-?[0-9]+) (-?[0-9]+)$/.test(msg)) {
event.reply(
`Roll from ${cmd2[1].trim()} to ${cmd2[2].trim()} => [ ${random(
cmd2[1].trim(),
cmd2[2].trim()
)} ]`
);
//
}
};
export default Roll;

@ -2,6 +2,7 @@ import { Client } from "irc-framework";
import InitDB from "./components/db.js";
import Weather from "./components/Weather.js";
import UrlTitle from "./components/UrlTitle.js";
import Roll from "./components/Roll.js";
import Help from "./components/Help.js";
InitDB();
@ -43,6 +44,10 @@ bot.matchMessage(/^,w/, async (event) => {
return Weather(event);
});
bot.matchMessage(/^,r/, async (event) => {
return Roll(event);
});
bot.matchMessage(/^,help/, (event) => {
return Help(event);
});

Loading…
Cancel
Save