sbl is owner only now

This commit is contained in:
Master Kwoth 2016-03-19 21:19:25 +01:00
parent 5499f5df37
commit 0485d2ed93

View File

@ -469,25 +469,32 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "sbl") cgb.CreateCommand(Prefix + "sbl")
.Description("Blacklists a server by a name or id (#general for example).\n**Usage**: ;usl [servername/serverid]") .Description("Blacklists a server by a name or id (#general for example).\n**Usage**: ;usl [servername/serverid]")
.Parameter("server", ParameterType.Unparsed) .Parameter("server", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e => {
await Task.Run(async () => { await Task.Run(async () => {
var arg = e.GetArg("server")?.Trim(); var arg = e.GetArg("server")?.Trim();
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? ulong serverId;
NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (!ulong.TryParse(arg, out serverId)) {
if (server == null) { await e.Channel.SendMessage("Not a valid Id");
await e.Channel.SendMessage("Cannot find that server");
return; return;
} }
NadekoBot.Config.ServerBlacklist.Add(server.Id); var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ??
NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault();
NadekoBot.Config.ServerBlacklist.Add(serverId);
ConfigHandler.SaveConfig(); ConfigHandler.SaveConfig();
//cleanup trivias and typeracing //cleanup trivias and typeracing
Classes.Trivia.TriviaGame trivia; Classes.Trivia.TriviaGame trivia;
Commands.Trivia.RunningTrivias.TryRemove(server.Id, out trivia); Commands.Trivia.RunningTrivias.TryRemove(serverId, out trivia);
Commands.TypingGame typeracer; Commands.TypingGame typeracer;
Commands.SpeedTyping.RunningContests.TryRemove(server.Id, out typeracer); Commands.SpeedTyping.RunningContests.TryRemove(serverId, out typeracer);
await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`");
if (server == null) {
await e.Channel.SendMessage("Cannot find that server");
} else {
await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`");
}
}); });
}); });
}); });