Exemplo n.º 1
0
        public static async Task HandlerAdd(DiscordSocketClient client, DbService db, Cacheable <IUserMessage, ulong> cachedMessage, SocketReaction reaction)
        {
            var userId = reaction.UserId;

            if (client.CurrentUser.Id == userId || reaction.Emote.Name != "📳")
            {
                return;
            }

            var eventId = await AnnounceUtil.GetEventId(cachedMessage);

            if (eventId == null)
            {
                return;
            }
            if (await db.AddEventReaction(eventId.Value, userId))
            {
                var user = client.GetUser(userId);
                await user.SendMessageAsync($"You have signed up for notifications for run {eventId}!");

                Log.Information("User {User} has signed up for notifications for event {EventId}.", user.ToString(), eventId);
            }
            else if (await db.RemoveEventReaction(eventId.Value, userId))
            {
                var user = client.GetUser(userId);
                await user.SendMessageAsync($"You have been removed from the notifications list for event {eventId}.");

                Log.Information("User {User} has been removed from notifications for event {EventId}.", user.ToString(), eventId);
            }

            var message = await cachedMessage.GetOrDownloadAsync();

            try
            {
                await message.RemoveReactionAsync(new Emoji("📳"), userId);
            }
            catch { /* ignored */ }
        }
Exemplo n.º 2
0
        public static async Task HandlerAdd(DiscordSocketClient client, FFXIV3RoleQueueService queueService, DbService db, Cacheable <IUserMessage, ulong> cachedMessage, SocketReaction reaction)
        {
            var userId = reaction.UserId;

            if (client.CurrentUser.Id == userId || !RoleReactions.ContainsKey(reaction.Emote.Name))
            {
                return;
            }

            var role = RoleReactions[reaction.Emote.Name];

            var eventId = await AnnounceUtil.GetEventId(cachedMessage);

            if (eventId == null)
            {
                return;
            }

            var guildConfig = db.Guilds.FirstOrDefault(g => g.Id == SpecialGuilds.CrystalExploratoryMissions);

            if (guildConfig == null)
            {
                Log.Error("No guild configuration found for the default guild!");
                return;
            }

            var user  = client.GetUser(userId);
            var guild = client.GetGuild(SpecialGuilds.CrystalExploratoryMissions);

            var message = await cachedMessage.GetOrDownloadAsync();

            var inputChannel = guild.GetTextChannel(GetScheduleInputChannel(guildConfig, message.Channel.Id));
            var eventMessage = await inputChannel.GetMessageAsync(eventId.Value);

            var host         = guild.GetUser(eventMessage.Author.Id);
            var discordRoles = DelubrumProgressionRoles.Roles.Keys
                               .Select(rId => guild.GetRole(rId));
            var authorHasProgressionRole = discordRoles.Any(dr => host.HasRole(dr));
            var freshProg = !authorHasProgressionRole || eventMessage.Content.ToLowerInvariant().Contains("810201516291653643");

#if DEBUG
            Log.Information("Fresh prog: {FreshProg}", freshProg);
#endif

            var scheduleQueue = GetScheduleQueue(guildConfig, freshProg, reaction.Channel.Id);
            if (scheduleQueue == 0)
            {
                return;
            }

            var queueName = QueueInfo.LfgChannels[scheduleQueue];
            var queue     = queueService.GetOrCreateQueue(queueName);

            if (queue.Enqueue(userId, role, eventId.Value.ToString()))
            {
                await user.SendMessageAsync($"You have been added to the {role} queue for event `{eventId}`. " +
                                            "You can check your position in queue with `~queue` in the queue channel.\n" +
                                            "Clicking the reaction again will refresh your position in the queue.");

                Log.Information("User {User} has been added to the {FFXIVRole} queue for {QueueName}, with event {Event}", user.ToString(), role.ToString(), queueName, eventId);
            }
            else
            {
                queueService.GetOrCreateQueue("lfg-castrum").Refresh(userId);
                queueService.GetOrCreateQueue("lfg-delubrum-normal").Refresh(userId);
                queueService.GetOrCreateQueue("lfg-drs-fresh-prog").Refresh(userId);
                queueService.GetOrCreateQueue("lfg-delubrum-savage").Refresh(userId);

                await user.SendMessageAsync($"{user.Mention}, your timeouts in the Bozja queues have been refreshed!");
            }

            queueService.Save();

            try
            {
                await message.RemoveReactionAsync(reaction.Emote, userId);
            }
            catch { /* ignored */ }
        }
