/// <inheritdoc /> public async Task AddToStarboard(IGuild guild, IUserMessage message, string content, Embed embed) { var starChannel = await GetStarboardChannel(guild); var starEntry = await starChannel.SendMessageAsync(content, false, embed); using (var transaction = await _messageRepository.BeginMaintainTransactionAsync()) { if (await _messageRepository.GetMessage(message.Id) == null) { var creationData = new MessageCreationData { Id = message.Id, GuildId = guild.Id, ChannelId = message.Channel.Id, AuthorId = message.Author.Id, Timestamp = message.Timestamp, }; await _messageRepository.CreateAsync(creationData); } await _messageRepository.UpdateStarboardColumn(message.Id, starEntry.Id); transaction.Commit(); } }
private async Task HandleMessageReceived(IMessage message) { Log.LogDebug("Handling message received event for message #{MessageId}.", message.Id); if (!message.Content.StartsWith('!') && message.Channel is IGuildChannel channel && message.Author is IGuildUser author && author.Guild is IGuild guild && !author.IsBot && !author.IsWebhook) { using (_stats.StartTimer("message_processing_ms")) { await SelfExecuteRequest <IMessageRepository>( async messages => { Log.LogInformation("Logging message #{MessageId} to the database.", message.Id); var creationData = new MessageCreationData { Id = message.Id, GuildId = guild.Id, ChannelId = channel.Id, AuthorId = author.Id, Timestamp = message.Timestamp }; Log.LogDebug("Entity for message #{MessageId}: {@Message}", message.Id, creationData); using (var transaction = await messages.BeginMaintainTransactionAsync()) { try { await messages.CreateAsync(creationData); } catch (Exception ex) { Log.LogError(ex, "An unexpected error occurred when attempting to log message #{MessageId}.", message.Id); } transaction.Commit(); } }); } } }