diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index bb85995e..ba2ba256 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -9,7 +9,6 @@ namespace NadekoBot.Classes.JSONModels { public bool DontJoinServers { get; set; } = false; public bool ForwardMessages { get; set; } = true; public bool IsRotatingStatus { get; set; } = false; - public bool SendPrivateMessageOnMention { get; set; } = false; public HashSet ObservingStreams { get; set; } = new HashSet(); public List RotatingStatuses { get; set; } = new List(); public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel(); @@ -100,7 +99,7 @@ namespace NadekoBot.Classes.JSONModels { this.ServerId == other.ServerId; public override int GetHashCode() { - return (int) ((int) ServerId + Username.Length + (int) Type); + return (int)((int)ServerId + Username.Length + (int)Type); } } } diff --git a/NadekoBot/Classes/Permissions/PermissionsHandler.cs b/NadekoBot/Classes/Permissions/PermissionsHandler.cs index 23d42c59..f0994752 100644 --- a/NadekoBot/Classes/Permissions/PermissionsHandler.cs +++ b/NadekoBot/Classes/Permissions/PermissionsHandler.cs @@ -71,7 +71,7 @@ namespace NadekoBot.Classes.Permissions { internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) { var server = user.Server; - ServerPermissions serverPerms; + ServerPermissions serverPerms = PermissionsDict.GetOrAdd(server.Id, id => new ServerPermissions(id, server.Name)); if (!PermissionsDict.TryGetValue(server.Id, out serverPerms)) { serverPerms = new ServerPermissions(server.Id, server.Name); PermissionsDict.TryAdd(server.Id, serverPerms); @@ -387,6 +387,8 @@ namespace NadekoBot.Classes.Permissions { Name = name; Modules = new Dictionary(); Commands = new Dictionary(); + FilterInvites = false; + FilterWords = false; } public override string ToString() { diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index 5d89034e..43b0cbd1 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -20,12 +20,11 @@ namespace NadekoBot.Classes { configs = JsonConvert .DeserializeObject>( File.ReadAllText(filePath)); - } - catch (Exception ex) { + } catch (Exception ex) { Console.WriteLine($"Deserialization failing: {ex}"); } } - if(configs == null) + if (configs == null) configs = new ConcurrentDictionary(); } @@ -45,15 +44,25 @@ namespace NadekoBot.Classes { internal class ServerSpecificConfig : INotifyPropertyChanged { [JsonProperty("VoicePlusTextEnabled")] - private bool? voicePlusTextEnabled; + private bool voicePlusTextEnabled; [JsonIgnore] - public bool? VoicePlusTextEnabled { + public bool VoicePlusTextEnabled { get { return voicePlusTextEnabled; } set { voicePlusTextEnabled = value; OnPropertyChanged(); } } + [JsonProperty("SendPrivateMessageOnMention")] + private bool sendPrivateMessageOnMention; + [JsonIgnore] + public bool SendPrivateMessageOnMention { + get { return sendPrivateMessageOnMention; } + set { + sendPrivateMessageOnMention = value; + OnPropertyChanged(); + } + } public event PropertyChangedEventHandler PropertyChanged = delegate { SpecificConfigurations.Default.Save(); }; diff --git a/NadekoBot/Commands/LogCommand.cs b/NadekoBot/Commands/LogCommand.cs index d56a8e66..45ca6b18 100644 --- a/NadekoBot/Commands/LogCommand.cs +++ b/NadekoBot/Commands/LogCommand.cs @@ -5,6 +5,7 @@ using System.Timers; using System.Threading.Tasks; using Discord.Commands; using Discord; +using NadekoBot.Classes; using NadekoBot.Classes.Permissions; using NadekoBot.Modules; @@ -21,22 +22,23 @@ namespace NadekoBot.Commands { NadekoBot.Client.MessageUpdated += MsgUpdtd; NadekoBot.Client.UserUpdated += UsrUpdtd; - if (NadekoBot.Config.SendPrivateMessageOnMention) - NadekoBot.Client.MessageReceived += async (s, e) => { - try { - if (e.Channel.IsPrivate) - return; - var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); - if (usr?.Status != UserStatus.Offline) - return; - await e.Channel.SendMessage($"User `{usr.Name}` is offline. PM sent."); - await usr.SendMessage( - $"User `{e.User.Name}` mentioned you on " + - $"`{e.Server.Name}` server while you were offline.\n" + - $"`Message:` {e.Message.Text}"); - } catch { } - }; + NadekoBot.Client.MessageReceived += async (s, e) => { + if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return; + try { + if (e.Channel.IsPrivate) + return; + var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); + if (usr?.Status != UserStatus.Offline) + return; + await e.Channel.SendMessage($"User `{usr.Name}` is offline. PM sent."); + await usr.SendMessage( + $"User `{e.User.Name}` mentioned you on " + + $"`{e.Server.Name}` server while you were offline.\n" + + $"`Message:` {e.Message.Text}"); + + } catch { } + }; } public Func DoFunc() => async e => { @@ -122,6 +124,20 @@ namespace NadekoBot.Commands { internal override void Init(CommandGroupBuilder cgb) { + cgb.CreateCommand(Module.Prefix + "spmom") + .Description("Toggles whether mentions of other offline users on your server will send a pm to them.") + .Do(async e => { + var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id); + specificConfig.SendPrivateMessageOnMention = + !specificConfig.SendPrivateMessageOnMention; + if (specificConfig.SendPrivateMessageOnMention) + await e.Channel.SendMessage(":ok: I will send private messages " + + "to mentioned offline users."); + else + await e.Channel.SendMessage(":ok: I won't send private messages " + + "to mentioned offline users anymore."); + }); + cgb.CreateCommand(Module.Prefix + "logserver") .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.") .Do(DoFunc()); diff --git a/NadekoBot/Commands/StreamNotifications.cs b/NadekoBot/Commands/StreamNotifications.cs index eccdc30a..ab7b89ff 100644 --- a/NadekoBot/Commands/StreamNotifications.cs +++ b/NadekoBot/Commands/StreamNotifications.cs @@ -46,7 +46,7 @@ namespace NadekoBot.Commands { if (stream.Type == StreamNotificationConfig.StreamType.Hitbox) msg += $"\n`Here is the Link:`【http://www.hitbox.tv/{stream.Username}】"; else if (stream.Type == StreamNotificationConfig.StreamType.Twitch) - msg += $"\n`Here is the Link:`【http://www.twitch.tv/channels/{stream.Username}】"; + msg += $"\n`Here is the Link:`【http://www.twitch.tv/{stream.Username}】"; else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming) msg += $"\n`Here is the Link:`【not implemented yet - {stream.Username}】"; await channel.SendMessage(msg); @@ -175,7 +175,7 @@ namespace NadekoBot.Commands { if (type == StreamNotificationConfig.StreamType.Hitbox) msg += $"\n`Here is the Link:` http://www.hitbox.tv/{stream.Username}"; else if (type == StreamNotificationConfig.StreamType.Twitch) - msg += $"\n`Here is the Link:` http://www.twitch.tv/channels/{stream.Username}"; + msg += $"\n`Here is the Link:` http://www.twitch.tv/{stream.Username}"; else if (type == StreamNotificationConfig.StreamType.YoutubeGaming) msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}"; stream.LastStatus = data.Item1; diff --git a/NadekoBot/Commands/VoicePlusTextCommand.cs b/NadekoBot/Commands/VoicePlusTextCommand.cs index d12e9dce..424d20e2 100644 --- a/NadekoBot/Commands/VoicePlusTextCommand.cs +++ b/NadekoBot/Commands/VoicePlusTextCommand.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Commands { try { var config = SpecificConfigurations.Default.Of(e.Server.Id); if (e.Before.VoiceChannel == e.After.VoiceChannel) return; - if (!(config.VoicePlusTextEnabled ?? false)) + if (!config.VoicePlusTextEnabled) return; var beforeVch = e.Before.VoiceChannel; diff --git a/NadekoBot/bin/Debug/data/ServerSpecificConfigs.json b/NadekoBot/bin/Debug/data/ServerSpecificConfigs.json new file mode 100644 index 00000000..61f8f887 --- /dev/null +++ b/NadekoBot/bin/Debug/data/ServerSpecificConfigs.json @@ -0,0 +1,14 @@ +{ + "143857445461164032": { + "VoicePlusTextEnabled": false, + "SendPrivateMessageOnMention": false + }, + "117523346618318850": { + "VoicePlusTextEnabled": false, + "SendPrivateMessageOnMention": true + }, + "81384788765712384": { + "VoicePlusTextEnabled": false, + "SendPrivateMessageOnMention": false + } +} \ No newline at end of file