Command handler logging
This commit is contained in:
parent
828053d299
commit
dfeb1223fa
@ -68,6 +68,7 @@ namespace NadekoBot.Services
|
||||
|
||||
private async Task MessageReceivedHandler(IMessage msg)
|
||||
{
|
||||
_log.Info("Message received.");
|
||||
var usrMsg = msg as IUserMessage;
|
||||
if (usrMsg == null)
|
||||
return;
|
||||
@ -96,7 +97,6 @@ namespace NadekoBot.Services
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var filteredWords = Permissions.FilterCommands.FilteredWordsForChannel(usrMsg.Channel.Id, guild.Id).Concat(Permissions.FilterCommands.FilteredWordsForServer(guild.Id));
|
||||
var wordsInMessage = usrMsg.Content.ToLowerInvariant().Split(' ');
|
||||
if (filteredWords.Any(w => wordsInMessage.Contains(w)))
|
||||
@ -123,25 +123,7 @@ namespace NadekoBot.Services
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
bool verbose = false;
|
||||
Permission rootPerm = null;
|
||||
string permRole = "";
|
||||
if (guild != null)
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
||||
verbose = config.VerbosePermissions;
|
||||
rootPerm = config.RootPermission;
|
||||
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
_log.Info("Done checks.");
|
||||
var throwaway = Task.Run(async () =>
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
@ -149,9 +131,10 @@ namespace NadekoBot.Services
|
||||
|
||||
try
|
||||
{
|
||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, rootPerm, permRole, MultiMatchHandling.Best);
|
||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
|
||||
var command = t.Item1;
|
||||
var result = t.Item2;
|
||||
var verbose = t.Item2;
|
||||
var result = t.Item3;
|
||||
sw.Stop();
|
||||
var channel = (usrMsg.Channel as ITextChannel);
|
||||
if (result.IsSuccess)
|
||||
@ -206,20 +189,19 @@ namespace NadekoBot.Services
|
||||
if (ex.InnerException != null)
|
||||
_log.Warn(ex.InnerException, "Inner Exception of the error in CommandHandler");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
_log.Error(ex, "Error in the outter scope of the commandhandler.");
|
||||
if (ex.InnerException != null)
|
||||
_log.Error(ex.InnerException, "Inner exception: ");
|
||||
_log.Info("Command handling done.");
|
||||
}
|
||||
});
|
||||
_log.Info("Command handling started.");
|
||||
return;
|
||||
}
|
||||
|
||||
public async Task<Tuple<Command, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, Permission rootPerm, string permRole, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
||||
public async Task<Tuple<Command,bool, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
||||
var searchResult = _commandService.Search(message, input);
|
||||
if (!searchResult.IsSuccess)
|
||||
return new Tuple<Command, IResult>(null, searchResult);
|
||||
return new Tuple<Command, bool, IResult>(null, false, searchResult);
|
||||
|
||||
var commands = searchResult.Commands;
|
||||
for (int i = commands.Count - 1; i >= 0; i--)
|
||||
@ -228,7 +210,7 @@ namespace NadekoBot.Services
|
||||
if (!preconditionResult.IsSuccess)
|
||||
{
|
||||
if (commands.Count == 1)
|
||||
return new Tuple<Command, IResult>(null, searchResult);
|
||||
return new Tuple<Command, bool, IResult>(null, false, searchResult);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
@ -252,11 +234,25 @@ namespace NadekoBot.Services
|
||||
if (!parseResult.IsSuccess)
|
||||
{
|
||||
if (commands.Count == 1)
|
||||
return new Tuple<Command, IResult>(null, parseResult);
|
||||
return new Tuple<Command, bool, IResult>(null, false, parseResult);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bool verbose = false;
|
||||
Permission rootPerm = null;
|
||||
string permRole = "";
|
||||
if (guild != null)
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
||||
verbose = config.VerbosePermissions;
|
||||
rootPerm = config.RootPermission;
|
||||
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
_log.Info("Permissions retrieved");
|
||||
var cmd = commands[i];
|
||||
//check permissions
|
||||
if (guild != null)
|
||||
@ -265,7 +261,7 @@ namespace NadekoBot.Services
|
||||
if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd.Text, cmd.Module.Name, out index))
|
||||
{
|
||||
var returnMsg = $"Permission number #{index + 1} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action.";
|
||||
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, returnMsg));
|
||||
return new Tuple<Command, bool, IResult>(cmd, verbose, SearchResult.FromError(CommandError.Exception, returnMsg));
|
||||
}
|
||||
|
||||
|
||||
@ -273,19 +269,19 @@ namespace NadekoBot.Services
|
||||
{
|
||||
if (!((IGuildUser)user).Roles.Any(r => r.Name.Trim().ToLowerInvariant() == permRole))
|
||||
{
|
||||
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, $"You need the **{permRole}** role in order to use permission commands."));
|
||||
return new Tuple<Command, bool, IResult>(cmd, false, SearchResult.FromError(CommandError.Exception, $"You need the **{permRole}** role in order to use permission commands."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (CmdCdsCommands.HasCooldown(cmd, guild, user))
|
||||
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
|
||||
return new Tuple<Command, bool, IResult>(cmd, false, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
|
||||
|
||||
return new Tuple<Command, IResult>(commands[i], await commands[i].Execute(message, parseResult));
|
||||
return new Tuple<Command, bool, IResult>(commands[i], false, await commands[i].Execute(message, parseResult));
|
||||
}
|
||||
|
||||
return new Tuple<Command, IResult>(null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));
|
||||
return new Tuple<Command, bool, IResult>(null, false, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user