a lot of fixes. .spmom
command, moved spmom to serverspecific config
This commit is contained in:
parent
7978b01644
commit
2619a46ea2
@ -9,7 +9,6 @@ namespace NadekoBot.Classes.JSONModels {
|
|||||||
public bool DontJoinServers { get; set; } = false;
|
public bool DontJoinServers { get; set; } = false;
|
||||||
public bool ForwardMessages { get; set; } = true;
|
public bool ForwardMessages { get; set; } = true;
|
||||||
public bool IsRotatingStatus { get; set; } = false;
|
public bool IsRotatingStatus { get; set; } = false;
|
||||||
public bool SendPrivateMessageOnMention { get; set; } = false;
|
|
||||||
public HashSet<StreamNotificationConfig> ObservingStreams { get; set; } = new HashSet<StreamNotificationConfig>();
|
public HashSet<StreamNotificationConfig> ObservingStreams { get; set; } = new HashSet<StreamNotificationConfig>();
|
||||||
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
public List<string> RotatingStatuses { get; set; } = new List<string>();
|
||||||
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel();
|
||||||
@ -100,7 +99,7 @@ namespace NadekoBot.Classes.JSONModels {
|
|||||||
this.ServerId == other.ServerId;
|
this.ServerId == other.ServerId;
|
||||||
|
|
||||||
public override int GetHashCode() {
|
public override int GetHashCode() {
|
||||||
return (int) ((int) ServerId + Username.Length + (int) Type);
|
return (int)((int)ServerId + Username.Length + (int)Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
|
|
||||||
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) {
|
internal static PermissionBanType GetPermissionBanType(Command command, User user, Channel channel) {
|
||||||
var server = user.Server;
|
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)) {
|
if (!PermissionsDict.TryGetValue(server.Id, out serverPerms)) {
|
||||||
serverPerms = new ServerPermissions(server.Id, server.Name);
|
serverPerms = new ServerPermissions(server.Id, server.Name);
|
||||||
PermissionsDict.TryAdd(server.Id, serverPerms);
|
PermissionsDict.TryAdd(server.Id, serverPerms);
|
||||||
@ -387,6 +387,8 @@ namespace NadekoBot.Classes.Permissions {
|
|||||||
Name = name;
|
Name = name;
|
||||||
Modules = new Dictionary<string, bool>();
|
Modules = new Dictionary<string, bool>();
|
||||||
Commands = new Dictionary<string, bool>();
|
Commands = new Dictionary<string, bool>();
|
||||||
|
FilterInvites = false;
|
||||||
|
FilterWords = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
|
@ -20,12 +20,11 @@ namespace NadekoBot.Classes {
|
|||||||
configs = JsonConvert
|
configs = JsonConvert
|
||||||
.DeserializeObject<ConcurrentDictionary<ulong, ServerSpecificConfig>>(
|
.DeserializeObject<ConcurrentDictionary<ulong, ServerSpecificConfig>>(
|
||||||
File.ReadAllText(filePath));
|
File.ReadAllText(filePath));
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
Console.WriteLine($"Deserialization failing: {ex}");
|
Console.WriteLine($"Deserialization failing: {ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(configs == null)
|
if (configs == null)
|
||||||
configs = new ConcurrentDictionary<ulong, ServerSpecificConfig>();
|
configs = new ConcurrentDictionary<ulong, ServerSpecificConfig>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,15 +44,25 @@ namespace NadekoBot.Classes {
|
|||||||
|
|
||||||
internal class ServerSpecificConfig : INotifyPropertyChanged {
|
internal class ServerSpecificConfig : INotifyPropertyChanged {
|
||||||
[JsonProperty("VoicePlusTextEnabled")]
|
[JsonProperty("VoicePlusTextEnabled")]
|
||||||
private bool? voicePlusTextEnabled;
|
private bool voicePlusTextEnabled;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool? VoicePlusTextEnabled {
|
public bool VoicePlusTextEnabled {
|
||||||
get { return voicePlusTextEnabled; }
|
get { return voicePlusTextEnabled; }
|
||||||
set {
|
set {
|
||||||
voicePlusTextEnabled = value;
|
voicePlusTextEnabled = value;
|
||||||
OnPropertyChanged();
|
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(); };
|
public event PropertyChangedEventHandler PropertyChanged = delegate { SpecificConfigurations.Default.Save(); };
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using System.Timers;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord;
|
using Discord;
|
||||||
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes.Permissions;
|
||||||
using NadekoBot.Modules;
|
using NadekoBot.Modules;
|
||||||
|
|
||||||
@ -21,22 +22,23 @@ namespace NadekoBot.Commands {
|
|||||||
NadekoBot.Client.MessageUpdated += MsgUpdtd;
|
NadekoBot.Client.MessageUpdated += MsgUpdtd;
|
||||||
NadekoBot.Client.UserUpdated += UsrUpdtd;
|
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<CommandEventArgs, Task> DoFunc() => async e => {
|
public Func<CommandEventArgs, Task> DoFunc() => async e => {
|
||||||
@ -122,6 +124,20 @@ namespace NadekoBot.Commands {
|
|||||||
|
|
||||||
internal override void Init(CommandGroupBuilder cgb) {
|
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")
|
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.")
|
.Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.")
|
||||||
.Do(DoFunc());
|
.Do(DoFunc());
|
||||||
|
@ -46,7 +46,7 @@ namespace NadekoBot.Commands {
|
|||||||
if (stream.Type == StreamNotificationConfig.StreamType.Hitbox)
|
if (stream.Type == StreamNotificationConfig.StreamType.Hitbox)
|
||||||
msg += $"\n`Here is the Link:`【http://www.hitbox.tv/{stream.Username}】";
|
msg += $"\n`Here is the Link:`【http://www.hitbox.tv/{stream.Username}】";
|
||||||
else if (stream.Type == StreamNotificationConfig.StreamType.Twitch)
|
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)
|
else if (stream.Type == StreamNotificationConfig.StreamType.YoutubeGaming)
|
||||||
msg += $"\n`Here is the Link:`【not implemented yet - {stream.Username}】";
|
msg += $"\n`Here is the Link:`【not implemented yet - {stream.Username}】";
|
||||||
await channel.SendMessage(msg);
|
await channel.SendMessage(msg);
|
||||||
@ -175,7 +175,7 @@ namespace NadekoBot.Commands {
|
|||||||
if (type == StreamNotificationConfig.StreamType.Hitbox)
|
if (type == StreamNotificationConfig.StreamType.Hitbox)
|
||||||
msg += $"\n`Here is the Link:` http://www.hitbox.tv/{stream.Username}";
|
msg += $"\n`Here is the Link:` http://www.hitbox.tv/{stream.Username}";
|
||||||
else if (type == StreamNotificationConfig.StreamType.Twitch)
|
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)
|
else if (type == StreamNotificationConfig.StreamType.YoutubeGaming)
|
||||||
msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
|
msg += $"\n`Here is the Link:` not implemented yet - {stream.Username}";
|
||||||
stream.LastStatus = data.Item1;
|
stream.LastStatus = data.Item1;
|
||||||
|
@ -24,7 +24,7 @@ namespace NadekoBot.Commands {
|
|||||||
try {
|
try {
|
||||||
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||||
if (e.Before.VoiceChannel == e.After.VoiceChannel) return;
|
if (e.Before.VoiceChannel == e.After.VoiceChannel) return;
|
||||||
if (!(config.VoicePlusTextEnabled ?? false))
|
if (!config.VoicePlusTextEnabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var beforeVch = e.Before.VoiceChannel;
|
var beforeVch = e.Before.VoiceChannel;
|
||||||
|
14
NadekoBot/bin/Debug/data/ServerSpecificConfigs.json
Normal file
14
NadekoBot/bin/Debug/data/ServerSpecificConfigs.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"143857445461164032": {
|
||||||
|
"VoicePlusTextEnabled": false,
|
||||||
|
"SendPrivateMessageOnMention": false
|
||||||
|
},
|
||||||
|
"117523346618318850": {
|
||||||
|
"VoicePlusTextEnabled": false,
|
||||||
|
"SendPrivateMessageOnMention": true
|
||||||
|
},
|
||||||
|
"81384788765712384": {
|
||||||
|
"VoicePlusTextEnabled": false,
|
||||||
|
"SendPrivateMessageOnMention": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user