cleanup
This commit is contained in:
parent
d8182a663a
commit
55221b7bf5
@ -278,7 +278,7 @@ namespace NadekoBot.Classes
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(StreamNotificationConfig other) =>
|
public bool Equals(StreamNotificationConfig other) =>
|
||||||
this.Username.ToLower().Trim() == other.Username.ToLower().Trim() &&
|
this.Username.ToUpperInvariant().Trim() == other.Username.ToUpperInvariant().Trim() &&
|
||||||
this.Type == other.Type &&
|
this.Type == other.Type &&
|
||||||
this.ServerId == other.ServerId;
|
this.ServerId == other.ServerId;
|
||||||
|
|
||||||
|
@ -56,33 +56,36 @@ namespace NadekoBot.Modules.Administration.Commands
|
|||||||
|
|
||||||
// start the userpresence queue
|
// start the userpresence queue
|
||||||
|
|
||||||
NadekoBot.OnReady += () => Task.Run(async () =>
|
NadekoBot.OnReady += () =>
|
||||||
{
|
{
|
||||||
while (true)
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var toSend = new Dictionary<Channel, string>();
|
while (true)
|
||||||
//take everything from the queue and merge the messages which are going to the same channel
|
{
|
||||||
KeyValuePair<Channel, string> item;
|
var toSend = new Dictionary<Channel, string>();
|
||||||
while (voicePresenceUpdates.TryTake(out item))
|
//take everything from the queue and merge the messages which are going to the same channel
|
||||||
{
|
KeyValuePair<Channel, string> item;
|
||||||
if (toSend.ContainsKey(item.Key))
|
while (voicePresenceUpdates.TryTake(out item))
|
||||||
{
|
{
|
||||||
toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
|
if (toSend.ContainsKey(item.Key))
|
||||||
}
|
{
|
||||||
else
|
toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
|
||||||
{
|
}
|
||||||
toSend.Add(item.Key, item.Value);
|
else
|
||||||
}
|
{
|
||||||
}
|
toSend.Add(item.Key, item.Value);
|
||||||
//send merged messages to each channel
|
}
|
||||||
foreach (var k in toSend)
|
}
|
||||||
{
|
//send merged messages to each channel
|
||||||
try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
|
foreach (var k in toSend)
|
||||||
}
|
{
|
||||||
|
try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e)
|
private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e)
|
||||||
|
@ -23,7 +23,9 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
|
|
||||||
public ClashOfClansModule()
|
public ClashOfClansModule()
|
||||||
{
|
{
|
||||||
NadekoBot.OnReady += () => Task.Run(async () =>
|
NadekoBot.OnReady += () =>
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (File.Exists("data/clashofclans/wars.json"))
|
if (File.Exists("data/clashofclans/wars.json"))
|
||||||
{
|
{
|
||||||
@ -109,6 +111,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
|||||||
await Task.Delay(5000);
|
await Task.Delay(5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Save()
|
private static void Save()
|
||||||
|
@ -4,7 +4,6 @@ using Discord.Commands.Permissions;
|
|||||||
using NadekoBot.Classes.JSONModels;
|
using NadekoBot.Classes.JSONModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Permissions.Classes
|
namespace NadekoBot.Modules.Permissions.Classes
|
||||||
@ -14,10 +13,8 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
{
|
{
|
||||||
public static PermissionChecker Instance { get; } = new PermissionChecker();
|
public static PermissionChecker Instance { get; } = new PermissionChecker();
|
||||||
|
|
||||||
//key - sid:command
|
|
||||||
//value - userid
|
|
||||||
private ConcurrentDictionary<string, ulong> commandCooldowns = new ConcurrentDictionary<string, ulong>();
|
private ConcurrentDictionary<string, ulong> commandCooldowns = new ConcurrentDictionary<string, ulong>();
|
||||||
private HashSet<ulong> timeBlackList { get; } = new HashSet<ulong>();
|
private ConcurrentDictionary<ulong, bool> timeBlackList { get; } = new ConcurrentDictionary<ulong, bool>();
|
||||||
|
|
||||||
static PermissionChecker() { }
|
static PermissionChecker() { }
|
||||||
private PermissionChecker()
|
private PermissionChecker()
|
||||||
@ -26,7 +23,6 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//blacklist is cleared every 1.00 seconds. That is the most time anyone will be blocked
|
|
||||||
await Task.Delay(1000).ConfigureAwait(false);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
timeBlackList.Clear();
|
timeBlackList.Clear();
|
||||||
}
|
}
|
||||||
@ -43,21 +39,28 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
if (channel.IsPrivate || channel.Server == null)
|
if (channel.IsPrivate || channel.Server == null)
|
||||||
return command.Category == "Help";
|
return command.Category == "Help";
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (ConfigHandler.IsUserBlacklisted(user.Id) ||
|
if (ConfigHandler.IsUserBlacklisted(user.Id) ||
|
||||||
(!channel.IsPrivate &&
|
(!channel.IsPrivate &&
|
||||||
(ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id))))
|
(ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id))))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (timeBlackList.Contains(user.Id))
|
try
|
||||||
return false;
|
{
|
||||||
|
if (timeBlackList.ContainsKey(user.Id))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch { return false; }
|
||||||
|
|
||||||
if (!channel.IsPrivate && !channel.Server.CurrentUser.GetPermissions(channel).SendMessages)
|
if (!channel.IsPrivate && !channel.Server.CurrentUser.GetPermissions(channel).SendMessages)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeBlackList.Add(user.Id);
|
timeBlackList.TryAdd(user.Id, true);
|
||||||
|
|
||||||
ServerPermissions perms;
|
ServerPermissions perms;
|
||||||
PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms);
|
PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms);
|
||||||
|
@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Initialize()
|
public static Task Initialize() => Task.Run(() =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Reading from the permission files.");
|
Console.WriteLine("Reading from the permission files.");
|
||||||
Directory.CreateDirectory("data/permissions");
|
Directory.CreateDirectory("data/permissions");
|
||||||
@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
Console.WriteLine("Permission initialization complete.");
|
Console.WriteLine("Permission initialization complete.");
|
||||||
}
|
});
|
||||||
|
|
||||||
internal static Permissions GetRolePermissionsById(Server server, ulong id)
|
internal static Permissions GetRolePermissionsById(Server server, ulong id)
|
||||||
{
|
{
|
||||||
@ -157,7 +157,7 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
Newtonsoft.Json.JsonConvert.SerializeObject(serverPerms, Newtonsoft.Json.Formatting.Indented));
|
Newtonsoft.Json.JsonConvert.SerializeObject(serverPerms, Newtonsoft.Json.Formatting.Indented));
|
||||||
});
|
});
|
||||||
|
|
||||||
public static Task WriteToJson() => Task.Run(() =>
|
public static Task WriteToJson() => Task.Run(() =>
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory("data/permissions/");
|
Directory.CreateDirectory("data/permissions/");
|
||||||
foreach (var kvp in PermissionsDict)
|
foreach (var kvp in PermissionsDict)
|
||||||
@ -428,11 +428,13 @@ namespace NadekoBot.Modules.Permissions.Classes
|
|||||||
{
|
{
|
||||||
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
|
||||||
new ServerPermissions(server.Id, server.Name));
|
new ServerPermissions(server.Id, server.Name));
|
||||||
if (value == 0) {
|
if (value == 0)
|
||||||
|
{
|
||||||
int throwaway;
|
int throwaway;
|
||||||
serverPerms.CommandCooldowns.TryRemove(commandName, out throwaway);
|
serverPerms.CommandCooldowns.TryRemove(commandName, out throwaway);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
serverPerms.CommandCooldowns.AddOrUpdate(commandName, value, (str, v) => value);
|
serverPerms.CommandCooldowns.AddOrUpdate(commandName, value, (str, v) => value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user