Fixes when prefix is missing

This commit is contained in:
Kwoth 2016-10-12 04:47:28 +02:00
parent cfe0d09da6
commit d69a960e45
2 changed files with 11 additions and 9 deletions

View File

@ -30,21 +30,22 @@ namespace NadekoBot.Attributes
}
}
public NadekoModuleAttribute(string moduleName, string defaultPrefix) : base(GetModulePrefix(moduleName) ?? defaultPrefix)
public NadekoModuleAttribute(string moduleName, string defaultPrefix) : base(GetModulePrefix(moduleName, defaultPrefix))
{
AppendSpace = false;
}
private static string GetModulePrefix(string moduleName)
private static string GetModulePrefix(string moduleName, string defaultPrefix)
{
string prefix;
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
string prefix = null;
if (!ModulePrefixes.TryGetValue(moduleName, out prefix))
{
return prefix;
NadekoBot.ModulePrefixes.TryAdd(moduleName, defaultPrefix);
NLog.LogManager.GetCurrentClassLogger().Warn("Prefix not found for {0}. Will use default one: {1}", moduleName, defaultPrefix);
}
NLog.LogManager.GetCurrentClassLogger().Warn("Cache not hit for {0}", moduleName);
return null;
return prefix ?? defaultPrefix;
}
}
}

View File

@ -17,6 +17,7 @@ using System.Collections.ObjectModel;
using NadekoBot.Modules.Permissions;
using Module = Discord.Commands.Module;
using NadekoBot.TypeReaders;
using System.Collections.Concurrent;
namespace NadekoBot
{
@ -33,7 +34,7 @@ namespace NadekoBot
public static GoogleApiService Google { get; private set; }
public static StatsService Stats { get; private set; }
public static IReadOnlyDictionary<string, string> ModulePrefixes { get; private set; }
public static ConcurrentDictionary<string, string> ModulePrefixes { get; private set; }
public async Task RunAsync(string[] args)
{
@ -86,7 +87,7 @@ namespace NadekoBot
//load commands and prefixes
using (var uow = DbHandler.UnitOfWork())
{
ModulePrefixes = new ReadOnlyDictionary<string, string>(uow.BotConfig.GetOrCreate().ModulePrefixes.ToDictionary(m => m.ModuleName, m => m.Prefix));
ModulePrefixes = new ConcurrentDictionary<string, string>(uow.BotConfig.GetOrCreate().ModulePrefixes.ToDictionary(m => m.ModuleName, m => m.Prefix));
}
// start handling messages received in commandhandler
await CommandHandler.StartHandling();