From db15d302b9280bfd8b9fb789665de980df1a01bc Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 19:24:09 +0200 Subject: [PATCH 1/7] Leave command --- .../Administration/AdministrationModule.cs | 2 + .../Administration/Commands/SelfCommands.cs | 49 +++++++++++++++++++ NadekoBot/NadekoBot.cs | 2 +- NadekoBot/NadekoBot.csproj | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 NadekoBot/Modules/Administration/Commands/SelfCommands.cs diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index fc612d18..834fe52c 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -30,12 +30,14 @@ namespace NadekoBot.Modules.Administration commands.Add(new InfoCommands(this)); commands.Add(new CustomReactionsCommands(this)); commands.Add(new AutoAssignRole(this)); + commands.Add(new SelfCommands(this)); } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; public override void Install(ModuleManager manager) { + manager.CreateCommands("", cgb => { diff --git a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs new file mode 100644 index 00000000..a09e04c3 --- /dev/null +++ b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -0,0 +1,49 @@ +using NadekoBot.Classes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Commands; +using NadekoBot.Modules.Permissions.Classes; + +namespace NadekoBot.Modules.Administration.Commands +{ + class SelfCommands : DiscordCommand + { + public SelfCommands(DiscordModule module) : base(module) + { + } + + internal override void Init(CommandGroupBuilder cgb) + { + cgb.CreateCommand(Module.Prefix + "leave") + .Description("Makes Nadeko leave the server. Either name or id required.\n**Usage**:.leave NSFW") + .Parameter("arg", ParameterType.Required) + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + var arg = e.GetArg("arg")?.Trim(); + if (string.IsNullOrWhiteSpace(arg)) + return; + var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? + NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); + if (server == null) + { + await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); + return; + } + var serverId = server.Id; + if (!server.IsOwner) + { + await server.Leave(); + } + else + { + await server.Delete(); + } + await NadekoBot.SendMessageToOwner("Left server " + server.Name); + }); + } + } +} diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index d6e0974d..1c9aea9d 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -252,7 +252,7 @@ namespace NadekoBot public static bool IsOwner(ulong id) => Creds.OwnerIds.Contains(id); - public async Task SendMessageToOwner(string message) + public static async Task SendMessageToOwner(string message) { if (Config.ForwardMessages && OwnerPrivateChannel != null) await OwnerPrivateChannel.SendMessage(message).ConfigureAwait(false); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 8789a5db..df37a039 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -136,6 +136,7 @@ + From f05f753065aa8841699d953de9b8fc031ad57ca4 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 19:42:07 +0200 Subject: [PATCH 2/7] Add usage to $award --- NadekoBot/Modules/Gambling/GamblingModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Gambling/GamblingModule.cs b/NadekoBot/Modules/Gambling/GamblingModule.cs index ef49e6dc..5c0c8919 100644 --- a/NadekoBot/Modules/Gambling/GamblingModule.cs +++ b/NadekoBot/Modules/Gambling/GamblingModule.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Gambling }); cgb.CreateCommand(Prefix + "award") - .Description("Gives someone a certain amount of flowers. **Owner only!**") + .Description("Gives someone a certain amount of flowers. **Owner only!**\n**Usage**: `$award 100 @person`") .AddCheck(SimpleCheckers.OwnerOnly()) .Parameter("amount", ParameterType.Required) .Parameter("receiver", ParameterType.Unparsed) From 1f8dd72606bc5a8d335a715c069cd820db364170 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 19:56:31 +0200 Subject: [PATCH 3/7] Code analysis recommended this MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ¯\_(ツ)_/¯ --- NadekoBot/Classes/NadekoStats.cs | 17 ++++++++++++++++- .../Modules/Searches/Commands/EvalCommand.cs | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 66ef0984..36fe55bd 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -14,7 +14,7 @@ using System.Timers; namespace NadekoBot { - public class NadekoStats + public class NadekoStats : IDisposable { public static NadekoStats Instance { get; } = new NadekoStats(); @@ -231,5 +231,20 @@ namespace NadekoBot } }).ConfigureAwait(false); } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposing) + { + carbonClient.Dispose(); + } + + } } } \ No newline at end of file diff --git a/NadekoBot/Modules/Searches/Commands/EvalCommand.cs b/NadekoBot/Modules/Searches/Commands/EvalCommand.cs index 57f45342..fdb2f1c1 100644 --- a/NadekoBot/Modules/Searches/Commands/EvalCommand.cs +++ b/NadekoBot/Modules/Searches/Commands/EvalCommand.cs @@ -49,11 +49,11 @@ namespace NadekoBot.Modules.Searches.Commands string result = parser.Parse(expression).ToString(); return result; } - catch (OverflowException e) + catch (OverflowException) { return $"Overflow error on {expression}"; } - catch (FormatException e) + catch (FormatException) { return $"\"{expression}\" was not formatted correctly"; } From e6cd56946cc66186258f11fb7b02fab5cd14c5b6 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 20:50:44 +0200 Subject: [PATCH 4/7] Revert "Code analysis recommended this" This reverts commit 1f8dd72606bc5a8d335a715c069cd820db364170. --- NadekoBot/Classes/NadekoStats.cs | 17 +---------------- .../Modules/Searches/Commands/EvalCommand.cs | 4 ++-- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 36fe55bd..66ef0984 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -14,7 +14,7 @@ using System.Timers; namespace NadekoBot { - public class NadekoStats : IDisposable + public class NadekoStats { public static NadekoStats Instance { get; } = new NadekoStats(); @@ -231,20 +231,5 @@ namespace NadekoBot } }).ConfigureAwait(false); } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposing) - { - carbonClient.Dispose(); - } - - } } } \ No newline at end of file diff --git a/NadekoBot/Modules/Searches/Commands/EvalCommand.cs b/NadekoBot/Modules/Searches/Commands/EvalCommand.cs index fdb2f1c1..57f45342 100644 --- a/NadekoBot/Modules/Searches/Commands/EvalCommand.cs +++ b/NadekoBot/Modules/Searches/Commands/EvalCommand.cs @@ -49,11 +49,11 @@ namespace NadekoBot.Modules.Searches.Commands string result = parser.Parse(expression).ToString(); return result; } - catch (OverflowException) + catch (OverflowException e) { return $"Overflow error on {expression}"; } - catch (FormatException) + catch (FormatException e) { return $"\"{expression}\" was not formatted correctly"; } From d899f13f71c675affbf378973a7b2a4ac415e4b2 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 5 Jun 2016 22:18:52 +0200 Subject: [PATCH 5/7] Update SelfCommands.cs --- NadekoBot/Modules/Administration/Commands/SelfCommands.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index a09e04c3..1530eee4 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -24,8 +24,6 @@ namespace NadekoBot.Modules.Administration.Commands .Do(async e => { var arg = e.GetArg("arg")?.Trim(); - if (string.IsNullOrWhiteSpace(arg)) - return; var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (server == null) @@ -33,7 +31,6 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); return; } - var serverId = server.Id; if (!server.IsOwner) { await server.Leave(); From 091701e93136438a643175c3807fdd5c5cf840b7 Mon Sep 17 00:00:00 2001 From: appelemac Date: Tue, 7 Jun 2016 19:54:55 +0200 Subject: [PATCH 6/7] rip upgrade I'm not scaling the strings *hands off* --- .vs/NadekoBot/NadekoBot.scgdat | Bin 0 -> 131072 bytes .../Modules/Conversations/Conversations.cs | 58 +++++++++++++++++- NadekoBot/NadekoBot.csproj | 1 + NadekoBot/Properties/Resources.Designer.cs | 10 +++ NadekoBot/Properties/Resources.resx | 3 + NadekoBot/resources/images/rose_overlay.png | Bin 0 -> 18492 bytes 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .vs/NadekoBot/NadekoBot.scgdat create mode 100644 NadekoBot/resources/images/rose_overlay.png diff --git a/.vs/NadekoBot/NadekoBot.scgdat b/.vs/NadekoBot/NadekoBot.scgdat new file mode 100644 index 0000000000000000000000000000000000000000..e34ebe8d2ab64f089e47c182c8648a3a419a7573 GIT binary patch literal 131072 zcmeI*TWlQF8Nl(gu9!e-`)jZIo7lCN0ih2&%E*0hZ9N$L;uo4$4-@!$u4I>IrGlytWwKlCM`ej ztk-+EL#Ir>EQvF!?S6k-K%=M(EhnzL7(WiU}$yzEhus%%l3hy^BF{&x7M$ZKb6(?j5~ZQk}zRG zf99go1)sen?87Pq5V$@BYWj%lqe9dI0R#|0009ILK;W7a_+aR7x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Xcdqg~jMP8}dq?vfY|idf(J_oTZ|{0%^Sx`%ULtoys~y8wb-LEOn(tcYi&m#! z-O+r%I{W=&Sht{qb6Rs!=XQ7Vooa5@pW}pp^Y*CsHs7Pp*FN`E$3_MxCgeSioNW{n zdousDIet`o%lU+!Ec$M-^IW^}##YnV^pt75x5hLc{zu06`0p8``ccOC-)7Tz{pT5D z-2v11-P>7X@6YnafezF7<140dc)w}`jM}1k100IagfB*srAbB87a{FU;AJlMyF?=Lj|31(B( zYIXii73LCl*0(ayb?~pn`t|XrvWf5iUxF)15I_I{1Q0*~0R#|0009JAEAYhdyWj4R z>;HGe!i49u4{-fIX2T)^2q1s}0tg_000IagfB*v5l7PPc|BX}cmveIc|GsOf;0st* z{X7Ky*@*x7NPH@r8ovI&fYl&00tg_000IagfB*srAb`LPCh+p}e@HKq>;FSHSiPw( z0tg_000IagfB*srAbUrgwAWHv$MCfB*srAbU-Zp1RKjZGd&JFJDZFdjeb5GyUjxD8fd2q}2q3wfP?zyv4+0s`Y z94eJ6_m(T$`>v9jQ49nSKmY**5I_I{1Q0*~0R#|;2*{=Wzpj7%rGlLQ|H|8t)#v|8 ze#xLe1^6tu*}XkdEl&5I_I{1Q0*~ z0R#|00D)^;z(4=LwrfG@5kLR|1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009IL zKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~ z0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY** z5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0 L009ILa0UJkXGugR literal 0 HcmV?d00001 diff --git a/NadekoBot/Modules/Conversations/Conversations.cs b/NadekoBot/Modules/Conversations/Conversations.cs index b8de0cea..458108ce 100644 --- a/NadekoBot/Modules/Conversations/Conversations.cs +++ b/NadekoBot/Modules/Conversations/Conversations.cs @@ -1,6 +1,7 @@ using Discord; using Discord.Commands; using Discord.Modules; +using NadekoBot.Classes; using NadekoBot.Classes.Conversations.Commands; using NadekoBot.DataModels; using NadekoBot.Extensions; @@ -9,6 +10,7 @@ using NadekoBot.Properties; using System; using System.Diagnostics; using System.Drawing; +using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; using System.Linq; @@ -194,13 +196,15 @@ namespace NadekoBot.Modules.Conversations return; var usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault(); var text = ""; + var avatar = await GetAvatar(usr.AvatarUrl); text = usr?.Name ?? e.GetArg("user"); await e.Channel.SendFile("ripzor_m8.png", - RipName(text, string.IsNullOrWhiteSpace(e.GetArg("year")) + RipUser(text, avatar, string.IsNullOrWhiteSpace(e.GetArg("year")) ? null : e.GetArg("year"))) .ConfigureAwait(false); }); + if (!NadekoBot.Config.DontJoinServers) { cgb.CreateCommand("j") @@ -351,7 +355,7 @@ namespace NadekoBot.Modules.Conversations { fontSize -= (name.Length - 10) / 2; } - + //TODO use measure string var g = Graphics.FromImage(bm); g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200); @@ -362,6 +366,56 @@ namespace NadekoBot.Modules.Conversations return bm.ToStream(ImageFormat.Png); } + public Stream RipUser(string name, Image avatar, string year = null) + { + var bm = Resources.rip; + var offset = name.Length * 2; + + var fontSize = 20; + + if (name.Length > 10) + { + fontSize -= (name.Length - 10) / 2; + } + //var avatar = Image.FromStream(await SearchHelper.GetResponseStreamAsync(aviLink)); + + + + //TODO use measure string + var g = Graphics.FromImage(bm); + g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 220); + g.DrawString((year ?? "?") + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 240); + + g.DrawImage(avatar, 80,135); + g.DrawImage((Image)Resources.rose_overlay, 0, 0); + g.Flush(); + g.Dispose(); + + return bm.ToStream(ImageFormat.Png); + + } + + + public static async Task GetAvatar(string url) + { + var stream = await SearchHelper.GetResponseStreamAsync(url); + Bitmap bmp = new Bitmap(100, 100); + using (GraphicsPath gp = new GraphicsPath()) + { + gp.AddEllipse(0,0, bmp.Width, bmp.Height); + using (Graphics gr = Graphics.FromImage(bmp)) + { + gr.SetClip(gp); + gr.DrawImage(Image.FromStream(stream), Point.Empty); + + } + } + return bmp; + + } + + + private static Func SayYes() => async e => await e.Channel.SendMessage("Yes. :)").ConfigureAwait(false); } diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index df37a039..afbc37af 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -492,6 +492,7 @@ +