Ejemplo n.º 1
0
        public static void React(this MessageResponse response, string text, ulong channelId, ulong messageId)
        {
            if (!DiscordEmoji.TryParse(text, out var emoji))
            {
                throw new FormatException("Could not parse the emoji");
            }

            React(response, emoji, channelId, messageId);
        }
Ejemplo n.º 2
0
 public async Task IdentifyEmojiAsync(IContext e)
 {
     if (DiscordEmoji.TryParse(e.GetArgumentPack().Pack.TakeAll(), out var emote))
     {
         await new EmbedBuilder()
         .SetTitle("Emoji Identified!")
         .AddInlineField("Name", emote.Name)
         .AddInlineField("Id", emote.Id.ToString())
         .AddInlineField("Code", $"`{emote}`")
         .ToEmbed()
         .QueueAsync(e, e.GetChannel());
     }
 }
Ejemplo n.º 3
0
 public async Task IdentifyEmojiAsync(EventContext e)
 {
     if (DiscordEmoji.TryParse(e.Arguments.ToString(), out var emote))
     {
         await new EmbedBuilder()
         .SetTitle("Emoji Identified!")
         .AddInlineField("Name", emote.Name)
         .AddInlineField("Id", emote.Id.ToString())
         //.AddInlineField("Created At", emote.ToString())
         .AddInlineField("Code", "`" + emote.ToString() + "`")
         //.SetThumbnail(emote.Url)
         .ToEmbed().QueueToChannelAsync(e.Channel);
     }
 }
Ejemplo n.º 4
0
        public async Task GiveawayAsync(IContext e)
        {
            if (!e.HasFeatureEnabled(FeatureFlags.GiveawayUsingNewScheduler))
            {
                throw new CommandDisabledException();
            }

            DiscordEmoji.TryParse("🎁", out var emoji);

            var args = e.GetArgumentPack();

            var giveawayText = args.TakeRequired <string>();

            if (args.CanTake)
            {
                while (!args.Pack.Peek().HasValue)
                {
                    giveawayText += " " + args.Pack.Take();
                }
            }

            var mml = new MMLParser(e.GetArgumentPack().Pack.TakeAll()).Parse();

            int      amount   = mml.Get("amount", 1);
            TimeSpan timeLeft = mml.Get("time", "1h").GetTimeFromString();

            if (amount > 10)
            {
                await e.ErrorEmbed("We can only allow up to 10 picks per giveaway")
                .ToEmbed()
                .QueueAsync(e, e.GetChannel())
                .ConfigureAwait(false);

                return;
            }

            giveawayText += amount > 1 ? $" x {amount:N0}" : "";

            List <IDiscordUser> winners = new List <IDiscordUser>();

            IDiscordMessage msg = await CreateGiveawayEmbed(e, giveawayText)
                                  .AddField("Time", timeLeft.ToTimeString(e.GetLocale()), true)
                                  .AddField("React to participate", "good luck", true)
                                  .ToEmbed()
                                  .SendToChannelAsync(e.GetChannel())
                                  .ConfigureAwait(false);

            await msg.CreateReactionAsync(emoji)
            .ConfigureAwait(false);

            //taskScheduler.AddTask(e.GetAuthor().Id, async (desc) =>
            //{
            //    msg = await e.GetChannel()
            //        .GetMessageAsync(msg.Id)
            //        .ConfigureAwait(false);
            //    if(msg == null)
            //    {
            //        return;
            //    }

            //    await msg.DeleteReactionAsync(emoji)
            //        .ConfigureAwait(false);

            //    await Task.Delay(1000)
            //        .ConfigureAwait(false);

            //    var reactions = (await msg.GetReactionsAsync(emoji)
            //            .ConfigureAwait(false))
            //        .ToList();

            //    //do
            //    //{
            //    //	reactions.AddRange();
            //    //	reactionsGained += 100;
            //    //} while (reactions.Count == reactionsGained);

            //    // Select random winners
            //    for(int i = 0; i < amount; i++)
            //    {
            //        if(!reactions.Any())
            //        {
            //            break;
            //        }

            //        int index = MikiRandom.Next(reactions.Count());
            //        winners.Add(reactions.ElementAtOrDefault(index));
            //    }

            //    if(updateTask != -1)
            //    {
            //        taskScheduler.CancelReminder(e.GetAuthor().Id, updateTask);
            //    }

            //    string winnerText = string.Join(
            //        "\n", winners.Select(x => $"{x.Username}#{x.Discriminator}").ToArray());
            //    if(string.IsNullOrEmpty(winnerText))
            //    {
            //        winnerText = "nobody!";
            //    }

            //    await msg.EditAsync(new EditMessageArgs
            //    {
            //        Embed = CreateGiveawayEmbed(e, giveawayText)
            //            .AddField("Winners", winnerText)
            //            .ToEmbed()
            //    }).ConfigureAwait(false);
            //}, "description var", timeLeft);
        }