From 440f3a97c298f5813349ac5f7a1970fe854efed2 Mon Sep 17 00:00:00 2001 From: runebaas Date: Fri, 2 Mar 2018 23:05:14 +0100 Subject: [PATCH] Revive ping pong --- Geekbot.net/Commands/Admin.cs | 21 +++++++++++++++++++-- Geekbot.net/Handlers.cs | 9 +++++++++ Geekbot.net/Lib/MtgManaConverter.cs | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Geekbot.net/Commands/Admin.cs b/Geekbot.net/Commands/Admin.cs index 0b76b4b..681ff99 100644 --- a/Geekbot.net/Commands/Admin.cs +++ b/Geekbot.net/Commands/Admin.cs @@ -34,8 +34,7 @@ namespace Geekbot.net.Commands { _redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("WelcomeMsg", welcomeMessage)}); var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); - await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" + - formatedMessage); + await ReplyAsync($"Welcome message has been changed\r\nHere is an example of how it would look:\r\n{formatedMessage}"); } [Command("modchannel", RunMode = RunMode.Async)] @@ -155,5 +154,23 @@ namespace Geekbot.net.Commands _errorHandler.HandleCommandException(e, Context); } } + + [Command("ping", RunMode = RunMode.Async)] + [Remarks(CommandCategories.Admin)] + [Summary("Enable the ping reply.")] + public async Task togglePing() + { + try + { + bool.TryParse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ping"), out var current); + _redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("ping", current ? "false" : "true"), }); + await ReplyAsync(!current ? "i will reply to ping now" : "No more pongs..."); + } + catch (Exception e) + { + _errorHandler.HandleCommandException(e, Context); + } + } + } } \ No newline at end of file diff --git a/Geekbot.net/Handlers.cs b/Geekbot.net/Handlers.cs index 7ca9390..c1e0ee3 100644 --- a/Geekbot.net/Handlers.cs +++ b/Geekbot.net/Handlers.cs @@ -49,6 +49,15 @@ namespace Geekbot.net message.Channel.SendMessageAsync("hui!!!"); return Task.CompletedTask; } + if (lowCaseMsg.StartsWith("ping ") || lowCaseMsg.Equals("ping")) + { + bool.TryParse(_redis.HashGet($"{((SocketGuildChannel) message.Channel).Guild.Id}:Settings", "ping"), out var allowPings); + if (allowPings) + { + message.Channel.SendMessageAsync("pong"); + return Task.CompletedTask; + } + } if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return Task.CompletedTask; var context = new CommandContext(_client, message); diff --git a/Geekbot.net/Lib/MtgManaConverter.cs b/Geekbot.net/Lib/MtgManaConverter.cs index aeb1c9e..098542e 100644 --- a/Geekbot.net/Lib/MtgManaConverter.cs +++ b/Geekbot.net/Lib/MtgManaConverter.cs @@ -67,7 +67,7 @@ namespace Geekbot.net.Lib public string ConvertMana(string mana) { - var rgx = Regex.Matches(mana, "(\\{(.*?)\\})"); + var rgx = Regex.Matches(mana, @"(\{(.*?)\})"); foreach (Match manaTypes in rgx) { var m = _manaDict.GetValueOrDefault(manaTypes.Value);