Split Transactions from the GeekbotCommandBase
This commit is contained in:
parent
d708525a2f
commit
833a8a0dd8
2 changed files with 46 additions and 34 deletions
|
@ -1,22 +1,17 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.Core.Database.Models;
|
using Geekbot.Core.Database.Models;
|
||||||
using Geekbot.Core.ErrorHandling;
|
using Geekbot.Core.ErrorHandling;
|
||||||
using Geekbot.Core.GuildSettingsManager;
|
using Geekbot.Core.GuildSettingsManager;
|
||||||
using Sentry;
|
|
||||||
|
|
||||||
namespace Geekbot.Core
|
namespace Geekbot.Core
|
||||||
{
|
{
|
||||||
public class GeekbotCommandBase : ModuleBase<ICommandContext>
|
public class GeekbotCommandBase : TransactionModuleBase
|
||||||
{
|
{
|
||||||
protected readonly IGuildSettingsManager GuildSettingsManager;
|
protected readonly IGuildSettingsManager GuildSettingsManager;
|
||||||
protected GuildSettingsModel GuildSettings;
|
protected GuildSettingsModel GuildSettings;
|
||||||
protected readonly IErrorHandler ErrorHandler;
|
protected readonly IErrorHandler ErrorHandler;
|
||||||
protected ITransaction Transaction;
|
|
||||||
|
|
||||||
protected GeekbotCommandBase(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager)
|
protected GeekbotCommandBase(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager)
|
||||||
{
|
{
|
||||||
|
@ -28,20 +23,6 @@ namespace Geekbot.Core
|
||||||
{
|
{
|
||||||
base.BeforeExecute(command);
|
base.BeforeExecute(command);
|
||||||
|
|
||||||
// Transaction Setup
|
|
||||||
Transaction = SentrySdk.StartTransaction(new Transaction(command.Name, "Exec"));
|
|
||||||
Transaction.SetTags(new []
|
|
||||||
{
|
|
||||||
new KeyValuePair<string, string>("GuildId", Context.Guild.Id.ToString()),
|
|
||||||
new KeyValuePair<string, string>("Guild", Context.Guild.Name),
|
|
||||||
});
|
|
||||||
Transaction.User = new User()
|
|
||||||
{
|
|
||||||
Id = Context.User.Id.ToString(),
|
|
||||||
Username = Context.User.Username,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Command Setup
|
|
||||||
var setupSpan = Transaction.StartChild("Setup");
|
var setupSpan = Transaction.StartChild("Setup");
|
||||||
|
|
||||||
GuildSettings = GuildSettingsManager.GetSettings(Context?.Guild?.Id ?? 0);
|
GuildSettings = GuildSettingsManager.GetSettings(Context?.Guild?.Id ?? 0);
|
||||||
|
@ -50,19 +31,5 @@ namespace Geekbot.Core
|
||||||
|
|
||||||
setupSpan.Finish();
|
setupSpan.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AfterExecute(CommandInfo command)
|
|
||||||
{
|
|
||||||
base.AfterExecute(command);
|
|
||||||
Transaction.Finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Task<IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
|
|
||||||
{
|
|
||||||
var replySpan = Transaction.StartChild("Reply");
|
|
||||||
var msg = base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference);
|
|
||||||
replySpan.Finish();
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
45
src/Core/TransactionModuleBase.cs
Normal file
45
src/Core/TransactionModuleBase.cs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Sentry;
|
||||||
|
|
||||||
|
namespace Geekbot.Core
|
||||||
|
{
|
||||||
|
public class TransactionModuleBase : ModuleBase<ICommandContext>
|
||||||
|
{
|
||||||
|
protected ITransaction Transaction;
|
||||||
|
|
||||||
|
protected override void BeforeExecute(CommandInfo command)
|
||||||
|
{
|
||||||
|
base.BeforeExecute(command);
|
||||||
|
|
||||||
|
// Transaction Setup
|
||||||
|
Transaction = SentrySdk.StartTransaction(new Transaction(command.Name, "Exec"));
|
||||||
|
Transaction.SetTags(new []
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("GuildId", Context.Guild.Id.ToString()),
|
||||||
|
new KeyValuePair<string, string>("Guild", Context.Guild.Name),
|
||||||
|
});
|
||||||
|
Transaction.User = new User()
|
||||||
|
{
|
||||||
|
Id = Context.User.Id.ToString(),
|
||||||
|
Username = Context.User.Username,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AfterExecute(CommandInfo command)
|
||||||
|
{
|
||||||
|
base.AfterExecute(command);
|
||||||
|
Transaction.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task<IUserMessage> ReplyAsync(string message = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
|
||||||
|
{
|
||||||
|
var replySpan = Transaction.StartChild("Reply");
|
||||||
|
var msg = base.ReplyAsync(message, isTTS, embed, options, allowedMentions, messageReference);
|
||||||
|
replySpan.Finish();
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue