Esempio n. 1
0
        private async Task CreatureReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var CreatureHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureHelper) ?? false);

            if (CreatureHelperEmbed != null)
            {
                CreatureEnvironment environment = StarforgedUtilites.CreatureEnvironmentFromEmote(reaction.Emote.Name);
                if (reaction.Emote.IsSameAs(randomEmoji))
                {
                    string lookupValue = Services.GetRequiredService <OracleService>().RandomRow("Creature Environment").Description;
                    environment = StarforgedUtilites.GetAnyEnvironment(lookupValue);
                }
                if (environment == CreatureEnvironment.None)
                {
                    return;
                }

                var newCreature = Creature.GenerateNewCreature(Services, channel.Id, environment);
                Task.WaitAll(message.RemoveAllReactionsAsync());

                await message.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = newCreature.GetEmbedBuilder().Build();
                }).ConfigureAwait(false);

                await Task.Run(async() =>
                {
                    if (message.Reactions.Count > 0)
                    {
                        await Task.Delay(1500); //wait just in case we are still adding more reactions. Impatient users deserve to wait!!!
                        await message.RemoveAllReactionsAsync();
                    }

                    await message.AddReactionAsync(revealAspectEmoji).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return;
            }

            var creatureEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureTitle) ?? false);

            if (creatureEmbed == null)
            {
                return;
            }

            var creature = Creature.FromEmbed(creatureEmbed, Services, channel.Id);

            if (reaction.Emote.IsSameAs(revealAspectEmoji))
            {
                creature.AddRandomAspect();
            }

            await message.ModifyAsync(msg => msg.Embed = creature.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            return;
        }
Esempio n. 2
0
        private async Task CreatureReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var CreatureHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureHelper) ?? false);

            if (CreatureHelperEmbed != null)
            {
                CreatureEnvironment environment = StarforgedUtilites.CreatureEnvironmentFromEmote(reaction.Emote.Name);
                if (reaction.Emote.Name == randomEmoji.Name)
                {
                    string lookupValue = Services.GetRequiredService <OracleService>().RandomRow("Creature Environment").Description;
                    environment = StarforgedUtilites.GetAnyEnvironment(lookupValue);
                }
                if (environment == CreatureEnvironment.None)
                {
                    return;
                }

                var newCreature = Creature.GenerateCreature(Services, channel.Id, environment);
                Task.WaitAll(message.RemoveAllReactionsAsync());

                await message.ModifyAsync(msg =>
                {
                    msg.Content = string.Empty;
                    msg.Embed   = newCreature.GetEmbedBuilder().Build();
                }).ConfigureAwait(false);

                await message.AddReactionAsync(revealAspectEmoji).ConfigureAwait(false);

                return;
            }

            var creatureEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(CreatureResources.CreatureTitle) ?? false);

            if (creatureEmbed == null)
            {
                return;
            }

            var creature = Creature.FromEmbed(creatureEmbed, Services, channel.Id);

            if (reaction.Emote.Name == revealAspectEmoji.Name)
            {
                creature.RevealedAspectsToShow++;
            }

            await message.ModifyAsync(msg => msg.Embed = creature.GetEmbedBuilder().Build()).ConfigureAwait(false);

            await message.RemoveReactionAsync(reaction.Emote, user).ConfigureAwait(false);

            return;
        }