added !tag create, !tag delete and !tag remove

This commit is contained in:
Deukhoofd 2018-08-05 22:19:29 +02:00
parent d0959aecdc
commit 398a6a0c61
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 43 additions and 4 deletions

View File

@ -27,15 +27,15 @@ namespace DeukBot4.MessageHandlers.CommandHandler
}
[Command("tag", PermissionLevel.Everyone)]
[CommandParameters(ParameterMatcher.ParameterType.Word)]
[CommandParameters(ParameterMatcher.ParameterType.Remainder)]
[CommandHelp("Gets a tag", "Gets a tag earlier set by a moderator.")]
[BlockUsageInPm, RequireParameterMatch]
[BlockUsageInPm]
public async Task GetTag(CommandRequest request)
{
TagStorage.GetTag(request);
}
[Command("tags", PermissionLevel.Everyone)]
[CommandHelp("List tags in the server", "List tags in the server set by a moderator.")]
[BlockUsageInPm]

View File

@ -32,9 +32,14 @@ namespace DeukBot4.MessageHandlers.CommandHandler
return key.ToLowerInvariant();
}
public static readonly string[] ReservedTags = new[] {"create", "delete", "remove"};
public (bool success, string result) AddTag(string key, string value)
{
var parsedTag = CleanKey(key);
if (ReservedTags.Contains(parsedTag))
{
return (false, $"You can't use keyword {parsedTag}, that's a reserved tag");
}
if (Tags.ContainsKey(parsedTag))
{
return (false, "A tag with that name already exists");
@ -140,7 +145,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
ServerCache.Add(serverId, serverTags);
}
var key = cmd.Parameters[0].AsString();
var key = cmd.Parameters[0].AsString();
var value = cmd.Parameters[1].AsString();
var result = serverTags.AddTag(key, value);
if (!result.success)
@ -190,6 +195,40 @@ namespace DeukBot4.MessageHandlers.CommandHandler
ServerCache.Add(serverId, serverTags);
}
var split = cmd.Parameters[0].AsString().Split(" ");
var first = split[0].ToLowerInvariant();
if (first == "create")
{
var keyword = split[1];
var rest = split.Skip(2).ToArray().Join(" ");
var result = serverTags.AddTag(keyword, rest);
if (!result.success)
{
cmd.SendMessageAsync("Something went wrong: " + result.result);
}
else
{
cmd.SendMessageAsync("Success! Added tag with key: " + keyword);
}
return;
}
if (first == "remove" || first == "delete")
{
var keyword = split[1];
var result = serverTags.RemoveTag(keyword);
if (!result.success)
{
cmd.SendMessageAsync("Something went wrong: " + result.result);
}
else
{
cmd.SendMessageAsync("Success! Removed tag with key: " + keyword);
}
return;
}
var key = cmd.Parameters[0].AsString();
cmd.SendMessageAsync(serverTags.GetTag(key));
}