From 9b26bd9ee5fd5ed305faf2b9e6ec72b35e4ef0df Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 24 Dec 2016 10:55:51 +0100 Subject: [PATCH] Can roll fate dice now with `$roll 5dF` --- .../Gambling/Commands/DiceRollCommand.cs | 39 +++++++++++++++++-- src/NadekoBot/Modules/Utility/Utility.cs | 2 + src/NadekoBot/Resources/CommandStrings.resx | 4 +- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index 7b2c8118..71e17453 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -19,6 +19,9 @@ namespace NadekoBot.Modules.Gambling public class DriceRollCommands { private Regex dndRegex { get; } = new Regex(@"^(?\d+)d(?\d+)(?:\+(?\d+))?(?:\-(?\d+))?$", RegexOptions.Compiled); + private Regex fudgeRegex { get; } = new Regex(@"^(?\d+)d(?:F|f)$", RegexOptions.Compiled); + + private readonly char[] fateRolls = new[] { '-', ' ', '+' }; [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] @@ -86,6 +89,17 @@ namespace NadekoBot.Modules.Gambling await InternallDndRoll(umsg, arg, false).ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task FateRoll(IUserMessage msg, string arg) + { + var channel = (ITextChannel)msg.Channel; + + int n1; + Match match; + + } + private async Task InternalRoll(IUserMessage umsg, int num, bool ordered) { var channel = (ITextChannel)umsg.Channel; @@ -141,12 +155,29 @@ namespace NadekoBot.Modules.Gambling if (channel == null) return; - var rng = new NadekoRandom(); Match match; - if ((match = dndRegex.Match(arg)).Length != 0) + int n1; + int n2; + if ((match = fudgeRegex.Match(arg)).Length != 0 && + int.TryParse(match.Groups["n1"].ToString(), out n1) && + n1 > 0 && n1 < 500) { - int n1; - int n2; + var rng = new NadekoRandom(); + + var rolls = new List(); + + for (int i = 0; i < n1; i++) + { + rolls.Add(fateRolls[rng.Next(0, fateRolls.Length)]); + } + var embed = new EmbedBuilder().WithOkColor().WithDescription($"{umsg.Author.Mention} rolled {n1} fate {(n1 == 1 ? "die" : "dice")}.") + .AddField(efb => efb.WithName(Format.Bold("Result")) + .WithValue(string.Join(" ", rolls.Select(c => Format.Code($"[{c}]"))))); + await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); + } + else if ((match = dndRegex.Match(arg)).Length != 0) + { + var rng = new NadekoRandom(); if (int.TryParse(match.Groups["n1"].ToString(), out n1) && int.TryParse(match.Groups["n2"].ToString(), out n2) && n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index f79e5fd1..5de70a5f 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -220,7 +220,9 @@ namespace NadekoBot.Modules.Utility .AddField(efb => efb.WithName(Format.Bold("Owner ID(s)")).WithValue(stats.OwnerIds).WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Uptime")).WithValue(stats.GetUptimeString("\n")).WithIsInline(true)) .AddField(efb => efb.WithName(Format.Bold("Presence")).WithValue($"{NadekoBot.Client.GetGuilds().Count} Servers\n{stats.TextChannels} Text Channels\n{stats.VoiceChannels} Voice Channels").WithIsInline(true)) +#if !GLOBAL_NADEKO .WithFooter(efb => efb.WithText($"Playing {Music.Music.MusicPlayers.Where(mp => mp.Value.CurrentSong != null).Count()} songs, {Music.Music.MusicPlayers.Sum(mp => mp.Value.Playlist.Count)} queued.")) +#endif .Build()); } diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 3289c998..fb067b65 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1192,10 +1192,10 @@ roll - Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice. If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. + Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice. If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y. Y can be a letter 'F' if you want to roll fate dice instead of dnd. - `{0}roll` or `{0}roll 7` or `{0}roll 3d5` + `{0}roll` or `{0}roll 7` or `{0}roll 3d5` or `{0}roll 5dF` rolluo