コード例 #1
0
 public async Task AddStarboardMessage(ulong guildId, ulong messageId, ulong postedMessageId)
 => await _soraTransactor.DoInTransactionAsync(async context =>
 {
     // Since this is a weak entity the guild has to exist
     await GuildRepository.GetOrSetAndGetGuild(guildId, context).ConfigureAwait(false);
     // Actually create and add it
     context.StarboardMessages.Add(new StarboardMessage(messageId, postedMessageId, guildId));
     await context.SaveChangesAsync().ConfigureAwait(false);
 }).ConfigureAwait(false);
コード例 #2
0
        public async Task SetStarboardChannelId(ulong guildId, ulong starboardChannelId)
        => await _soraTransactor.DoInTransactionAsync(async context =>
        {
            // We have to create a guild if it doesnt exist, bcs the starboard is a weak entity.
            await GuildRepository.GetOrSetAndGetGuild(guildId, context).ConfigureAwait(false);

            // Then we try and get or create the starboard
            var starboard = await context.Starboards.FindAsync(guildId).ConfigureAwait(false);
            if (starboard == null)
            {
                // Create it
                starboard = new Starboard(guildId, starboardChannelId);
                // ReSharper disable once MethodHasAsyncOverload
                context.Starboards.Add(starboard);
            }
            else
            {
                starboard.StarboardChannelId = starboardChannelId;
            }

            await context.SaveChangesAsync();
        }).ConfigureAwait(false);