Fixes when prefix is missing
This commit is contained in:
parent
cfe0d09da6
commit
d69a960e45
@ -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;
|
AppendSpace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetModulePrefix(string moduleName)
|
private static string GetModulePrefix(string moduleName, string defaultPrefix)
|
||||||
{
|
{
|
||||||
string prefix;
|
string prefix = null;
|
||||||
if (ModulePrefixes.TryGetValue(moduleName, out prefix))
|
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 prefix ?? defaultPrefix;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ using System.Collections.ObjectModel;
|
|||||||
using NadekoBot.Modules.Permissions;
|
using NadekoBot.Modules.Permissions;
|
||||||
using Module = Discord.Commands.Module;
|
using Module = Discord.Commands.Module;
|
||||||
using NadekoBot.TypeReaders;
|
using NadekoBot.TypeReaders;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
@ -33,7 +34,7 @@ namespace NadekoBot
|
|||||||
public static GoogleApiService Google { get; private set; }
|
public static GoogleApiService Google { get; private set; }
|
||||||
public static StatsService Stats { 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)
|
public async Task RunAsync(string[] args)
|
||||||
{
|
{
|
||||||
@ -86,7 +87,7 @@ namespace NadekoBot
|
|||||||
//load commands and prefixes
|
//load commands and prefixes
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
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
|
// start handling messages received in commandhandler
|
||||||
await CommandHandler.StartHandling();
|
await CommandHandler.StartHandling();
|
||||||
|
Loading…
Reference in New Issue
Block a user