Revive ping pong

This commit is contained in:
runebaas 2018-03-02 23:05:14 +01:00
parent 8189d78cea
commit 440f3a97c2
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
3 changed files with 29 additions and 3 deletions

View file

@ -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);
}
}
}
}

View file

@ -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);

View file

@ -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);