diff --git a/src/NadekoBot/Attributes/NadekoModule.cs b/src/NadekoBot/Attributes/NadekoModuleAttribute.cs similarity index 100% rename from src/NadekoBot/Attributes/NadekoModule.cs rename to src/NadekoBot/Attributes/NadekoModuleAttribute.cs diff --git a/src/NadekoBot/DataStructures/AsyncLazy.cs b/src/NadekoBot/DataStructures/AsyncLazy.cs new file mode 100644 index 00000000..40800755 --- /dev/null +++ b/src/NadekoBot/DataStructures/AsyncLazy.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.DataStructures +{ + public class AsyncLazy : Lazy> + { + public AsyncLazy(Func valueFactory) : + base(() => Task.Factory.StartNew(valueFactory)) + { } + + public AsyncLazy(Func> taskFactory) : + base(() => Task.Factory.StartNew(taskFactory).Unwrap()) + { } + + public TaskAwaiter GetAwaiter() { return Value.GetAwaiter(); } + } + +} diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 3f52ac17..405485dd 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -16,7 +16,7 @@ using NLog; namespace NadekoBot.Modules.Administration { [NadekoModule("Administration", ".")] - public partial class Administration : NadekoModule + public partial class Administration : NadekoTopLevelModule { private static ConcurrentHashSet deleteMessagesOnCommand { get; } diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 95c4538a..88d512e7 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -1068,7 +1068,7 @@ namespace NadekoBot.Modules.Administration public static class GuildExtensions { public static string GetLogText(this IGuild guild, string key, params object[] replacements) - => NadekoModule.GetTextStatic(key, + => NadekoTopLevelModule.GetTextStatic(key, NadekoBot.Localization.GetCultureInfo(guild), typeof(Administration).Name.ToLowerInvariant(), replacements); diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index 37f07efa..043a12b2 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -17,7 +17,7 @@ using NLog; namespace NadekoBot.Modules.ClashOfClans { [NadekoModule("ClashOfClans", ",")] - public class ClashOfClans : NadekoModule + public class ClashOfClans : NadekoTopLevelModule { public static ConcurrentDictionary> ClashWars { get; set; } = new ConcurrentDictionary>(); diff --git a/src/NadekoBot/Modules/ClashOfClans/Extensions.cs b/src/NadekoBot/Modules/ClashOfClans/Extensions.cs index 032d3bcd..5756d3db 100644 --- a/src/NadekoBot/Modules/ClashOfClans/Extensions.cs +++ b/src/NadekoBot/Modules/ClashOfClans/Extensions.cs @@ -135,7 +135,7 @@ namespace NadekoBot.Modules.ClashOfClans public static string Localize(this ClashWar cw, string key) { - return NadekoModule.GetTextStatic(key, + return NadekoTopLevelModule.GetTextStatic(key, NadekoBot.Localization.GetCultureInfo(cw.Channel?.GuildId), typeof(ClashOfClans).Name.ToLowerInvariant()); } diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index ebeb4922..efd3717e 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -17,7 +17,7 @@ using NadekoBot.DataStructures; namespace NadekoBot.Modules.CustomReactions { [NadekoModule("CustomReactions", ".")] - public class CustomReactions : NadekoModule + public class CustomReactions : NadekoTopLevelModule { private static CustomReaction[] _globalReactions = new CustomReaction[] { }; public static CustomReaction[] GlobalReactions => _globalReactions; diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 39c749d2..040e657e 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -272,12 +272,12 @@ namespace NadekoBot.Modules.Gambling } private string GetText(string text) - => NadekoModule.GetTextStatic(text, + => NadekoTopLevelModule.GetTextStatic(text, NadekoBot.Localization.GetCultureInfo(_raceChannel.Guild), typeof(Gambling).Name.ToLowerInvariant()); private string GetText(string text, params object[] replacements) - => NadekoModule.GetTextStatic(text, + => NadekoTopLevelModule.GetTextStatic(text, NadekoBot.Localization.GetCultureInfo(_raceChannel.Guild), typeof(Gambling).Name.ToLowerInvariant(), replacements); diff --git a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index a75827e7..721b5b4e 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -10,6 +10,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using ImageSharp.Formats; using Image = ImageSharp.Image; namespace NadekoBot.Modules.Gambling @@ -35,7 +36,7 @@ namespace NadekoBot.Modules.Gambling var imageStream = await Task.Run(() => { var ms = new MemoryStream(); - new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms); + new[] { GetDice(num1), GetDice(num2) }.Merge().Save(ms); ms.Position = 0; return ms; }).ConfigureAwait(false); @@ -120,7 +121,7 @@ namespace NadekoBot.Modules.Gambling var bitmap = dice.Merge(); var ms = new MemoryStream(); - bitmap.SaveAsPng(ms); + bitmap.Save(ms); ms.Position = 0; await Context.Channel.SendFileAsync(ms, "dice.png", Context.User.Mention + diff --git a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs index 7471f7d0..b7a68ece 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs @@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Gambling images.Add(new Image(stream)); } MemoryStream bitmapStream = new MemoryStream(); - images.Merge().SaveAsPng(bitmapStream); + images.Merge().Save(bitmapStream); bitmapStream.Position = 0; var toSend = $"{Context.User.Mention}"; if (cardObjects.Count == 5) diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs index 973bc90e..40b8a735 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs @@ -52,17 +52,22 @@ namespace NadekoBot.Modules.Gambling return; } var imgs = new Image[count]; - using (var heads = _images.Heads.ToStream()) - using(var tails = _images.Tails.ToStream()) + for (var i = 0; i < count; i++) { - for (var i = 0; i < count; i++) + using (var heads = _images.Heads.ToStream()) + using (var tails = _images.Tails.ToStream()) { - imgs[i] = rng.Next(0, 10) < 5 ? - new Image(heads) : - new Image(tails); + if (rng.Next(0, 10) < 5) + { + imgs[i] = new Image(heads); + } + else + { + imgs[i] = new Image(tails); + } } - await Context.Channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false); } + await Context.Channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Modules/Gambling/Commands/Slots.cs b/src/NadekoBot/Modules/Gambling/Commands/Slots.cs index c298a9b4..ea20b4b1 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/Slots.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/Slots.cs @@ -1,5 +1,6 @@ using Discord; using Discord.Commands; +using ImageSharp; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services; @@ -163,83 +164,43 @@ namespace NadekoBot.Modules.Gambling var result = SlotMachine.Pull(); int[] numbers = result.Numbers; - using (var bgPixels = bgImage.Lock()) + + for (int i = 0; i < 3; i++) { - for (int i = 0; i < 3; i++) + using (var file = _images.SlotEmojis[numbers[i]].ToStream()) + using (var randomImage = new ImageSharp.Image(file)) { - using (var file = _images.SlotEmojis[numbers[i]].ToStream()) - { - var randomImage = new ImageSharp.Image(file); - using (var toAdd = randomImage.Lock()) - { - for (int j = 0; j < toAdd.Width; j++) - { - for (int k = 0; k < toAdd.Height; k++) - { - var x = 95 + 142 * i + j; - int y = 330 + k; - var toSet = toAdd[j, k]; - if (toSet.A < _alphaCutOut) - continue; - bgPixels[x, y] = toAdd[j, k]; - } - } - } - } + bgImage.DrawImage(randomImage, 100, default(Size), new Point(95 + 142 * i, 330)); } - - var won = amount * result.Multiplier; - var printWon = won; - var n = 0; - do - { - var digit = printWon % 10; - using (var fs = NadekoBot.Images.SlotNumbers[digit].ToStream()) - { - var img = new ImageSharp.Image(fs); - using (var pixels = img.Lock()) - { - for (int i = 0; i < pixels.Width; i++) - { - for (int j = 0; j < pixels.Height; j++) - { - if (pixels[i, j].A < _alphaCutOut) - continue; - var x = 230 - n * 16 + i; - bgPixels[x, 462 + j] = pixels[i, j]; - } - } - } - } - n++; - } while ((printWon /= 10) != 0); - - var printAmount = amount; - n = 0; - do - { - var digit = printAmount % 10; - using (var fs = _images.SlotNumbers[digit].ToStream()) - { - var img = new ImageSharp.Image(fs); - using (var pixels = img.Lock()) - { - for (int i = 0; i < pixels.Width; i++) - { - for (int j = 0; j < pixels.Height; j++) - { - if (pixels[i, j].A < _alphaCutOut) - continue; - var x = 395 - n * 16 + i; - bgPixels[x, 462 + j] = pixels[i, j]; - } - } - } - } - n++; - } while ((printAmount /= 10) != 0); } + var won = amount * result.Multiplier; + var printWon = won; + var n = 0; + do + { + var digit = printWon % 10; + using (var fs = NadekoBot.Images.SlotNumbers[digit].ToStream()) + using (var img = new ImageSharp.Image(fs)) + { + bgImage.DrawImage(img, 100, default(Size), new Point(230 - n * 16, 462)); + } + n++; + } while ((printWon /= 10) != 0); + + var printAmount = amount; + n = 0; + do + { + var digit = printAmount % 10; + using (var fs = _images.SlotNumbers[digit].ToStream()) + using (var img = new ImageSharp.Image(fs)) + { + bgImage.DrawImage(img, 100, default(Size), new Point(395 - n * 16, 462)); + } + n++; + } while ((printAmount /= 10) != 0); + var msg = GetText("better_luck"); if (result.Multiplier != 0) { diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 3cdd7165..0db8e198 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -12,7 +12,7 @@ using System.Collections.Generic; namespace NadekoBot.Modules.Gambling { [NadekoModule("Gambling", "$")] - public partial class Gambling : NadekoModule + public partial class Gambling : NadekoTopLevelModule { public static string CurrencyName { get; set; } public static string CurrencyPluralName { get; set; } diff --git a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs index 088b95d7..aa11f1c6 100644 --- a/src/NadekoBot/Modules/Games/Commands/Acropobia.cs +++ b/src/NadekoBot/Modules/Games/Commands/Acropobia.cs @@ -299,7 +299,7 @@ $@"-- } private string GetText(string key, params object[] replacements) - => NadekoModule.GetTextStatic(key, + => NadekoTopLevelModule.GetTextStatic(key, NadekoBot.Localization.GetCultureInfo(_channel.Guild), typeof(Games).Name.ToLowerInvariant()); } diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index b6b9130b..88a663df 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -4,18 +4,33 @@ using NadekoBot.Services; using System.Threading.Tasks; using NadekoBot.Attributes; using System; +using System.Collections.Concurrent; using System.Linq; using System.Collections.Generic; using System.Collections.Immutable; +using System.IO; +using System.Threading; using NadekoBot.Extensions; +using System.Net.Http; +using ImageSharp; +using NadekoBot.DataStructures; +using NLog; +using ImageSharp.Drawing.Pens; +using SixLabors.Shapes; namespace NadekoBot.Modules.Games { [NadekoModule("Games", ">")] - public partial class Games : NadekoModule + public partial class Games : NadekoTopLevelModule { private static readonly ImmutableArray _8BallResponses = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray(); + private static readonly Timer _t = new Timer((_) => + { + _girlRatings.Clear(); + + }, null, TimeSpan.FromDays(1), TimeSpan.FromDays(1)); + [NadekoCommand, Usage, Description, Aliases] public async Task Choose([Remainder] string list = null) { @@ -91,6 +106,155 @@ namespace NadekoBot.Modules.Games await Context.Channel.SendConfirmAsync(msg).ConfigureAwait(false); } + private static readonly ConcurrentDictionary _girlRatings = new ConcurrentDictionary(); + + public class GirlRating + { + private static Logger _log = LogManager.GetCurrentClassLogger(); + + public double Crazy { get; } + public double Hot { get; } + public int Roll { get; } + public string Advice { get; } + public AsyncLazy Url { get; } + + public GirlRating(double crazy, double hot, int roll, string advice) + { + Crazy = crazy; + Hot = hot; + Roll = roll; + Advice = advice; // convenient to have it here, even though atm there are only few different ones. + + Url = new AsyncLazy(async () => + { + try + { + using (var ms = new MemoryStream(NadekoBot.Images.WifeMatrix.ToArray(), false)) + using (var img = new ImageSharp.Image(ms)) + { + var clr = new ImageSharp.Color(0x0000ff); + const int minx = 35; + const int miny = 385; + const int length = 345; + + var pointx = (int)(minx + length * (Hot / 10)); + var pointy = (int)(miny - length * ((Crazy - 4) / 6)); + + var p = new Pen(ImageSharp.Color.Red, 5); + + img.Draw(p, new SixLabors.Shapes.Ellipse(200, 200, 5, 5)); + + string url; + using (var http = new HttpClient()) + using (var imgStream = new MemoryStream()) + { + img.Save(imgStream); + var byteContent = new ByteArrayContent(imgStream.ToArray()); + http.AddFakeHeaders(); + + var reponse = await http.PutAsync("https://transfer.sh/img.png", byteContent); + url = await reponse.Content.ReadAsStringAsync(); + } + return url; + } + } + catch (Exception ex) + { + _log.Warn(ex); + return null; + } + }); + } + } + + //[NadekoCommand, Usage, Description, Aliases] + //[RequireContext(ContextType.Guild)] + //public async Task RateGirl(IGuildUser usr) + //{ + // var gr = _girlRatings.GetOrAdd(usr.Id, GetGirl); + // var img = await gr.Url; + // await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() + // .WithTitle("Girl Rating For " + usr) + // .AddField(efb => efb.WithName("Hot").WithValue(gr.Hot.ToString("F2")).WithIsInline(true)) + // .AddField(efb => efb.WithName("Crazy").WithValue(gr.Crazy.ToString("F2")).WithIsInline(true)) + // .AddField(efb => efb.WithName("Advice").WithValue(gr.Advice).WithIsInline(false)) + // .WithImageUrl(img)).ConfigureAwait(false); + //} + + private double NextDouble(double x, double y) + { + var rng = new Random(); + return rng.NextDouble() * (y - x) + x; + } + + private GirlRating GetGirl(ulong uid) + { + var rng = new NadekoRandom(); + + var roll = rng.Next(1, 1001); + + double hot; + double crazy; + string advice; + if (roll < 500) + { + hot = NextDouble(0, 5); + crazy = NextDouble(4, 10); + advice = + "This is your NO-GO ZONE. We do not hang around, and date, and marry women who are atleast, in our mind, a 5. " + + "So, this is your no-go zone. You don't go here. You just rule this out. Life is better this way, that's the way it is."; + } + else if (roll < 750) + { + hot = NextDouble(5, 8); + crazy = NextDouble(4, .6 * hot + 4); + advice = "Above a 5, and to about an 8, and below the crazy line - this is your FUN ZONE. You can " + + "hang around here, and meet these girls and spend time with them. Keep in mind, while you're " + + "in the fun zone, you want to move OUT of the fun zone to a more permanent location. " + + "These girls are most of the time not crazy."; + } + else if (roll < 900) + { + hot = NextDouble(5, 10); + crazy = NextDouble(.61 * hot + 4, 10); + advice = "Above the crazy line - it's the DANGER ZONE. This is redheads, strippers, anyone named Tiffany, " + + "hairdressers... This is where your car gets keyed, you get bunny in the pot, your tires get slashed, " + + "and you wind up in jail."; + } + else if (roll < 951) + { + hot = NextDouble(8, 10); + crazy = NextDouble(4, 10); + advice = "Below the crazy line, above an 8 hot, but still about 7 crazy. This is your DATE ZONE. " + + "You can stay in the date zone indefinitely. These are the girls you introduce to your friends and your family. " + + "They're good looking, and they're reasonably not crazy most of the time. You can stay here indefinitely."; + } + else if (roll < 990) + { + hot = NextDouble(8, 10); + crazy = NextDouble(5, 7); + advice = "Above an 8 hot, and between about 7 and a 5 crazy - this is WIFE ZONE. You you meet this girl, you should consider long-term " + + "relationship. Rare."; + } + else if (roll < 999) + { + hot = NextDouble(8, 10); + crazy = NextDouble(2, 3.99d); + advice = "You've met a girl she's above 8 hot, and not crazy at all (below 4)... totally cool?" + + " You should be careful. That's a dude. It's a tranny."; + } + else + { + hot = NextDouble(8, 10); + crazy = NextDouble(4, 5); + advice = "Below 5 crazy, and above 8 hot, this is the UNICORN ZONE, these things don't exist." + + "If you find a unicorn, please capture it safely, keep it alive, we'd like to study it, " + + "and maybe look at how to replicate that."; + } + + return new GirlRating(crazy, hot, roll, advice); + } + [NadekoCommand, Usage, Description, Aliases] public async Task Linux(string guhnoo, string loonix) { diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index c22a9789..d6ceb1bd 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -13,7 +13,7 @@ using System.Collections.Generic; namespace NadekoBot.Modules.Help { [NadekoModule("Help", "-")] - public class Help : NadekoModule + public class Help : NadekoTopLevelModule { private static string helpString { get; } = NadekoBot.BotConfig.HelpString; public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 4fbc8701..a7b46269 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Music { [NadekoModule("Music", "!!")] [DontAutoLoad] - public partial class Music : NadekoModule + public partial class Music : NadekoTopLevelModule { public static ConcurrentDictionary MusicPlayers { get; } = new ConcurrentDictionary(); diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 5538e8d6..53a3f3bb 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -17,7 +17,7 @@ using System.Collections.Concurrent; namespace NadekoBot.Modules.NSFW { [NadekoModule("NSFW", "~")] - public class NSFW : NadekoModule + public class NSFW : NadekoTopLevelModule { private static readonly ConcurrentDictionary AutoHentaiTimers = new ConcurrentDictionary(); diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index d76a483c..ea4a0049 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace NadekoBot.Modules { - public abstract class NadekoModule : ModuleBase + public abstract class NadekoTopLevelModule : ModuleBase { protected readonly Logger _log; protected CultureInfo _cultureInfo; @@ -17,7 +17,7 @@ namespace NadekoBot.Modules public readonly string ModuleTypeName; public readonly string LowerModuleTypeName; - protected NadekoModule(bool isTopLevelModule = true) + protected NadekoTopLevelModule(bool isTopLevelModule = true) { //if it's top level module ModuleTypeName = isTopLevelModule ? this.GetType().Name : this.GetType().DeclaringType.Name; @@ -120,7 +120,7 @@ namespace NadekoBot.Modules } } - public abstract class NadekoSubmodule : NadekoModule + public abstract class NadekoSubmodule : NadekoTopLevelModule { protected NadekoSubmodule() : base(false) { diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 407ca2a2..3e8ecd13 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -15,7 +15,7 @@ using NLog; namespace NadekoBot.Modules.Permissions { [NadekoModule("Permissions", ";")] - public partial class Permissions : NadekoModule + public partial class Permissions : NadekoTopLevelModule { public class PermissionCache { diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index 08d3976f..c81091c7 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -16,7 +16,7 @@ using System.Collections.Concurrent; namespace NadekoBot.Modules.Pokemon { [NadekoModule("Pokemon", ">")] - public class Pokemon : NadekoModule + public class Pokemon : NadekoTopLevelModule { private static readonly List _pokemonTypes = new List(); private static readonly ConcurrentDictionary _stats = new ConcurrentDictionary(); diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 28a00413..ef47301c 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -1,5 +1,4 @@ using Discord; -using Discord.Commands; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -8,27 +7,25 @@ using System.Text; using System.Net.Http; using NadekoBot.Services; using System.Threading.Tasks; -using NadekoBot.Attributes; -using System.Text.RegularExpressions; using System.Net; using NadekoBot.Modules.Searches.Models; using System.Collections.Generic; -using ImageSharp; using NadekoBot.Extensions; using System.IO; using NadekoBot.Modules.Searches.Commands.OMDB; using NadekoBot.Modules.Searches.Commands.Models; -using AngleSharp.Parser.Html; using AngleSharp; using AngleSharp.Dom.Html; using AngleSharp.Dom; using System.Xml; -using System.Xml.Linq; +using Configuration = AngleSharp.Configuration; +using NadekoBot.Attributes; +using Discord.Commands; namespace NadekoBot.Modules.Searches { [NadekoModule("Searches", "~")] - public partial class Searches : NadekoModule + public partial class Searches : NadekoTopLevelModule { [NadekoCommand, Usage, Description, Aliases] public async Task Weather([Remainder] string query) @@ -396,7 +393,7 @@ namespace NadekoBot.Modules.Searches msg = "⚠ Found over 4 images. Showing random 4."; } var ms = new MemoryStream(); - await Task.Run(() => images.AsEnumerable().Merge().SaveAsPng(ms)); + await Task.Run(() => images.AsEnumerable().Merge().Save(ms)); ms.Position = 0; await Context.Channel.SendFileAsync(ms, arg + ".png", msg).ConfigureAwait(false); } @@ -625,7 +622,7 @@ namespace NadekoBot.Modules.Searches return; var img = new ImageSharp.Image(50, 50); - img.BackgroundColor(new ImageSharp.Color(color)); + //img.FillPolygon(new ImageSharp, new ImageSharp.Color(color)); await Context.Channel.SendFileAsync(img.ToStream(), $"{color}.png").ConfigureAwait(false); ; } diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index d627d956..8d3a95c4 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading.Tasks; using System.Text; using NadekoBot.Extensions; -using System.Text.RegularExpressions; using System.Reflection; using NadekoBot.Services.Impl; using System.Net.Http; @@ -21,7 +20,7 @@ using NadekoBot.Services; namespace NadekoBot.Modules.Utility { [NadekoModule("Utility", ".")] - public partial class Utility : NadekoModule + public partial class Utility : NadekoTopLevelModule { private static ConcurrentDictionary rotatingRoleColors = new ConcurrentDictionary(); @@ -122,10 +121,10 @@ namespace NadekoBot.Modules.Utility } return; } - + var hexColors = hexes.Select(hex => { - try { return (ImageSharp.Color?)new ImageSharp.Color(hex.Replace("#", "")); } catch { return null; } + try { return (ImageSharp.Color?)ImageSharp.Color.FromHex(hex.Replace("#", "")); } catch { return null; } }) .Where(c => c != null) .Select(c => c.Value) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 40d71602..7da895d6 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -60,6 +60,9 @@ namespace NadekoBot OkColor = new Color(Convert.ToUInt32(BotConfig.OkColor, 16)); ErrorColor = new Color(Convert.ToUInt32(BotConfig.ErrorColor, 16)); } + + //ImageSharp.Configuration.Default.AddImageFormat(new ImageSharp.Formats.PngFormat()); + //ImageSharp.Configuration.Default.AddImageFormat(new ImageSharp.Formats.JpegFormat()); } public async Task RunAsync(params string[] args) diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 579382ba..e6390b66 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -2381,33 +2381,6 @@ namespace NadekoBot.Resources { } } - /// - /// Looks up a localized string similar to qsearch. - /// - public static string searchquote_cmd { - get { - return ResourceManager.GetString("searchquote_cmd", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shows a random quote for a keyword that contains any text specified in the search.. - /// - public static string searchquote_desc { - get { - return ResourceManager.GetString("searchquote_desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to `{0}qsearch keyword text`. - /// - public static string searchquote_usage { - get { - return ResourceManager.GetString("searchquote_usage", resourceCulture); - } - } - /// /// Looks up a localized string similar to delmsgoncmd. /// @@ -5756,6 +5729,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to rategirl. + /// + public static string rategirl_cmd { + get { + return ResourceManager.GetString("rategirl_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Use the universal hot-crazy wife zone matrix to determine the girl's worth. It is everything young men need to know about women. At any moment in time, any woman you have previously located on this chart can vanish from that location and appear anywhere else on the chart.. + /// + public static string rategirl_desc { + get { + return ResourceManager.GetString("rategirl_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}rategirl @SomeGurl`. + /// + public static string rategirl_usage { + get { + return ResourceManager.GetString("rategirl_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to reloadimages. /// @@ -6701,6 +6701,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to qsearch. + /// + public static string searchquote_cmd { + get { + return ResourceManager.GetString("searchquote_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a random quote for a keyword that contains any text specified in the search.. + /// + public static string searchquote_desc { + get { + return ResourceManager.GetString("searchquote_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}qsearch keyword text`. + /// + public static string searchquote_usage { + get { + return ResourceManager.GetString("searchquote_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to send. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 732c0087..c661db7d 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1151,7 +1151,7 @@ `{0}qsearch keyword text` - + deletequote delq @@ -3141,4 +3141,13 @@ `{0}langli` - + + rategirl + + + Use the universal hot-crazy wife zone matrix to determine the girl's worth. It is everything young men need to know about women. At any moment in time, any woman you have previously located on this chart can vanish from that location and appear anywhere else on the chart. + + + `{0}rategirl @SomeGurl` + + \ No newline at end of file diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 90024cd2..c1eb0a5d 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -1170,9 +1170,42 @@ Don't forget to leave your discord name or id in the message. 8ball + + Acrophobia + + + Game ended with no submissions. + + + No votes cast. Game ended with no winner. + + + Acronym was {0}. + Acrophobia game is already running in this channel. + + Game started. Create a sentence with the following acronym: {0}. + + + You have {0} seconds to make a submission. + + + {0} submitted their sentence. ({1} total) + + + Vote by typing a number of the submission + + + {0} cast their vote! + + + Winner is {0} with {1} points. + + + {0} is the winner for being the only user who made a submission! + Question @@ -1182,4 +1215,7 @@ Don't forget to leave your discord name or id in the message. {0} won! {1} beats {2} + + Submissions Closed + \ No newline at end of file diff --git a/src/NadekoBot/Services/IImagesService.cs b/src/NadekoBot/Services/IImagesService.cs index 81e21907..e3b25458 100644 --- a/src/NadekoBot/Services/IImagesService.cs +++ b/src/NadekoBot/Services/IImagesService.cs @@ -21,6 +21,8 @@ namespace NadekoBot.Services ImmutableArray> SlotEmojis { get; } ImmutableArray> SlotNumbers { get; } + ImmutableArray WifeMatrix { get; } + Task Reload(); } } diff --git a/src/NadekoBot/Services/Impl/ImagesService.cs b/src/NadekoBot/Services/Impl/ImagesService.cs index 77ee9f26..567d63f2 100644 --- a/src/NadekoBot/Services/Impl/ImagesService.cs +++ b/src/NadekoBot/Services/Impl/ImagesService.cs @@ -28,6 +28,8 @@ namespace NadekoBot.Services.Impl private const string slotNumbersPath = basePath + "slots/numbers/"; private const string slotEmojisPath = basePath + "slots/emojis/"; + private const string _wifeMatrixPath = basePath + "wifematrix.png"; + public ImmutableArray Heads { get; private set; } public ImmutableArray Tails { get; private set; } @@ -41,6 +43,8 @@ namespace NadekoBot.Services.Impl public ImmutableArray> SlotNumbers { get; private set; } public ImmutableArray> SlotEmojis { get; private set; } + public ImmutableArray WifeMatrix { get; private set; } + private ImagesService() { _log = LogManager.GetCurrentClassLogger(); @@ -86,6 +90,8 @@ namespace NadekoBot.Services.Impl .Select(x => File.ReadAllBytes(x).ToImmutableArray()) .ToImmutableArray(); + WifeMatrix = File.ReadAllBytes(_wifeMatrixPath).ToImmutableArray(); + sw.Stop(); _log.Info($"Images loaded after {sw.Elapsed.TotalSeconds:F2}s!"); return sw.Elapsed; diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 4c32a542..8dbdf02b 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -22,7 +22,11 @@ namespace NadekoBot.Extensions private const string arrow_right = "➡"; public static Stream ToStream(this IEnumerable bytes, bool canWrite = false) - => new MemoryStream(bytes as byte[] ?? bytes.ToArray(), canWrite); + { + var ms = new MemoryStream(bytes as byte[] ?? bytes.ToArray(), canWrite); + ms.Seek(0, SeekOrigin.Begin); + return ms; + } /// /// danny kamisama @@ -398,22 +402,15 @@ namespace NadekoBot.Extensions public static ImageSharp.Image Merge(this IEnumerable images) { - var imgList = images.ToList(); + var imgs = images.ToArray(); - var canvas = new ImageSharp.Image(imgList.Sum(img => img.Width), imgList.Max(img => img.Height)); + var canvas = new ImageSharp.Image(imgs.Sum(img => img.Width), imgs.Max(img => img.Height)); - var canvasPixels = canvas.Lock(); - int offsetX = 0; - foreach (var img in imgList.Select(img => img.Lock())) + var xOffset = 0; + for (int i = 0; i < imgs.Length; i++) { - for (int i = 0; i < img.Width; i++) - { - for (int j = 0; j < img.Height; j++) - { - canvasPixels[i + offsetX, j] = img[i, j]; - } - } - offsetX += img.Width; + canvas.DrawImage(imgs[i], 100, default(Size), new Point(xOffset, 0)); + xOffset += imgs[i].Bounds.Width; } return canvas; @@ -422,7 +419,7 @@ namespace NadekoBot.Extensions public static Stream ToStream(this ImageSharp.Image img) { var imageStream = new MemoryStream(); - img.SaveAsPng(imageStream); + img.Save(imageStream); imageStream.Position = 0; return imageStream; } diff --git a/src/NadekoBot/data/images/wifematrix.png b/src/NadekoBot/data/images/wifematrix.png new file mode 100644 index 00000000..6e0b8db9 Binary files /dev/null and b/src/NadekoBot/data/images/wifematrix.png differ diff --git a/src/NadekoBot/project.json b/src/NadekoBot/project.json index 88ebdd52..d6b8ad6c 100644 --- a/src/NadekoBot/project.json +++ b/src/NadekoBot/project.json @@ -23,7 +23,12 @@ "Google.Apis.Urlshortener.v1": "1.19.0.138", "Google.Apis.YouTube.v3": "1.20.0.701", "Google.Apis.Customsearch.v1": "1.20.0.466", - "ImageSharp": "1.0.0-alpha-000079", + "ImageSharp": "1.0.0-alpha2-00090", + "ImageSharp.Processing": "1.0.0-alpha2-00078", + "ImageSharp.Formats.Png": "1.0.0-alpha2-00086", + "ImageSharp.Drawing": "1.0.0-alpha2-00090", + "ImageSharp.Drawing.Paths": "1.0.0-alpha2-00040", + //"ImageSharp.Formats.Jpeg": "1.0.0-alpha2-00090", "Microsoft.EntityFrameworkCore": "1.1.0", "Microsoft.EntityFrameworkCore.Design": "1.1.0", "Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",