Exemplo n.º 1
0
    public async Task PresentQuote(CommandContext ctx, SBDSODC.UserQuote quote, Language lang)
    {
        var b = new DiscordEmbedBuilder
        {
            Description = quote.QuoteContent,
            Footer      = new DiscordEmbedBuilder.EmbedFooter
            {
                Text = string.Format(lang.QuotePreviewQuoteID, quote.QuoteId)
            },
            Timestamp = quote.TimeStamp
        };
        var msg = await new DiscordMessageBuilder().WithReply(ctx.Message.Id).WithEmbed(b.Build())
                  .AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "deletequote", null, false,
                                                            new DiscordComponentEmoji("🗑"))).SendAsync(ctx.Channel);
        var response = await msg.WaitForButtonAsync(ctx.User, TimeSpan.FromSeconds(300));

        if (!response.TimedOut)
        {
            Dctx.userQuotes.Remove(quote);
            await Dctx.SaveChangesAsync();

            await response.Result.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage,
                                                                  new DiscordInteractionResponseBuilder().WithContent(lang.QuotePreviewDeleteSuccess));
        }
        else
        {
            await msg.ModifyAsync(new DiscordMessageBuilder().WithReply(ctx.Message.Id).WithEmbed(b.Build()));
        }
    }
Exemplo n.º 2
0
    public async Task Add(CommandContext ctx, [RemainingText] string content)
    {
        var lang = await Language.GetLanguageFromCtxAsync(ctx);

        var quote = new SBDSODC.UserQuote
        {
            QuoteContent = content,
            QuoteId      = RandomGenerator.RandomAbcString(6),
            TimeStamp    = DateTime.UtcNow,
            UserId       = ctx.User.Id
        };
        await Dctx.userQuotes.AddAsync(quote);

        await Dctx.SaveChangesAsync();

        await PresentQuote(ctx, quote, lang);
    }