Exemple #1
0
    private void BindChoices(Choice[] choices, string key, int triggerID)
    {
        int buttonCount = choices.Length;

        if (buttonCount > existingButton)
        {
            GenerateButtons(buttonCount - existingButton);
        }
        for (int i = 0; i < buttonCount; i++)
        {
            int          choiceNumber = i;
            Conversation c            = choices[i].nextConversation;
            buttonText[i].text            = choices[i].text;
            buttonTransforms[i].offsetMax = buttonText[i].GetPreferredValues(choices[i].text) * new Vector2(0.7f, 1) + new Vector2(10, 0);
            buttonTransforms[i].offsetMin = -buttonText[i].GetPreferredValues(choices[i].text) * new Vector2(0.7f, 1) - new Vector2(10, 0);
            buttons[i].onClick.RemoveAllListeners();
            buttons[i].onClick.AddListener(() => {
                ResetButtons(buttonCount);
                ChoiceTracker.Track(key, choiceNumber);
                DialogueManager.instance.SetupChoiceEvent(choiceNumber);
                DialogueManager.instance.LoadConversation(c, triggerID);
            });
        }
        ArrangeButtons(buttonCount);
    }
        public bool NextSequence()
        {
            Debug.Assert(choices.Count == 0 || nextChoiceIdx == choices.Count);
            if (choices.Count > 0)
            {
                while (true)
                {
                    ChoiceTracker foundChoice = choices.Last();
                    if (foundChoice.index == foundChoice.range.maxIndex)
                    {
                        choices.RemoveAt(choices.Count - 1);
                        if (choices.Count == 0)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        // found a thing we can increment, we're done
                        foundChoice.index++;
                        choices[choices.Count - 1] = foundChoice;
                        break;
                    }
                }
            }

            nextChoiceIdx = 0;
            return(true);
        }
        public int NextChoice(ChoiceRange range)
        {
            Debug.Assert(!done);
            ChoiceTracker c;

            if (nextChoiceIdx >= choices.Count)
            {
                c = new ChoiceTracker(range);
                choices.Add(c);
            }
            else
            {
                c = choices[nextChoiceIdx];
                //Debug.Assert(c.min == min && c.max == max);
            }

            nextChoiceIdx++;
            return(c.value);
        }
