Hopefuly fixed build. Added ~hs back. Good night

This commit is contained in:
Kwoth 2016-09-14 03:38:44 +02:00
parent 7267cf0ee7
commit a4cc1ab563
9 changed files with 340 additions and 301 deletions

View File

@ -40,11 +40,10 @@ namespace NadekoBot.Attributes
string prefix;
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
{
Console.WriteLine("Cache hit");
return prefix;
}
Console.WriteLine("Cache not hit for " + moduleName);
NLog.LogManager.GetCurrentClassLogger().Warn("Cache not hit for {0}", moduleName);
return null;
}
}

View File

@ -15,6 +15,9 @@ using System.Threading.Tasks;
namespace NadekoBot.Modules.Gambling
{
public partial class Gambling
{
[Group]
public class DriceRollCommands
{
private Regex dndRegex { get; } = new Regex(@"(?<n1>\d+)d(?<n2>\d+)", RegexOptions.Compiled);
@ -40,6 +43,36 @@ namespace NadekoBot.Modules.Gambling
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)]
@ -55,6 +88,7 @@ namespace NadekoBot.Modules.Gambling
{
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();
@ -93,40 +127,10 @@ namespace NadekoBot.Modules.Gambling
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);
}
//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 Rolluo(IUserMessage umsg, string arg = "")
public async Task Rolluo(IUserMessage umsg, string arg)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
@ -162,7 +166,7 @@ namespace NadekoBot.Modules.Gambling
if (channel == null)
return;
var ordered = true;
var ordered = false;
if (num < 1 || num > 30)
{
@ -242,7 +246,7 @@ namespace NadekoBot.Modules.Gambling
private Image GetDice(int num)
{
const string pathToImage = "data/images/dice";
if(num != 10)
if (num != 10)
{
using (var stream = File.OpenRead(Path.Combine(pathToImage, $"{num}.png")))
return new Image(stream);
@ -258,4 +262,5 @@ namespace NadekoBot.Modules.Gambling
}
}
}
}
}

View File

@ -62,7 +62,7 @@ namespace NadekoBot.Modules.NSFW
var channel = (ITextChannel)umsg.Channel;
tag = tag?.Trim() ?? "";
var link = await GetRule34ImageLink(tag).ConfigureAwait(false);
var link = await GetGelbooruImageLink(tag).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(link))
await channel.SendMessageAsync("Search yielded no results ;(");
else
@ -76,7 +76,7 @@ namespace NadekoBot.Modules.NSFW
var channel = (ITextChannel)umsg.Channel;
tag = tag?.Trim() ?? "";
var link = await GetGelbooruImageLink(tag).ConfigureAwait(false);
var link = await GetRule34ImageLink(tag).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(link))
await channel.SendMessageAsync("Search yielded no results ;(");
else

View File

@ -13,6 +13,10 @@ using System.Net;
using Discord.WebSocket;
using NadekoBot.Modules.Searches.Models;
using NadekoBot.Modules.Searches.IMDB;
using System.Collections.Generic;
using ImageProcessorCore;
using NadekoBot.Extensions;
using System.IO;
namespace NadekoBot.Modules.Searches
{
@ -199,51 +203,59 @@ $@"🌍 **Weather for** 【{obj["target"]}】
await channel.SendMessageAsync($"https://google.com/search?q={ WebUtility.UrlEncode(terms).Replace(' ', '+') }")
.ConfigureAwait(false);
}
////todo drawing
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
//{
// var channel = (ITextChannel)umsg.Channel;
// var arg = name;
// if (string.IsNullOrWhiteSpace(arg))
// {
// await channel.SendMessageAsync("💢 Please enter a card name to search for.").ConfigureAwait(false);
// return;
// }
// await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
// string response = "";
// using (var http = new HttpClient())
// {
// http.DefaultRequestHeaders.Clear();
// 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)
// .ConfigureAwait(false);
// try
// {
// var items = JArray.Parse(response).Shuffle().ToList();
// var images = new List<Image>();
// if (items == null)
// throw new KeyNotFoundException("Cannot find a card by that name");
// var cnt = 0;
// foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null))
// {
// images.Add(
// Image.FromStream(await http.GetStreamAsync(item["img"].ToString()).ConfigureAwait(false)));
// }
// if (items.Count > 4)
// {
// await channel.SendMessageAsync("⚠ Found over 4 images. Showing random 4.").ConfigureAwait(false);
// }
// await channel.SendMessageAsync(arg + ".png", (await images.MergeAsync()).ToStream(System.Drawing.Imaging.ImageFormat.Png))
// .ConfigureAwait(false);
// }
// catch (Exception ex)
// {
// await channel.SendMessageAsync($"💢 Error {ex.Message}").ConfigureAwait(false);
// }
// }
//}
//todo drawing
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
{
var channel = (ITextChannel)umsg.Channel;
var arg = name;
if (string.IsNullOrWhiteSpace(arg))
{
await channel.SendMessageAsync("💢 Please enter a card name to search for.").ConfigureAwait(false);
return;
}
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
string response = "";
using (var http = new HttpClient())
{
http.DefaultRequestHeaders.Clear();
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)}")
.ConfigureAwait(false);
try
{
var items = JArray.Parse(response).Shuffle().ToList();
var images = new List<Image>();
if (items == null)
throw new KeyNotFoundException("Cannot find a card by that name");
var cnt = 0;
foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null))
{
using (var sr =await http.GetStreamAsync(item["img"].ToString()))
{
var imgStream = new MemoryStream();
await sr.CopyToAsync(imgStream);
imgStream.Position = 0;
images.Add(new Image(imgStream));
}
}
string msg = null;
if (items.Count > 4)
{
msg = "⚠ Found over 4 images. Showing random 4.";
}
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]
[RequireContext(ContextType.Guild)]

View File

@ -13,6 +13,10 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using NLog.Fluent;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Microsoft.EntityFrameworkCore;
namespace NadekoBot
{
@ -52,12 +56,6 @@ namespace NadekoBot
CommandHandler = new CommandHandler(Client, Commands);
Stats = new StatsService(Client, CommandHandler);
//init db
using (var context = DbHandler.Instance.GetDbContext())
{
context.EnsureSeedData();
}
//setup DI
var depMap = new DependencyMap();
depMap.Add<ILocalization>(Localizer);

View 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>

View File

@ -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>
/// 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>
@ -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>
/// Looks up a localized string similar to Pulls the first image found using a search parameter. Use ~ir for different results..
/// </summary>

View File

@ -2205,13 +2205,13 @@
<data name="google_summary" xml:space="preserve">
<value>`~google query`</value>
</data>
<data name="hs_text" xml:space="preserve">
<value>hs</value>
<data name="hearthstone_text" xml:space="preserve">
<value>hearthstone hs</value>
</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>
</data>
<data name="hs_summary" xml:space="preserve">
<data name="hearthstone_summary" xml:space="preserve">
<value>`~hs Ysera`</value>
</data>
<data name="urbandict_text" xml:space="preserve">

View File

@ -33,6 +33,12 @@ namespace NadekoBot.Services.Database
public DbSet<RaceAnimal> RaceAnimals { get; set; }
public DbSet<ModulePrefix> ModulePrefixes { get; set; }
public NadekoContext()
{
this.Database.Migrate();
EnsureSeedData();
}
public void EnsureSeedData()
{
if (!BotConfig.Any())