added .logignore to ignore channels you don't want logged with .logserver

This commit is contained in:
Kwoth 2016-07-17 17:52:06 +02:00
parent 5c36a90408
commit 3512a99ce1
4 changed files with 55 additions and 14 deletions

View File

@ -100,6 +100,21 @@ namespace NadekoBot.Classes
} }
} }
[JsonIgnore]
private ObservableCollection<ulong> logserverIgnoreChannels;
public ObservableCollection<ulong> LogserverIgnoreChannels {
get { return logserverIgnoreChannels; }
set {
logserverIgnoreChannels = value;
if (value != null)
logserverIgnoreChannels.CollectionChanged += (s, e) =>
{
if (!SpecificConfigurations.Instantiated) return;
OnPropertyChanged();
};
}
}
[JsonProperty("LogPresenceChannel")] [JsonProperty("LogPresenceChannel")]
private ulong? logPresenceChannel = null; private ulong? logPresenceChannel = null;
[JsonIgnore] [JsonIgnore]
@ -212,6 +227,7 @@ namespace NadekoBot.Classes
ObservingStreams = new ObservableCollection<StreamNotificationConfig>(); ObservingStreams = new ObservableCollection<StreamNotificationConfig>();
GenerateCurrencyChannels = new ObservableConcurrentDictionary<ulong, int>(); GenerateCurrencyChannels = new ObservableConcurrentDictionary<ulong, int>();
VoiceChannelLog = new ObservableConcurrentDictionary<ulong, ulong>(); VoiceChannelLog = new ObservableConcurrentDictionary<ulong, ulong>();
LogserverIgnoreChannels = new ObservableCollection<ulong>();
} }
public event PropertyChangedEventHandler PropertyChanged = delegate { SpecificConfigurations.Default.Save(); }; public event PropertyChangedEventHandler PropertyChanged = delegate { SpecificConfigurations.Default.Save(); };

View File

@ -51,8 +51,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
try try
{ {
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null) var chId = config.LogServerChannel;
if (chId == null || config.LogserverIgnoreChannels.Contains(e.After.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -72,8 +73,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
try try
{ {
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null) var chId = config.LogServerChannel;
if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -87,8 +89,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
try try
{ {
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null) var chId = config.LogServerChannel;
if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -164,8 +167,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null || e.Channel.Id == chId) var chId = config.LogServerChannel;
if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -192,8 +196,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null || e.Channel.Id == chId) var chId = config.LogServerChannel;
if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -219,8 +224,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User?.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel; var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (chId == null || e.Channel.Id == chId) var chId = config.LogServerChannel;
if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
return; return;
Channel ch; Channel ch;
if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null) if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
@ -370,6 +376,25 @@ $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
await e.Channel.SendMessage($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false); await e.Channel.SendMessage($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false);
}); });
cgb.CreateCommand(Prefix + "logignore")
.Alias($"Toggles whether the {Prefix}logserver command ignores this channel. Useful if you have hidden admin channel and public log channel.")
.AddCheck(SimpleCheckers.OwnerOnly())
.AddCheck(SimpleCheckers.ManageServer())
.Do(async e =>
{
var config = SpecificConfigurations.Default.Of(e.Server.Id);
if (config.LogserverIgnoreChannels.Remove(e.Channel.Id))
{
await e.Channel.SendMessage($"`{Prefix}logserver will stop ignoring this channel.`");
}
else
{
config.LogserverIgnoreChannels.Add(e.Channel.Id);
await e.Channel.SendMessage($"`{Prefix}logserver will ignore this channel.`");
}
});
cgb.CreateCommand(Module.Prefix + "userpresence") cgb.CreateCommand(Module.Prefix + "userpresence")
.Description("Starts logging to this channel when someone from the server goes online/offline/idle.") .Description("Starts logging to this channel when someone from the server goes online/offline/idle.")
.AddCheck(SimpleCheckers.ManageServer()) .AddCheck(SimpleCheckers.ManageServer())

View File

@ -7,7 +7,7 @@ namespace NadekoBot.Classes
/// Base DiscordCommand Class. /// Base DiscordCommand Class.
/// Inherit this class to create your own command. /// Inherit this class to create your own command.
/// </summary> /// </summary>
internal abstract class DiscordCommand public abstract class DiscordCommand
{ {
/// <summary> /// <summary>

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using NadekoBot.Classes; using NadekoBot.Classes;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal abstract class DiscordModule : IModule { public abstract class DiscordModule : IModule {
protected readonly HashSet<DiscordCommand> commands = new HashSet<DiscordCommand>(); protected readonly HashSet<DiscordCommand> commands = new HashSet<DiscordCommand>();
public abstract string Prefix { get; } public abstract string Prefix { get; }