Exemple #4
0
        public async Task AddEmoji(string name, string nameOverride = null)
        {
            var emoji = DiscordEmoji.EmoteFromName(name);

            if (emoji == null)
            {
                await ReplyAsync("No emoji by that name was found on DiscordEmoji." +
                                 "\nPlease select a valid emoji from the catalog at https://discordemoji.com" +
                                 "\n\n(The emoji name is case sensitive. Don't include the colons in your command!)" +
                                 "\n\n If you're too lazy to go on the website, you can use the ``emojis`` command to list emojis." +
                                 $"\n``{Configuration.Prefix}emojis <category> <page (Optional)>``");

                return;
            }

            if (!(Context.Channel as ITextChannel).IsNsfw && DiscordEmoji.GetCategoryName(emoji.Category) == "NSFW")
            {
                await ReplyAsync("That's an NSFW emoji, go into an NSFW channel for that.");

                return;
            }

            var guildEmoji = Context.Guild.Emotes;

            if (guildEmoji.Count(x => x.Animated) >= 50 && emoji.Animated)
            {
                await ReplyAsync("You already have fifty (50) animated emoji on this server. That is Discord's limit. Remove some before adding more.");

                return;
            }

            if (guildEmoji.Count(x => !x.Animated) >= 50 && !emoji.Animated)
            {
                await ReplyAsync("You already have fifty (50) emoji on this server. That is Discord's limit. Remove some before adding more.");

                return;
            }

            EmbedBuilder embed = new EmbedBuilder
            {
                Title        = "Confirmation",
                Description  = "Are you sure that you want to add this emoji to your server?\nReact with ✅ in less than 20 seconds to confirm. React with ❌ to abort.",
                ThumbnailUrl = emoji.Image
            };

            embed.AddField("Name", emoji.Title);

            if (nameOverride != null)
            {
                embed.AddField("Name Override", nameOverride);
            }

            embed.AddField("Author", emoji.Author);

            SocketReaction reaction;

            try
            {
                var sent = await ReplyAsync(embed : embed.Build());

                ChoiceTracker.AddUser(Context.User.Id);

                var t = Task.Run(async() => await sent.AddReactionsAsync(new[] { reactionYes, reactionNo }));

                reaction = await ReactionCollector.GrabReaction(Context.User, sent,
                                                                x => x.Emote.Equals(reactionYes) || x.Emote.Equals(reactionNo), 20);
            }
            finally
            {
                ChoiceTracker.RemoveUser(Context.User.Id);
            }


            if (reaction == null)
            {
                await ReplyAsync("No reaction was given, aborting.");

                return;
            }

            if (reaction.Emote.Equals(reactionYes))
            {
                var successMessage = await ReplyAsync("Hold on while I add your emoji...");

                try
                {
                    using (Stream image = await DiscordEmoji.GetImageAsync(emoji))
                    {
                        // Check for Discord's 256kb emoji size cap
                        if (image.Length / 1024 > 256)
                        {
                            await ReplyAsync("The selected emoji is above 256kb and cannot be uploaded to Discord. Go bother Kohai (DiscordEmoji developer) to fix it.");

                            return;
                        }

                        await Context.Guild.CreateEmoteAsync(nameOverride ?? emoji.Title, new Image(image), options : new RequestOptions
                        {
                            AuditLogReason = $"Emoji added by {Context.User.Username}#{Context.User.Discriminator}",
                            RetryMode      = RetryMode.AlwaysFail // Will fail on too long of a ratelimit so the bot doesn't hang on emoji upload ratelimit
                        });
                    }

                    var addMessage = $"Cool beans, you've added {emoji.Title} to your server.";

                    if (nameOverride != null)
                    {
                        addMessage += $" Name override: {nameOverride}";
                    }

                    await successMessage.ModifyAsync(x => x.Content = addMessage);
                }
                catch (Exception ex)
                {
                    if (ex is RateLimitedException)
                    {
                        await ReplyAsync("Discord has a ratelimit on adding emoji, and you've just hit it. Try adding your emoji at a later time.");

                        return;
                    }
                    else if (ex is HttpException hex)
                    {
                        string message;

                        switch (hex.HttpCode)
                        {
                        case (HttpStatusCode)400:
                            message = $"The emoji failed to submit to Discord, it may have been too big. {hex.Reason ?? ""}";
                            break;

                        default:
                            message = "Unexpected status code received from Discord, something went wrong. Report it, I guess?";
                            break;
                        }

                        await ReplyAsync(message);

                        return;
                    }
                }
            }
            else
            {
                await ReplyAsync("Alright then, I won't be adding that emoji.");
            }
        }
Exemple #5
0
        public async Task RemoveEmoji(string name)
        {
            var serverEmoji = Context.Guild.Emotes;

            var toRemove = serverEmoji.FirstOrDefault(x => x.Name == name);

            if (toRemove == null)
            {
                await ReplyAsync("No emoji was found by that name on this server.");

                return;
            }

            EmbedBuilder embed = new EmbedBuilder
            {
                Title        = "Confirmation",
                Description  = "Are you sure that you want to remove this emoji?\nReact with ✅ in less than 20 seconds to confirm. React with ❌ to abort.",
                ThumbnailUrl = toRemove.Url
            };

            embed.AddField("Name", toRemove.Name);

            SocketReaction reaction;

            try
            {
                var sent = await ReplyAsync(embed : embed.Build());

                ChoiceTracker.AddUser(Context.User.Id);

                var t = Task.Run(async() => await sent.AddReactionsAsync(new[] { reactionYes, reactionNo }));

                reaction = await ReactionCollector.GrabReaction(Context.User, sent,
                                                                x => x.Emote.Equals(reactionYes) || x.Emote.Equals(reactionNo), 20);
            }
            finally
            {
                ChoiceTracker.RemoveUser(Context.User.Id);
            }

            if (reaction == null)
            {
                await ReplyAsync("No reaction was given, aborting.");

                return;
            }

            if (reaction.Emote.Equals(reactionYes))
            {
                try
                {
                    await Context.Guild.DeleteEmoteAsync(toRemove);
                }
                catch (HttpException)
                {
                    await ReplyAsync("I failed to remove the mentioned emoji, maybe somebody else removed it first?");

                    return;
                }

                await ReplyAsync("Emoji successfully removed.");
            }
            else
            {
                await ReplyAsync("Alright, I won't remove that emoji.");
            }
        }
 public void Track(int choice)
 {
     ChoiceTracker.Track(key, choice);
 }
Exemple #7
0
    public void StartConversationByChoice(string key)
    {
        int choiceNumber = ChoiceTracker.GetChoiceNumber(key);

        LoadConversation(choiceNumber);
    }