Merge remote-tracking branch 'refs/remotes/Kwoth/master'
This commit is contained in:
commit
2141431732
@ -91,7 +91,8 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
{
|
{
|
||||||
ch = e.Channel;
|
ch = e.Channel;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
ch = e.Server.FindChannels(meorchStr).FirstOrDefault();
|
ch = e.Server.FindChannels(meorchStr).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Gambling
|
namespace NadekoBot.Modules.Gambling
|
||||||
@ -19,13 +20,14 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
internal override void Init(CommandGroupBuilder cgb)
|
internal override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
cgb.CreateCommand(Module.Prefix + "roll")
|
cgb.CreateCommand(Module.Prefix + "roll")
|
||||||
.Description("Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice.\n**Usage**: $roll [x]")
|
.Description("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.\n**Usage**: $roll or $roll 7 or $roll 3d5")
|
||||||
.Parameter("num", ParameterType.Optional)
|
.Parameter("num", ParameterType.Optional)
|
||||||
.Do(Roll0to10Func());
|
.Do(RollFunc());
|
||||||
cgb.CreateCommand(Module.Prefix + "nroll")
|
cgb.CreateCommand(Module.Prefix + "nroll")
|
||||||
.Description("Rolls in a given range.\n**Usage**: `$nroll 5` (rolls 0-5) or `$nroll 5-15`")
|
.Description("Rolls in a given range.\n**Usage**: `$nroll 5` (rolls 0-5) or `$nroll 5-15`")
|
||||||
.Parameter("range", ParameterType.Required)
|
.Parameter("range", ParameterType.Required)
|
||||||
.Do(Roll0to5Func());
|
.Do(NRollFunc());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Image GetDice(int num) => num != 10
|
private Image GetDice(int num) => num != 10
|
||||||
@ -36,12 +38,15 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
(Properties.Resources.ResourceManager.GetObject("_" + 0) as Image),
|
(Properties.Resources.ResourceManager.GetObject("_" + 0) as Image),
|
||||||
}.Merge();
|
}.Merge();
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> Roll0to10Func()
|
|
||||||
|
Regex dndRegex = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||||
|
private Func<CommandEventArgs, Task> RollFunc()
|
||||||
{
|
{
|
||||||
var r = new Random();
|
var r = new Random();
|
||||||
return async e =>
|
return async e =>
|
||||||
{
|
{
|
||||||
if (e.Args[0] == "")
|
var arg = e.Args[0]?.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
{
|
{
|
||||||
var gen = r.Next(0, 101);
|
var gen = r.Next(0, 101);
|
||||||
|
|
||||||
@ -51,9 +56,27 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
var imageStream = new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png);
|
var imageStream = new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png);
|
||||||
|
|
||||||
await e.Channel.SendFile("dice.png", imageStream);
|
await e.Channel.SendFile("dice.png", imageStream);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
Match m;
|
||||||
|
if ((m = dndRegex.Match(arg)).Length != 0)
|
||||||
{
|
{
|
||||||
|
int n1;
|
||||||
|
int n2;
|
||||||
|
if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
||||||
|
int.TryParse(m.Groups["n2"].ToString(), out n2) &&
|
||||||
|
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
|
||||||
|
{
|
||||||
|
var arr = new int[n1];
|
||||||
|
for (int i = 0; i < n1; i++)
|
||||||
|
{
|
||||||
|
arr[i] = r.Next(1, n2 + 1);
|
||||||
|
}
|
||||||
|
var elemCnt = 0;
|
||||||
|
await e.Channel.SendMessage($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", arr.OrderBy(x => x).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString())));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var num = int.Parse(e.Args[0]);
|
var num = int.Parse(e.Args[0]);
|
||||||
@ -92,12 +115,11 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
await e.Channel.SendMessage("Please enter a number of dice to roll.");
|
await e.Channel.SendMessage("Please enter a number of dice to roll.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Func<CommandEventArgs, Task> Roll0to5Func() =>
|
private Func<CommandEventArgs, Task> NRollFunc() =>
|
||||||
async e =>
|
async e =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -360,17 +360,17 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await e.Channel.SendMessage("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆");
|
await e.Channel.SendMessage("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆");
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "magicitem")
|
cgb.CreateCommand(Prefix + "mi")
|
||||||
|
.Alias("magicitem")
|
||||||
.Description("Shows a random magicitem from <https://1d4chan.org/wiki/List_of_/tg/%27s_magic_items>")
|
.Description("Shows a random magicitem from <https://1d4chan.org/wiki/List_of_/tg/%27s_magic_items>")
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
var db =JsonConvert.DeserializeObject<List<MagicItem>>(File.ReadAllText("data/magicitems.json"));
|
var magicItems = JsonConvert.DeserializeObject<List<MagicItem>>(File.ReadAllText("data/magicitems.json"));
|
||||||
var item = db[rng.Next(0, db.Count)].ToString();
|
var item = magicItems[rng.Next(0, magicItems.Count)].ToString();
|
||||||
|
|
||||||
await e.Channel.SendMessage(item);
|
await e.Channel.SendMessage(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "revav")
|
cgb.CreateCommand(Prefix + "revav")
|
||||||
.Description("Returns a google reverse image search for someone's avatar.")
|
.Description("Returns a google reverse image search for someone's avatar.")
|
||||||
.Parameter("user", ParameterType.Unparsed)
|
.Parameter("user", ParameterType.Unparsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user