Project now magically works

This commit is contained in:
Kwoth 2016-10-10 06:38:20 +02:00
parent e60034728c
commit fd729e553d
8 changed files with 35 additions and 18 deletions

View File

@ -6,6 +6,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
namespace System.Collections.Concurrent
@ -672,6 +673,18 @@ namespace System.Collections.Concurrent
}
}
public int RemoveWhere(Func<T, bool> predicate)
{
var elems = this.Where(predicate);
var removed = 0;
foreach (var elem in elems)
{
if (this.TryRemove(elem))
removed++;
}
return removed;
}
private void AcquireAllLocks(ref int locksAcquired)
{
// First, acquire lock 0

View File

@ -150,16 +150,13 @@ namespace NadekoBot.Modules.CustomReactions
if (toDelete.GuildId == null && channel == null)
{
uow.CustomReactions.Remove(toDelete);
var toRemove = GlobalReactions.FirstOrDefault(cr => cr.Id == toDelete.Id);
GlobalReactions.TryRemove(toRemove);
GlobalReactions.RemoveWhere(cr => cr.Id == toDelete.Id);
success = true;
}
else if (toDelete.GuildId != null && channel?.Guild.Id == toDelete.GuildId)
{
uow.CustomReactions.Remove(toDelete);
var crs = GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>());
var toRemove = crs.FirstOrDefault(cr => cr.Id == toDelete.Id);
GuildReactions.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CustomReaction>()).RemoveWhere(cr=>cr.Id == toDelete.Id);
success = true;
}
if(success)

View File

@ -76,9 +76,7 @@ namespace NadekoBot.Modules.Permissions
else
{
uow.BotConfig.GetOrCreate().Blacklist.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
var toRemove = BlacklistedItems.FirstOrDefault(bi => bi.ItemId == id && bi.Type == type);
if (toRemove != null)
BlacklistedItems.TryRemove(toRemove);
BlacklistedItems.RemoveWhere(bi => bi.ItemId == id && bi.Type == type);
}
await uow.CompleteAsync().ConfigureAwait(false);
}

View File

@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Permissions
using (var uow = DbHandler.UnitOfWork())
{
var configs = uow.GuildConfigs.GetAll();
commandCooldowns = new ConcurrentDictionary<ulong, ConcurrentHashSet<CommandCooldown>>(configs.ToDictionary(k => k.GuildId, v => v.CommandCooldowns));
commandCooldowns = new ConcurrentDictionary<ulong, ConcurrentHashSet<CommandCooldown>>(configs.ToDictionary(k => k.GuildId, v => new ConcurrentHashSet<CommandCooldown>(v.CommandCooldowns)));
}
}
[NadekoCommand, Usage, Description, Aliases]

View File

@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Permissions
}
else
{
InviteFilteringServers.Remove(channel.Guild.Id);
InviteFilteringServers.TryRemove(channel.Guild.Id);
await channel.SendMessageAsync("`Invite filtering disabled on this server.`").ConfigureAwait(false);
}
}
@ -117,7 +117,7 @@ namespace NadekoBot.Modules.Permissions
}
else
{
InviteFilteringChannels.Remove(channel.Id);
InviteFilteringChannels.TryRemove(channel.Id);
await channel.SendMessageAsync("`Invite filtering disabled on this channel.`").ConfigureAwait(false);
}
}
@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Permissions
}
else
{
WordFilteringServers.Remove(channel.Guild.Id);
WordFilteringServers.TryRemove(channel.Guild.Id);
await channel.SendMessageAsync("`Word filtering disabled on this server.`").ConfigureAwait(false);
}
}
@ -176,7 +176,7 @@ namespace NadekoBot.Modules.Permissions
}
else
{
WordFilteringChannels.Remove(channel.Id);
WordFilteringChannels.TryRemove(channel.Id);
await channel.SendMessageAsync("`Word filtering disabled on this channel.`").ConfigureAwait(false);
}
}
@ -215,7 +215,7 @@ namespace NadekoBot.Modules.Permissions
}
else
{
filteredWords.Remove(word);
filteredWords.TryRemove(word);
await channel.SendMessageAsync($"Word `{word}` removed from the list of filtered words.")
.ConfigureAwait(false);
}

View File

@ -195,7 +195,7 @@ namespace NadekoBot.Modules.Searches
toRemove = streams.Where(fs => fs.ChannelId == channel.Id && fs.Username.ToUpperInvariant() == username).FirstOrDefault();
if (toRemove != null)
{
config.FollowedStreams = streams.Except(new[] { toRemove }).ToList();
config.FollowedStreams = new HashSet<FollowedStream>(streams.Except(new[] { toRemove }));
await uow.CompleteAsync();
}
}

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
namespace NadekoBot.Services.Database
{
@ -47,7 +48,7 @@ namespace NadekoBot.Services.Database
{
var bc = new BotConfig();
bc.ModulePrefixes.AddRange(new ConcurrentHashSet<ModulePrefix>()
bc.ModulePrefixes.AddRange(new HashSet<ModulePrefix>()
{
new ModulePrefix() { ModuleName = "Administration", Prefix = "." },
new ModulePrefix() { ModuleName = "Searches", Prefix = "~" },
@ -64,7 +65,7 @@ namespace NadekoBot.Services.Database
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." }
});
bc.RaceAnimals.AddRange(new ConcurrentHashSet<RaceAnimal>
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
{
new RaceAnimal { Icon = "🐼", Name = "Panda" },
new RaceAnimal { Icon = "🐻", Name = "Bear" },
@ -75,7 +76,7 @@ namespace NadekoBot.Services.Database
new RaceAnimal { Icon = "🦀", Name = "Crab" },
new RaceAnimal { Icon = "🦄", Name = "Unicorn" }
});
bc.EightBallResponses.AddRange(new ConcurrentHashSet<EightBallResponse>
bc.EightBallResponses.AddRange(new HashSet<EightBallResponse>
{
new EightBallResponse() { Text = "Most definitely yes" },
new EightBallResponse() { Text = "For sure" },

View File

@ -23,6 +23,14 @@ namespace NadekoBot.Extensions
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
}
public static void AddRange<T>(this HashSet<T> target, IEnumerable<T> elements) where T : class
{
foreach (var item in elements)
{
target.Add(item);
}
}
public static bool IsInteger(this decimal number) => number == Math.Truncate(number);
public static string SanitizeMentions(this string str) =>