private async Task SettlementReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var settlementHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(SettlementResources.SettlementHelper) ?? false);

            if (settlementHelperEmbed != null)
            {
                var region = StarforgedUtilites.SpaceRegionFromEmote(reaction.Emote.Name);
                if (region == SpaceRegion.None)
                {
                    return;
                }

                string command  = settlementHelperEmbed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.SettlementName).Value ?? string.Empty;
                string location = ExtractAnySettlementLocation(ref command);

                var newSettlement = Settlement.GenerateSettlement(Services, region, channel.Id, command, location);
                Task.WaitAll(message.RemoveAllReactionsAsync());

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

                await Task.Run(async() =>
                {
                    await message.AddReactionAsync(projectEmoji);
                    await message.AddReactionAsync(contactEmoji);
                    await message.AddReactionAsync(troubleEmoji);
                }).ConfigureAwait(false);

                return;
            }
        }
Ejemplo n.º 2
0
        private async Task ShipReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var starshipHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(StarShipResources.StarshipHelperTitle) ?? false);

            if (starshipHelperEmbed != null)
            {
                var region = StarforgedUtilites.SpaceRegionFromEmote(reaction.Emote.Name);
                if (region == SpaceRegion.None)
                {
                    return;
                }

                string name = starshipHelperEmbed.Fields.FirstOrDefault(fld => fld.Name == StarShipResources.StarshipName).Value ?? string.Empty;

                Starship newShip = Starship.GenerateShip(Services, region, name);
                Task.WaitAll(message.RemoveAllReactionsAsync());

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

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

                return;
            }

            var shipEmbed = message.Embeds.FirstOrDefault(embed => embed?.Description?.Contains(StarShipResources.Starship, StringComparison.OrdinalIgnoreCase) ?? false);

            if (shipEmbed == null)
            {
                return;
            }

            Starship ship = Starship.FromEmbed(Services, shipEmbed);

            if (reaction.Emote.Name == missionEmoji.Name)
            {
                ship.MissionRevealed = true;
                await message.RemoveReactionAsync(reaction.Emote, message.Author).ConfigureAwait(false);
            }

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

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

            return;
        }
Ejemplo n.º 3
0
        private async Task SettlementReactionHandler(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user)
        {
            var settlementHelperEmbed = message.Embeds.FirstOrDefault(embed => embed?.Title?.Contains(SettlementResources.SettlementHelper) ?? false);

            if (settlementHelperEmbed != null)
            {
                var region = StarforgedUtilites.SpaceRegionFromEmote(reaction.Emote.Name);
                if (region == SpaceRegion.None)
                {
                    return;
                }

                string name = settlementHelperEmbed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.SettlementName).Value ?? string.Empty;

                var newSettlement = Settlement.GenerateSettlement(Services, region, name);
                Task.WaitAll(message.RemoveAllReactionsAsync());

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

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

                return;
            }

            var settlmentEmbed = message.Embeds.FirstOrDefault(embed => embed?.Description?.Contains(SettlementResources.Settlement) ?? false);

            if (settlmentEmbed == null)
            {
                return;
            }

            var settlement = new Settlement(Services).FromEmbed(settlmentEmbed);

            if (reaction.Emote.Name == projectEmoji.Name)
            {
                settlement.ProjectsRevealed++;
            }

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

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

            return;
        }