This commit is contained in:
Kwoth 2016-09-05 21:34:59 +02:00
parent d8182a663a
commit 55221b7bf5
5 changed files with 52 additions and 41 deletions

View File

@ -278,7 +278,7 @@ namespace NadekoBot.Classes
}
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.ServerId == other.ServerId;

View File

@ -56,33 +56,36 @@ namespace NadekoBot.Modules.Administration.Commands
// start the userpresence queue
NadekoBot.OnReady += () => Task.Run(async () =>
{
while (true)
{
var toSend = new Dictionary<Channel, string>();
//take everything from the queue and merge the messages which are going to the same channel
KeyValuePair<Channel, string> item;
while (voicePresenceUpdates.TryTake(out item))
{
if (toSend.ContainsKey(item.Key))
{
toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
}
else
{
toSend.Add(item.Key, item.Value);
}
}
//send merged messages to each channel
foreach (var k in toSend)
{
try { await k.Key.SendMessage(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
}
NadekoBot.OnReady += () =>
{
Task.Run(async () =>
{
while (true)
{
var toSend = new Dictionary<Channel, string>();
//take everything from the queue and merge the messages which are going to the same channel
KeyValuePair<Channel, string> item;
while (voicePresenceUpdates.TryTake(out item))
{
if (toSend.ContainsKey(item.Key))
{
toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
}
else
{
toSend.Add(item.Key, item.Value);
}
}
//send merged messages to each channel
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)

View File

@ -23,7 +23,9 @@ namespace NadekoBot.Modules.ClashOfClans
public ClashOfClansModule()
{
NadekoBot.OnReady += () => Task.Run(async () =>
NadekoBot.OnReady += () =>
{
Task.Run(async () =>
{
if (File.Exists("data/clashofclans/wars.json"))
{
@ -109,6 +111,7 @@ namespace NadekoBot.Modules.ClashOfClans
await Task.Delay(5000);
}
});
};
}
private static void Save()

View File

@ -4,7 +4,6 @@ using Discord.Commands.Permissions;
using NadekoBot.Classes.JSONModels;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Permissions.Classes
@ -14,10 +13,8 @@ namespace NadekoBot.Modules.Permissions.Classes
{
public static PermissionChecker Instance { get; } = new PermissionChecker();
//key - sid:command
//value - userid
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() { }
private PermissionChecker()
@ -26,7 +23,6 @@ namespace NadekoBot.Modules.Permissions.Classes
{
while (true)
{
//blacklist is cleared every 1.00 seconds. That is the most time anyone will be blocked
await Task.Delay(1000).ConfigureAwait(false);
timeBlackList.Clear();
}
@ -43,21 +39,28 @@ namespace NadekoBot.Modules.Permissions.Classes
if (channel.IsPrivate || channel.Server == null)
return command.Category == "Help";
if (user == null)
return false;
if (ConfigHandler.IsUserBlacklisted(user.Id) ||
(!channel.IsPrivate &&
(ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id))))
{
return false;
}
if (timeBlackList.Contains(user.Id))
return false;
try
{
if (timeBlackList.ContainsKey(user.Id))
return false;
}
catch { return false; }
if (!channel.IsPrivate && !channel.Server.CurrentUser.GetPermissions(channel).SendMessages)
{
return false;
}
timeBlackList.Add(user.Id);
timeBlackList.TryAdd(user.Id, true);
ServerPermissions perms;
PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms);

View File

@ -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.");
Directory.CreateDirectory("data/permissions");
@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Permissions.Classes
catch { }
}
Console.WriteLine("Permission initialization complete.");
}
});
internal static Permissions GetRolePermissionsById(Server server, ulong id)
{
@ -428,11 +428,13 @@ namespace NadekoBot.Modules.Permissions.Classes
{
var serverPerms = PermissionsDict.GetOrAdd(server.Id,
new ServerPermissions(server.Id, server.Name));
if (value == 0) {
if (value == 0)
{
int throwaway;
serverPerms.CommandCooldowns.TryRemove(commandName, out throwaway);
}
else {
else
{
serverPerms.CommandCooldowns.AddOrUpdate(commandName, value, (str, v) => value);
}