mirror of
				https://gitlab.com/ceda_ei/Quadnite-Bot
				synced 2025-10-31 17:20:05 +01:00 
			
		
		
		
	Add dice
This commit is contained in:
		
							
								
								
									
										31
									
								
								commands/dice.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								commands/dice.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| function diceRoll(side) { | ||||
|  | ||||
| 	return Math.ceil(Math.random() * side); | ||||
|  | ||||
| } | ||||
| module.exports = () => async (ctx) => { | ||||
|  | ||||
| 	const numDice = parseInt(ctx.match[1] || "1"); | ||||
| 	const diceSides = parseInt(ctx.match[2]); | ||||
| 	const rolls = Array(numDice) | ||||
| 		.fill(0) | ||||
| 		.map(() => diceRoll(diceSides)); | ||||
| 	const total = rolls.reduce((acc, curr) => acc + curr, 0); | ||||
| 	const message = rolls | ||||
| 		.map((i) => `_You roll a_ *D${diceSides}* _and get a_ *${i}*`) | ||||
| 		.join("\n"); | ||||
| 	let totalMessage = ""; | ||||
| 	if (numDice > 1 || ctx.match[3]) | ||||
| 		totalMessage = `*Total:* ${total}`; | ||||
|  | ||||
| 	if (ctx.match[3]) { | ||||
|  | ||||
| 		const modifier = parseInt(ctx.match[5]); | ||||
| 		const sign = ctx.match[4]; | ||||
| 		if (sign === "+") totalMessage += ` + ${modifier} = ${total + modifier}`; | ||||
| 		else totalMessage += ` - ${modifier} = ${total - modifier}`; | ||||
|  | ||||
| 	} | ||||
| 	ctx.reply(message + "\n\n" + totalMessage, { parse_mode: "Markdown" }); | ||||
|  | ||||
| }; | ||||
| @@ -10,6 +10,7 @@ const info = require("./info"); | ||||
| const expand = require("./expand"); | ||||
| const roleplay = require("./roleplay"); | ||||
| const suggest = require("./suggest"); | ||||
| const dice = require("./dice"); | ||||
|  | ||||
| module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay_data ], feedback_id, apiToken, ugokiRoot, axios) => { | ||||
|  | ||||
| @@ -69,6 +70,7 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay | ||||
| 	bot.command("donate", (ctx) => ctx.reply("Thanks for considering to donate." | ||||
| 		+ " To support the development and hosting of Quadnite Bot, you can " | ||||
| 		+ "donate here: https://liberapay.com/ceda_ei/")); | ||||
| 	bot.hears(/(\d*)d(\d+)(\s*([-+])\s*(\d+))?/, dice()); | ||||
|  | ||||
| 	function getGetGif(command) { | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user