Hopefuly fixed build. Added ~hs back. Good night
This commit is contained in:
parent
7267cf0ee7
commit
a4cc1ab563
@ -40,11 +40,10 @@ namespace NadekoBot.Attributes
|
|||||||
string prefix;
|
string prefix;
|
||||||
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
|
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cache hit");
|
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Cache not hit for " + moduleName);
|
NLog.LogManager.GetCurrentClassLogger().Warn("Cache not hit for {0}", moduleName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,245 +16,250 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
{
|
{
|
||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
[Group]
|
||||||
|
public class DriceRollCommands
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
|
||||||
[RequireContext(ContextType.Guild)]
|
|
||||||
public async Task Roll(IUserMessage umsg)
|
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
var rng = new NadekoRandom();
|
|
||||||
var gen = rng.Next(1, 101);
|
|
||||||
|
|
||||||
var num1 = gen / 10;
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
var num2 = gen % 10;
|
[RequireContext(ContextType.Guild)]
|
||||||
var imageStream = await Task.Run(() =>
|
public async Task Roll(IUserMessage umsg)
|
||||||
{
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
var rng = new NadekoRandom();
|
||||||
|
var gen = rng.Next(1, 101);
|
||||||
|
|
||||||
|
var num1 = gen / 10;
|
||||||
|
var num2 = gen % 10;
|
||||||
|
var imageStream = await Task.Run(() =>
|
||||||
|
{
|
||||||
|
var ms = new MemoryStream();
|
||||||
|
new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
return ms;
|
||||||
|
});
|
||||||
|
|
||||||
|
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
//todo merge into internallDndRoll and internalRoll
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Roll(IUserMessage umsg, string arg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ordered = true;
|
||||||
|
var rng = new NadekoRandom();
|
||||||
|
Match match;
|
||||||
|
if ((match = dndRegex.Match(arg)).Length != 0)
|
||||||
|
{
|
||||||
|
int n1;
|
||||||
|
int n2;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
var arr = new int[n1];
|
||||||
|
for (int i = 0; i < n1; i++)
|
||||||
|
{
|
||||||
|
arr[i] = rng.Next(1, n2 + 1);
|
||||||
|
}
|
||||||
|
var elemCnt = 0;
|
||||||
|
await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Roll(IUserMessage umsg, int num)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ordered = true;
|
||||||
|
|
||||||
|
if (num < 1 || num > 30)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
|
||||||
|
num = 30;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rng = new NadekoRandom();
|
||||||
|
|
||||||
|
var dice = new List<Image>(num);
|
||||||
|
var values = new List<int>(num);
|
||||||
|
for (var i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
var randomNumber = rng.Next(1, 7);
|
||||||
|
var toInsert = dice.Count;
|
||||||
|
if (ordered)
|
||||||
|
{
|
||||||
|
if (randomNumber == 6 || dice.Count == 0)
|
||||||
|
toInsert = 0;
|
||||||
|
else if (randomNumber != 1)
|
||||||
|
for (var j = 0; j < dice.Count; j++)
|
||||||
|
{
|
||||||
|
if (values[j] < randomNumber)
|
||||||
|
{
|
||||||
|
toInsert = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toInsert = dice.Count;
|
||||||
|
}
|
||||||
|
dice.Insert(toInsert, GetDice(randomNumber));
|
||||||
|
values.Insert(toInsert, randomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bitmap = dice.Merge();
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
|
bitmap.SaveAsPng(ms);
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
return ms;
|
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
|
||||||
});
|
|
||||||
|
|
||||||
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
|
||||||
[RequireContext(ContextType.Guild)]
|
|
||||||
public async Task Roll(IUserMessage umsg, int num)
|
|
||||||
{
|
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var ordered = true;
|
|
||||||
|
|
||||||
if (num < 1 || num > 30)
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
|
|
||||||
num = 30;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var rng = new NadekoRandom();
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
var dice = new List<Image>(num);
|
public async Task Rolluo(IUserMessage umsg, string arg)
|
||||||
var values = new List<int>(num);
|
|
||||||
for (var i = 0; i < num; i++)
|
|
||||||
{
|
{
|
||||||
var randomNumber = rng.Next(1, 7);
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
var toInsert = dice.Count;
|
if (channel == null)
|
||||||
if (ordered)
|
return;
|
||||||
{
|
|
||||||
if (randomNumber == 6 || dice.Count == 0)
|
|
||||||
toInsert = 0;
|
|
||||||
else if (randomNumber != 1)
|
|
||||||
for (var j = 0; j < dice.Count; j++)
|
|
||||||
{
|
|
||||||
if (values[j] < randomNumber)
|
|
||||||
{
|
|
||||||
toInsert = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
toInsert = dice.Count;
|
|
||||||
}
|
|
||||||
dice.Insert(toInsert, GetDice(randomNumber));
|
|
||||||
values.Insert(toInsert, randomNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
var bitmap = dice.Merge();
|
var ordered = false;
|
||||||
var ms = new MemoryStream();
|
var rng = new NadekoRandom();
|
||||||
bitmap.SaveAsPng(ms);
|
Match match;
|
||||||
ms.Position = 0;
|
if ((match = dndRegex.Match(arg)).Length != 0)
|
||||||
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
//todo merge into internallDndRoll and internalRoll
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
|
||||||
[RequireContext(ContextType.Guild)]
|
|
||||||
public async Task Roll(IUserMessage umsg, string arg = "")
|
|
||||||
{
|
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var ordered = true;
|
|
||||||
var rng = new NadekoRandom();
|
|
||||||
Match match;
|
|
||||||
if ((match = dndRegex.Match(arg)).Length != 0)
|
|
||||||
{
|
|
||||||
int n1;
|
|
||||||
int n2;
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
var arr = new int[n1];
|
int n1;
|
||||||
for (int i = 0; i < n1; i++)
|
int n2;
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
arr[i] = rng.Next(1, n2 + 1);
|
var arr = new int[n1];
|
||||||
}
|
for (int i = 0; i < n1; i++)
|
||||||
var elemCnt = 0;
|
|
||||||
await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
|
||||||
[RequireContext(ContextType.Guild)]
|
|
||||||
public async Task Rolluo(IUserMessage umsg, string arg = "")
|
|
||||||
{
|
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var ordered = false;
|
|
||||||
var rng = new NadekoRandom();
|
|
||||||
Match match;
|
|
||||||
if ((match = dndRegex.Match(arg)).Length != 0)
|
|
||||||
{
|
|
||||||
int n1;
|
|
||||||
int n2;
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
var arr = new int[n1];
|
|
||||||
for (int i = 0; i < n1; i++)
|
|
||||||
{
|
|
||||||
arr[i] = rng.Next(1, n2 + 1);
|
|
||||||
}
|
|
||||||
var elemCnt = 0;
|
|
||||||
await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
|
||||||
[RequireContext(ContextType.Guild)]
|
|
||||||
public async Task Rolluo(IUserMessage umsg, int num)
|
|
||||||
{
|
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
|
||||||
if (channel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var ordered = true;
|
|
||||||
|
|
||||||
if (num < 1 || num > 30)
|
|
||||||
{
|
|
||||||
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
|
|
||||||
num = 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rng = new NadekoRandom();
|
|
||||||
|
|
||||||
var dice = new List<Image>(num);
|
|
||||||
var values = new List<int>(num);
|
|
||||||
for (var i = 0; i < num; i++)
|
|
||||||
{
|
|
||||||
var randomNumber = rng.Next(1, 7);
|
|
||||||
var toInsert = dice.Count;
|
|
||||||
if (ordered)
|
|
||||||
{
|
|
||||||
if (randomNumber == 6 || dice.Count == 0)
|
|
||||||
toInsert = 0;
|
|
||||||
else if (randomNumber != 1)
|
|
||||||
for (var j = 0; j < dice.Count; j++)
|
|
||||||
{
|
{
|
||||||
if (values[j] < randomNumber)
|
arr[i] = rng.Next(1, n2 + 1);
|
||||||
{
|
|
||||||
toInsert = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var elemCnt = 0;
|
||||||
|
await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Rolluo(IUserMessage umsg, int num)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
if (channel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ordered = false;
|
||||||
|
|
||||||
|
if (num < 1 || num > 30)
|
||||||
{
|
{
|
||||||
toInsert = dice.Count;
|
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
|
||||||
|
num = 30;
|
||||||
}
|
}
|
||||||
dice.Insert(toInsert, GetDice(randomNumber));
|
|
||||||
values.Insert(toInsert, randomNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
var bitmap = dice.Merge();
|
var rng = new NadekoRandom();
|
||||||
var ms = new MemoryStream();
|
|
||||||
bitmap.SaveAsPng(ms);
|
|
||||||
ms.Position = 0;
|
|
||||||
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
var dice = new List<Image>(num);
|
||||||
[RequireContext(ContextType.Guild)]
|
var values = new List<int>(num);
|
||||||
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
|
for (var i = 0; i < num; i++)
|
||||||
{
|
|
||||||
var channel = (ITextChannel)umsg.Channel;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int rolled;
|
|
||||||
if (range.Contains("-"))
|
|
||||||
{
|
{
|
||||||
var arr = range.Split('-')
|
var randomNumber = rng.Next(1, 7);
|
||||||
.Take(2)
|
var toInsert = dice.Count;
|
||||||
.Select(int.Parse)
|
if (ordered)
|
||||||
.ToArray();
|
{
|
||||||
if (arr[0] > arr[1])
|
if (randomNumber == 6 || dice.Count == 0)
|
||||||
throw new ArgumentException("First argument should be bigger than the second one.");
|
toInsert = 0;
|
||||||
rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
|
else if (randomNumber != 1)
|
||||||
|
for (var j = 0; j < dice.Count; j++)
|
||||||
|
{
|
||||||
|
if (values[j] < randomNumber)
|
||||||
|
{
|
||||||
|
toInsert = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toInsert = dice.Count;
|
||||||
|
}
|
||||||
|
dice.Insert(toInsert, GetDice(randomNumber));
|
||||||
|
values.Insert(toInsert, randomNumber);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var bitmap = dice.Merge();
|
||||||
|
var ms = new MemoryStream();
|
||||||
|
bitmap.SaveAsPng(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
|
int rolled;
|
||||||
|
if (range.Contains("-"))
|
||||||
|
{
|
||||||
|
var arr = range.Split('-')
|
||||||
|
.Take(2)
|
||||||
|
.Select(int.Parse)
|
||||||
|
.ToArray();
|
||||||
|
if (arr[0] > arr[1])
|
||||||
|
throw new ArgumentException("First argument should be bigger than the second one.");
|
||||||
|
rolled = new NadekoRandom().Next(arr[0], arr[1] + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($":anger: {ex.Message}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image GetDice(int num)
|
||||||
|
{
|
||||||
|
const string pathToImage = "data/images/dice";
|
||||||
|
if (num != 10)
|
||||||
|
{
|
||||||
|
using (var stream = File.OpenRead(Path.Combine(pathToImage, $"{num}.png")))
|
||||||
|
return new Image(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.SendMessageAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
|
using (var one = File.OpenRead(Path.Combine(pathToImage, "1.png")))
|
||||||
}
|
using (var zero = File.OpenRead(Path.Combine(pathToImage, "0.png")))
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
Image imgOne = new Image(one);
|
||||||
await channel.SendMessageAsync($":anger: {ex.Message}").ConfigureAwait(false);
|
Image imgZero = new Image(zero);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Image GetDice(int num)
|
return new[] { imgOne, imgZero }.Merge();
|
||||||
{
|
}
|
||||||
const string pathToImage = "data/images/dice";
|
|
||||||
if(num != 10)
|
|
||||||
{
|
|
||||||
using (var stream = File.OpenRead(Path.Combine(pathToImage, $"{num}.png")))
|
|
||||||
return new Image(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var one = File.OpenRead(Path.Combine(pathToImage, "1.png")))
|
|
||||||
using (var zero = File.OpenRead(Path.Combine(pathToImage, "0.png")))
|
|
||||||
{
|
|
||||||
Image imgOne = new Image(one);
|
|
||||||
Image imgZero = new Image(zero);
|
|
||||||
|
|
||||||
return new[] { imgOne, imgZero }.Merge();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
tag = tag?.Trim() ?? "";
|
tag = tag?.Trim() ?? "";
|
||||||
var link = await GetRule34ImageLink(tag).ConfigureAwait(false);
|
var link = await GetGelbooruImageLink(tag).ConfigureAwait(false);
|
||||||
if (string.IsNullOrWhiteSpace(link))
|
if (string.IsNullOrWhiteSpace(link))
|
||||||
await channel.SendMessageAsync("Search yielded no results ;(");
|
await channel.SendMessageAsync("Search yielded no results ;(");
|
||||||
else
|
else
|
||||||
@ -76,7 +76,7 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
|
||||||
tag = tag?.Trim() ?? "";
|
tag = tag?.Trim() ?? "";
|
||||||
var link = await GetGelbooruImageLink(tag).ConfigureAwait(false);
|
var link = await GetRule34ImageLink(tag).ConfigureAwait(false);
|
||||||
if (string.IsNullOrWhiteSpace(link))
|
if (string.IsNullOrWhiteSpace(link))
|
||||||
await channel.SendMessageAsync("Search yielded no results ;(");
|
await channel.SendMessageAsync("Search yielded no results ;(");
|
||||||
else
|
else
|
||||||
|
@ -13,6 +13,10 @@ using System.Net;
|
|||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using NadekoBot.Modules.Searches.Models;
|
using NadekoBot.Modules.Searches.Models;
|
||||||
using NadekoBot.Modules.Searches.IMDB;
|
using NadekoBot.Modules.Searches.IMDB;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ImageProcessorCore;
|
||||||
|
using NadekoBot.Extensions;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Searches
|
namespace NadekoBot.Modules.Searches
|
||||||
{
|
{
|
||||||
@ -199,51 +203,59 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
|
await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
////todo drawing
|
//todo drawing
|
||||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
//[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
//public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
|
public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
|
||||||
//{
|
{
|
||||||
// var channel = (ITextChannel)umsg.Channel;
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
// var arg = name;
|
var arg = name;
|
||||||
// if (string.IsNullOrWhiteSpace(arg))
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
// {
|
{
|
||||||
// await channel.SendMessageAsync("💢 Please enter a card name to search for.").ConfigureAwait(false);
|
await channel.SendMessageAsync("💢 Please enter a card name to search for.").ConfigureAwait(false);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||||
// string response = "";
|
string response = "";
|
||||||
// using (var http = new HttpClient())
|
using (var http = new HttpClient())
|
||||||
// {
|
{
|
||||||
// http.DefaultRequestHeaders.Clear();
|
http.DefaultRequestHeaders.Clear();
|
||||||
// http.DefaultRequestHeaders.Add("X-Mashape-Key", NadekoBot.Credentials.MashapeKey);
|
http.DefaultRequestHeaders.Add("X-Mashape-Key", NadekoBot.Credentials.MashapeKey);
|
||||||
// response = await http.GetStringAsync($"https://omgvamp-hearthstone-v1.p.mashape.com/cards/search/{Uri.EscapeUriString(arg)}", headers)
|
response = await http.GetStringAsync($"https://omgvamp-hearthstone-v1.p.mashape.com/cards/search/{Uri.EscapeUriString(arg)}")
|
||||||
// .ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// var items = JArray.Parse(response).Shuffle().ToList();
|
var items = JArray.Parse(response).Shuffle().ToList();
|
||||||
// var images = new List<Image>();
|
var images = new List<Image>();
|
||||||
// if (items == null)
|
if (items == null)
|
||||||
// throw new KeyNotFoundException("Cannot find a card by that name");
|
throw new KeyNotFoundException("Cannot find a card by that name");
|
||||||
// var cnt = 0;
|
var cnt = 0;
|
||||||
// foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null))
|
foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null))
|
||||||
// {
|
{
|
||||||
// images.Add(
|
using (var sr =await http.GetStreamAsync(item["img"].ToString()))
|
||||||
// Image.FromStream(await http.GetStreamAsync(item["img"].ToString()).ConfigureAwait(false)));
|
{
|
||||||
// }
|
var imgStream = new MemoryStream();
|
||||||
// if (items.Count > 4)
|
await sr.CopyToAsync(imgStream);
|
||||||
// {
|
imgStream.Position = 0;
|
||||||
// await channel.SendMessageAsync("⚠ Found over 4 images. Showing random 4.").ConfigureAwait(false);
|
images.Add(new Image(imgStream));
|
||||||
// }
|
}
|
||||||
// await channel.SendMessageAsync(arg + ".png", (await images.MergeAsync()).ToStream(System.Drawing.Imaging.ImageFormat.Png))
|
}
|
||||||
// .ConfigureAwait(false);
|
string msg = null;
|
||||||
// }
|
if (items.Count > 4)
|
||||||
// catch (Exception ex)
|
{
|
||||||
// {
|
msg = "⚠ Found over 4 images. Showing random 4.";
|
||||||
// await channel.SendMessageAsync($"💢 Error {ex.Message}").ConfigureAwait(false);
|
}
|
||||||
// }
|
var ms = new MemoryStream();
|
||||||
// }
|
images.Merge().SaveAsPng(ms);
|
||||||
//}
|
ms.Position = 0;
|
||||||
|
await channel.SendFileAsync(ms, arg + ".png", msg).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"💢 Error {ex.Message}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
|
@ -13,6 +13,10 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NLog.Fluent;
|
using NLog.Fluent;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
@ -52,12 +56,6 @@ namespace NadekoBot
|
|||||||
CommandHandler = new CommandHandler(Client, Commands);
|
CommandHandler = new CommandHandler(Client, Commands);
|
||||||
Stats = new StatsService(Client, CommandHandler);
|
Stats = new StatsService(Client, CommandHandler);
|
||||||
|
|
||||||
//init db
|
|
||||||
using (var context = DbHandler.Instance.GetDbContext())
|
|
||||||
{
|
|
||||||
context.EnsureSeedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
//setup DI
|
//setup DI
|
||||||
var depMap = new DependencyMap();
|
var depMap = new DependencyMap();
|
||||||
depMap.Add<ILocalization>(Localizer);
|
depMap.Add<ILocalization>(Localizer);
|
||||||
|
19
src/NadekoBot/NuGet.Config
Normal file
19
src/NadekoBot/NuGet.Config
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
<add key="Discord myget feed" value="https://www.myget.org/F/discord-net/api/v3/index.json" />
|
||||||
|
<add key="Image Processor" value="https://www.myget.org/F/imageprocessor/api/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
<disabledPackageSources>
|
||||||
|
<add key="Microsoft and .NET" value="true" />
|
||||||
|
</disabledPackageSources>
|
||||||
|
<packageRestore>
|
||||||
|
<add key="enabled" value="True" />
|
||||||
|
<add key="automatic" value="True" />
|
||||||
|
</packageRestore>
|
||||||
|
<bindingRedirects>
|
||||||
|
<add key="skip" value="False" />
|
||||||
|
</bindingRedirects>
|
||||||
|
</configuration>
|
54
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
54
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -3002,6 +3002,33 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Searches for a Hearthstone card and shows its image. Takes a while to complete..
|
||||||
|
/// </summary>
|
||||||
|
public static string hearthstone_desc {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("hearthstone_desc", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to `~hs Ysera`.
|
||||||
|
/// </summary>
|
||||||
|
public static string hearthstone_summary {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("hearthstone_summary", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to hearthstone hs.
|
||||||
|
/// </summary>
|
||||||
|
public static string hearthstone_text {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("hearthstone_text", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +).
|
/// Looks up a localized string similar to Shows a random NSFW hentai image from gelbooru and danbooru with a given tag. Tag is optional but preffered. (multiple tags are appended with +).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -3110,33 +3137,6 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Searches for a Hearthstone card and shows its image. Takes a while to complete..
|
|
||||||
/// </summary>
|
|
||||||
public static string hs_desc {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("hs_desc", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to `~hs Ysera`.
|
|
||||||
/// </summary>
|
|
||||||
public static string hs_summary {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("hs_summary", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to hs.
|
|
||||||
/// </summary>
|
|
||||||
public static string hs_text {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("hs_text", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Pulls the first image found using a search parameter. Use ~ir for different results..
|
/// Looks up a localized string similar to Pulls the first image found using a search parameter. Use ~ir for different results..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2205,13 +2205,13 @@
|
|||||||
<data name="google_summary" xml:space="preserve">
|
<data name="google_summary" xml:space="preserve">
|
||||||
<value>`~google query`</value>
|
<value>`~google query`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="hs_text" xml:space="preserve">
|
<data name="hearthstone_text" xml:space="preserve">
|
||||||
<value>hs</value>
|
<value>hearthstone hs</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="hs_desc" xml:space="preserve">
|
<data name="hearthstone_desc" xml:space="preserve">
|
||||||
<value>Searches for a Hearthstone card and shows its image. Takes a while to complete.</value>
|
<value>Searches for a Hearthstone card and shows its image. Takes a while to complete.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="hs_summary" xml:space="preserve">
|
<data name="hearthstone_summary" xml:space="preserve">
|
||||||
<value>`~hs Ysera`</value>
|
<value>`~hs Ysera`</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="urbandict_text" xml:space="preserve">
|
<data name="urbandict_text" xml:space="preserve">
|
||||||
|
@ -33,6 +33,12 @@ namespace NadekoBot.Services.Database
|
|||||||
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
public DbSet<RaceAnimal> RaceAnimals { get; set; }
|
||||||
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
|
||||||
|
|
||||||
|
public NadekoContext()
|
||||||
|
{
|
||||||
|
this.Database.Migrate();
|
||||||
|
EnsureSeedData();
|
||||||
|
}
|
||||||
|
|
||||||
public void EnsureSeedData()
|
public void EnsureSeedData()
|
||||||
{
|
{
|
||||||
if (!BotConfig.Any())
|
if (!BotConfig.Any())
|
||||||
|
Loading…
Reference in New Issue
Block a user