Exemplo n.º 3
0
        public static async Task HandlerAdd(DiscordSocketClient client, FFXIV3RoleQueueService queueService, IDbService db, Cacheable <IUserMessage, ulong> cachedMessage, SocketReaction reaction)
        {
            var userId = reaction.UserId;

            if (client.CurrentUser.Id == userId || !RoleReactions.ContainsKey(reaction.Emote.Name))
            {
                return;
            }

            var role = RoleReactions[reaction.Emote.Name];

            var eventId = await AnnounceUtil.GetEventId(cachedMessage);

            if (eventId == null)
            {
                return;
            }

            var guildConfig = db.Guilds.FirstOrDefault(g => g.Id == SpecialGuilds.CrystalExploratoryMissions);

            if (guildConfig == null)
            {
                Log.Error("No guild configuration found for the default guild!");
                return;
            }

            var user  = client.GetUser(userId);
            var guild = client.GetGuild(SpecialGuilds.CrystalExploratoryMissions);

            var message = await cachedMessage.GetOrDownloadAsync();

            var noQueueChannels = new[]
            {
                guildConfig.BozjaClusterScheduleOutputChannel,
                guildConfig.SocialScheduleOutputChannel,
                guildConfig.DelubrumNormalScheduleOutputChannel,
                guildConfig.DelubrumScheduleOutputChannel,

                guildConfig.CastrumScheduleOutputChannel,
                guildConfig.ScheduleOutputChannel, // BA
            };

            if (noQueueChannels.Contains(message.Channel.Id))
            {
                return;
            }

            var inputChannel = guild.GetTextChannel(GetScheduleInputChannel(guildConfig, message.Channel.Id));

            if (inputChannel == null)
            {
                return;
            }
            var eventMessage = await inputChannel.GetMessageAsync(eventId.Value);

            var host         = guild.GetUser(eventMessage.Author.Id);
            var discordRoles = DelubrumProgressionRoles.Roles.Keys
                               .Select(rId => guild.GetRole(rId));
            var authorHasProgressionRole = discordRoles.Any(dr => host.HasRole(dr));
            var freshProg = !authorHasProgressionRole || eventMessage.Content.ToLowerInvariant().Contains("810201516291653643");

#if DEBUG
            Log.Information("Fresh prog: {FreshProg}", freshProg);
#endif

            var scheduleQueue = GetScheduleQueue(guildConfig, freshProg, reaction.Channel.Id);
            if (scheduleQueue == 0)
            {
                return;
            }

            var queueName = QueueInfo.LfgChannels[scheduleQueue];
            var queue     = queueService.GetOrCreateQueue(queueName);

            if (queue.Enqueue(userId, role, eventId.Value.ToString()))
            {
                var embed     = message.Embeds.FirstOrDefault(e => e.Type == EmbedType.Rich);
                var eventTime = embed?.Timestamp;
                if (eventTime != null && eventTime.Value.AddHours(-2) <= DateTimeOffset.Now)
                {
                    queue.ConfirmEvent(userId, eventId.Value.ToString());
#if DEBUG
                    Log.Information("Auto-confirmed.");
#endif
                }
#if DEBUG
                else
                {
                    if (eventTime != null)
                    {
                        Log.Information((eventTime.Value - DateTimeOffset.Now).ToString());
                    }

                    Log.Information("Not auto-confirmed.");
                }
#endif

                await user.SendMessageAsync($"You have been added to the {role} queue for event `{eventId}`. " +
                                            "You can check your position in queue with `~queue` in the queue channel.");

                Log.Information("User {User} has been added to the {FFXIVRole} queue for {QueueName}, with event {Event}", user.ToString(), role.ToString(), queueName, eventId);
            }
            else
            {
                await user.SendMessageAsync("You are already in that queue, in position " +
                                            $"{queue.GetPosition(userId, role, eventId.Value.ToString())}/{queue.Count(role, eventId.Value.ToString())}.\n" +
                                            $"If you would like to leave the queue, please use `~leavequeue {eventId}` in the queue channel.");
            }

            queueService.Save();

            try
            {
                await message.RemoveReactionAsync(reaction.Emote, userId);
            }
            catch { /* ignored */ }
        }