a lot of fixes. .spmom command, moved spmom to serverspecific config

This commit is contained in:
Master Kwoth 2016-03-14 14:13:21 +01:00
parent 7978b01644
commit 2619a46ea2
7 changed files with 66 additions and 26 deletions

View File

@ -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<StreamNotificationConfig> ObservingStreams { get; set; } = new HashSet<StreamNotificationConfig>();
public List<string> RotatingStatuses { get; set; } = new List<string>();
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);
}
}
}

View File

@ -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<string, bool>();
Commands = new Dictionary<string, bool>();
FilterInvites = false;
FilterWords = false;
}
public override string ToString() {

View File

@ -20,12 +20,11 @@ namespace NadekoBot.Classes {
configs = JsonConvert
.DeserializeObject<ConcurrentDictionary<ulong, ServerSpecificConfig>>(
File.ReadAllText(filePath));
}
catch (Exception ex) {
} catch (Exception ex) {
Console.WriteLine($"Deserialization failing: {ex}");
}
}
if(configs == null)
if (configs == null)
configs = new ConcurrentDictionary<ulong, ServerSpecificConfig>();
}
@ -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(); };

View File

@ -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,8 +22,9 @@ namespace NadekoBot.Commands {
NadekoBot.Client.MessageUpdated += MsgUpdtd;
NadekoBot.Client.UserUpdated += UsrUpdtd;
if (NadekoBot.Config.SendPrivateMessageOnMention)
NadekoBot.Client.MessageReceived += async (s, e) => {
if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return;
try {
if (e.Channel.IsPrivate)
return;
@ -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());

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,14 @@
{
"143857445461164032": {
"VoicePlusTextEnabled": false,
"SendPrivateMessageOnMention": false
},
"117523346618318850": {
"VoicePlusTextEnabled": false,
"SendPrivateMessageOnMention": true
},
"81384788765712384": {
"VoicePlusTextEnabled": false,
"SendPrivateMessageOnMention": false
}
}