observing streams are now in serverspecificconfig
This commit is contained in:
parent
b073a08030
commit
ac8ade46a2
1
.gitignore
vendored
1
.gitignore
vendored
@ -34,3 +34,4 @@ Tests/bin
|
||||
#!**/packages/repositories.config
|
||||
NadekoBot/bin/Debug/data/nadekobot.sqlite
|
||||
NadekoBot/bin/Debug/data/config.json
|
||||
NadekoBot/bin/Debug/data/ServerSpecificConfigs.json
|
@ -13,9 +13,6 @@ namespace NadekoBot.Classes.JSONModels {
|
||||
[JsonIgnore]
|
||||
public List<Quote> Quotes { get; set; } = new List<Quote>();
|
||||
|
||||
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();
|
||||
public HashSet<ulong> ServerBlacklist { get; set; } = new HashSet<ulong>();
|
||||
@ -113,29 +110,6 @@ namespace NadekoBot.Classes.JSONModels {
|
||||
public static bool IsUserBlacklisted(ulong id) => NadekoBot.Config.UserBlacklist.Contains(id);
|
||||
}
|
||||
|
||||
public class StreamNotificationConfig : IEquatable<StreamNotificationConfig> {
|
||||
public string Username { get; set; }
|
||||
public StreamType Type { get; set; }
|
||||
public ulong ServerId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
public bool LastStatus { get; set; }
|
||||
|
||||
public enum StreamType {
|
||||
Twitch,
|
||||
Hitbox,
|
||||
YoutubeGaming
|
||||
}
|
||||
|
||||
public bool Equals(StreamNotificationConfig other) =>
|
||||
this.Username.ToLower().Trim() == other.Username.ToLower().Trim() &&
|
||||
this.Type == other.Type &&
|
||||
this.ServerId == other.ServerId;
|
||||
|
||||
public override int GetHashCode() {
|
||||
return (int)((int)ServerId + Username.Length + (int)Type);
|
||||
}
|
||||
}
|
||||
|
||||
public class Quote {
|
||||
public string Author { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using NadekoBot.Classes.JSONModels;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Classes {
|
||||
@ -34,6 +35,8 @@ namespace NadekoBot.Classes {
|
||||
|
||||
private readonly ConcurrentDictionary<ulong, ServerSpecificConfig> configs;
|
||||
|
||||
public IEnumerable<ServerSpecificConfig> AllConfigs => configs.Values;
|
||||
|
||||
public ServerSpecificConfig Of(ulong id) =>
|
||||
configs.GetOrAdd(id, _ => new ServerSpecificConfig());
|
||||
|
||||
@ -82,8 +85,23 @@ namespace NadekoBot.Classes {
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
private ObservableCollection<StreamNotificationConfig> observingStreams;
|
||||
public ObservableCollection<StreamNotificationConfig> ObservingStreams {
|
||||
get { return observingStreams; }
|
||||
set {
|
||||
observingStreams = value;
|
||||
if (value != null)
|
||||
observingStreams.CollectionChanged += (s, e) => {
|
||||
if (!SpecificConfigurations.Instantiated) return;
|
||||
OnPropertyChanged();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public ServerSpecificConfig() {
|
||||
ListOfSelfAssignableRoles = new ObservableCollection<ulong>();
|
||||
ObservingStreams = new ObservableCollection<StreamNotificationConfig>();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged = delegate { SpecificConfigurations.Default.Save(); };
|
||||
@ -93,4 +111,27 @@ namespace NadekoBot.Classes {
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
public class StreamNotificationConfig : IEquatable<StreamNotificationConfig> {
|
||||
public string Username { get; set; }
|
||||
public StreamType Type { get; set; }
|
||||
public ulong ServerId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
public bool LastStatus { get; set; }
|
||||
|
||||
public enum StreamType {
|
||||
Twitch,
|
||||
Hitbox,
|
||||
YoutubeGaming
|
||||
}
|
||||
|
||||
public bool Equals(StreamNotificationConfig other) =>
|
||||
this.Username.ToLower().Trim() == other.Username.ToLower().Trim() &&
|
||||
this.Type == other.Type &&
|
||||
this.ServerId == other.ServerId;
|
||||
|
||||
public override int GetHashCode() {
|
||||
return (int)((int)ServerId + Username.Length + (int)Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ namespace NadekoBot.Commands {
|
||||
|
||||
checkTimer.Elapsed += async (s, e) => {
|
||||
try {
|
||||
var streams = NadekoBot.Config.ObservingStreams;
|
||||
if (streams == null || !streams.Any()) return;
|
||||
var streams = SpecificConfigurations.Default.AllConfigs.SelectMany(c => c.ObservingStreams);
|
||||
if (!streams.Any()) return;
|
||||
|
||||
foreach (var stream in streams) {
|
||||
Tuple<bool, string> data;
|
||||
@ -108,7 +108,9 @@ namespace NadekoBot.Commands {
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
return;
|
||||
|
||||
var toRemove = NadekoBot.Config.ObservingStreams
|
||||
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
|
||||
var toRemove = config.ObservingStreams
|
||||
.FirstOrDefault(snc => snc.ChannelId == e.Channel.Id &&
|
||||
snc.Username.ToLower().Trim() == username);
|
||||
if (toRemove == null) {
|
||||
@ -116,7 +118,7 @@ namespace NadekoBot.Commands {
|
||||
return;
|
||||
}
|
||||
|
||||
NadekoBot.Config.ObservingStreams.Remove(toRemove);
|
||||
config.ObservingStreams.Remove(toRemove);
|
||||
ConfigHandler.SaveConfig();
|
||||
await e.Channel.SendMessage($":ok: Removed `{toRemove.Username}`'s stream from notifications.");
|
||||
});
|
||||
@ -126,7 +128,10 @@ namespace NadekoBot.Commands {
|
||||
.Description("Lists all streams you are following on this server." +
|
||||
"\n**Usage**: ~ls")
|
||||
.Do(async e => {
|
||||
var streams = NadekoBot.Config.ObservingStreams.Where(snc =>
|
||||
|
||||
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
|
||||
var streams = config.ObservingStreams.Where(snc =>
|
||||
snc.ServerId == e.Server.Id);
|
||||
|
||||
var streamsArray = streams as StreamNotificationConfig[] ?? streams.ToArray();
|
||||
@ -153,13 +158,15 @@ namespace NadekoBot.Commands {
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
return;
|
||||
|
||||
var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
|
||||
var stream = new StreamNotificationConfig {
|
||||
ServerId = e.Server.Id,
|
||||
ChannelId = e.Channel.Id,
|
||||
Username = username,
|
||||
Type = type,
|
||||
};
|
||||
var exists = NadekoBot.Config.ObservingStreams.Contains(stream);
|
||||
var exists = config.ObservingStreams.Contains(stream);
|
||||
if (exists) {
|
||||
await e.Channel.SendMessage(":anger: I am already notifying that stream on this channel.");
|
||||
}
|
||||
@ -182,8 +189,7 @@ namespace NadekoBot.Commands {
|
||||
if (!exists)
|
||||
msg = $":ok: I will notify this channel when status changes.\n{msg}";
|
||||
await e.Channel.SendMessage(msg);
|
||||
NadekoBot.Config.ObservingStreams.Add(stream);
|
||||
ConfigHandler.SaveConfig();
|
||||
config.ObservingStreams.Add(stream);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
"DontJoinServers": false,
|
||||
"ForwardMessages": true,
|
||||
"IsRotatingStatus": false,
|
||||
"ObservingStreams": [],
|
||||
"RotatingStatuses": [],
|
||||
"CommandPrefixes": {
|
||||
"Administration": ".",
|
||||
|
Loading…
Reference in New Issue
Block a user