greet/bye small cleanup, code is still disgusting

This commit is contained in:
Master Kwoth 2016-05-02 01:40:53 +02:00
parent d9f1988be5
commit 6c55e68c62

View File

@ -223,12 +223,9 @@ namespace NadekoBot.Modules.Administration.Commands
.Do(async e => .Do(async e =>
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
var controls = AnnouncementsDictionary[e.Server.Id]; if (ann.ToggleDelete())
if (controls.ToggleDelete())
await e.Channel.SendMessage("`Automatic deletion of greet and bye messages has been enabled.`").ConfigureAwait(false); await e.Channel.SendMessage("`Automatic deletion of greet and bye messages has been enabled.`").ConfigureAwait(false);
else else
await e.Channel.SendMessage("`Automatic deletion of greet and bye messages has been disabled.`").ConfigureAwait(false); await e.Channel.SendMessage("`Automatic deletion of greet and bye messages has been disabled.`").ConfigureAwait(false);
@ -239,12 +236,9 @@ namespace NadekoBot.Modules.Administration.Commands
.Do(async e => .Do(async e =>
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
var controls = AnnouncementsDictionary[e.Server.Id]; if (ann.ToggleGreet(e.Channel.Id))
if (controls.ToggleGreet(e.Channel.Id))
await e.Channel.SendMessage("Greet announcements enabled on this channel.").ConfigureAwait(false); await e.Channel.SendMessage("Greet announcements enabled on this channel.").ConfigureAwait(false);
else else
await e.Channel.SendMessage("Greet announcements disabled.").ConfigureAwait(false); await e.Channel.SendMessage("Greet announcements disabled.").ConfigureAwait(false);
@ -257,12 +251,11 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (e.GetArg("msg") == null) return; if (e.GetArg("msg") == null) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary[e.Server.Id].GreetText = e.GetArg("msg"); ann.GreetText = e.GetArg("msg");
await e.Channel.SendMessage("New greet message set.").ConfigureAwait(false); await e.Channel.SendMessage("New greet message set.").ConfigureAwait(false);
if (!AnnouncementsDictionary[e.Server.Id].Greet) if (!ann.Greet)
await e.Channel.SendMessage("Enable greet messsages by typing `.greet`").ConfigureAwait(false); await e.Channel.SendMessage("Enable greet messsages by typing `.greet`").ConfigureAwait(false);
}); });
@ -271,12 +264,9 @@ namespace NadekoBot.Modules.Administration.Commands
.Do(async e => .Do(async e =>
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
var controls = AnnouncementsDictionary[e.Server.Id]; if (ann.ToggleBye(e.Channel.Id))
if (controls.ToggleBye(e.Channel.Id))
await e.Channel.SendMessage("Bye announcements enabled on this channel.").ConfigureAwait(false); await e.Channel.SendMessage("Bye announcements enabled on this channel.").ConfigureAwait(false);
else else
await e.Channel.SendMessage("Bye announcements disabled.").ConfigureAwait(false); await e.Channel.SendMessage("Bye announcements disabled.").ConfigureAwait(false);
@ -289,12 +279,11 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (e.GetArg("msg") == null) return; if (e.GetArg("msg") == null) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary[e.Server.Id].ByeText = e.GetArg("msg"); ann.ByeText = e.GetArg("msg");
await e.Channel.SendMessage("New bye message set.").ConfigureAwait(false); await e.Channel.SendMessage("New bye message set.").ConfigureAwait(false);
if (!AnnouncementsDictionary[e.Server.Id].Bye) if (!ann.Bye)
await e.Channel.SendMessage("Enable bye messsages by typing `.bye`.").ConfigureAwait(false); await e.Channel.SendMessage("Enable bye messsages by typing `.bye`.").ConfigureAwait(false);
}); });
@ -303,15 +292,14 @@ namespace NadekoBot.Modules.Administration.Commands
.Do(async e => .Do(async e =>
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id)) var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary[e.Server.Id].ToggleByePM();
if (AnnouncementsDictionary[e.Server.Id].ByePM) if (ann.ToggleByePM())
await e.Channel.SendMessage("Bye messages will be sent in a PM from now on.\n ⚠ Keep in mind this might fail if the user and the bot have no common servers after the user leaves.").ConfigureAwait(false); await e.Channel.SendMessage("Bye messages will be sent in a PM from now on.\n ⚠ Keep in mind this might fail if the user and the bot have no common servers after the user leaves.").ConfigureAwait(false);
else else
await e.Channel.SendMessage("Bye messages will be sent in a bound channel from now on.").ConfigureAwait(false); await e.Channel.SendMessage("Bye messages will be sent in a bound channel from now on.").ConfigureAwait(false);
if (!AnnouncementsDictionary[e.Server.Id].Bye) if (!ann.Bye)
await e.Channel.SendMessage("Enable bye messsages by typing `.bye`, and set the bye message using `.byemsg`").ConfigureAwait(false); await e.Channel.SendMessage("Enable bye messsages by typing `.bye`, and set the bye message using `.byemsg`").ConfigureAwait(false);
}); });
@ -320,15 +308,14 @@ namespace NadekoBot.Modules.Administration.Commands
.Do(async e => .Do(async e =>
{ {
if (!e.User.ServerPermissions.ManageServer) return; if (!e.User.ServerPermissions.ManageServer) return;
if (!AnnouncementsDictionary.ContainsKey(e.Server.Id))
AnnouncementsDictionary.TryAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
AnnouncementsDictionary[e.Server.Id].ToggleGreetPM(); var ann = AnnouncementsDictionary.GetOrAdd(e.Server.Id, new AnnounceControls(e.Server.Id));
if (AnnouncementsDictionary[e.Server.Id].GreetPM)
if (ann.ToggleGreetPM())
await e.Channel.SendMessage("Greet messages will be sent in a PM from now on.").ConfigureAwait(false); await e.Channel.SendMessage("Greet messages will be sent in a PM from now on.").ConfigureAwait(false);
else else
await e.Channel.SendMessage("Greet messages will be sent in a bound channel from now on.").ConfigureAwait(false); await e.Channel.SendMessage("Greet messages will be sent in a bound channel from now on.").ConfigureAwait(false);
if (!AnnouncementsDictionary[e.Server.Id].Greet) if (!ann.Greet)
await e.Channel.SendMessage("Enable greet messsages by typing `.greet`, and set the greet message using `.greetmsg`").ConfigureAwait(false); await e.Channel.SendMessage("Enable greet messsages by typing `.greet`, and set the greet message using `.greetmsg`").ConfigureAwait(false);
}); });
} }