示例#1
0
        private async Task HandleRaidSignupAsync(ReactionAddedEventArgs e)
        {
            if (!GetClassNames().Contains(e.Emoji.Name))
            {
                return;
            }
            if (e.User.Id == 668648526431125505 || e.User.Id == CurrentUser.Id)
            {
                return;
            }
#if DEBUG
            if (e.User.Id != 89613772372574208)
            {
                return;
            }
#else
            if (e.Channel.Id == 793661221861064715)
            {
                return;
            }
#endif
            var dbContext = this.GetRequiredService <AbfDbContext>();

            var msg = await e.Message.FetchAsync() as RestUserMessage;

            await using (dbContext)
            {
                var(check, raid, user, character) = await CheckForRaidAsync(e.Message.Id.RawValue, e.User.Id.RawValue, e.Emoji.Name, dbContext);

                if (!check)
                {
                    if (character is null)
                    {
                        var reactionUser = await e.User.FetchAsync();

                        await e.Channel.SendMessageAsync($"{reactionUser.Mention}, I didn't find a {e.Emoji.Name} character for you. Please add a character with the `!character add` command. Example: `!character add Gnomeorpuns Mage Ranged`. Do `!help character add` for full command information.");
                    }
                    await msg.RemoveMemberReactionAsync(e.User.Id, e.Emoji);

                    return;
                }

                if (raid.Participants.Any(p => p.CharacterId == character.Id))
                {
                    return;
                }

                var participant = new RaidParticipant {
                    Character = character, Raid = raid, SignedUpAt = DateTimeOffset.UtcNow
                };

                raid.Participants.Add(participant);
                dbContext.Update(raid);

                await dbContext.SaveChangesAsync();

                await WowRaidModule.CreateRaidEmbedAsync(msg, raid);
            }
        }
示例#2
0
        private async Task HandleRaidResignAsync(ReactionRemovedEventArgs e)
        {
            if (!GetClassNames().Contains(e.Emoji.Name))
            {
                return;
            }
#if DEBUG
            if (e.User.Id != 89613772372574208)
            {
                return;
            }
#else
            if (e.Channel.Id == 793661221861064715)
            {
                return;
            }
#endif
            var dbContext = this.GetRequiredService <AbfDbContext>();

            await using (dbContext)
            {
                var(check, raid, user, character) = await CheckForRaidAsync(e.Message.Id.RawValue, e.User.Id.RawValue, e.Emoji.Name, dbContext);

                if (!check)
                {
                    return;
                }

                var charToRemove = raid.Participants.FirstOrDefault(p => p.CharacterId == character.Id);

                if (charToRemove is null)
                {
                    return;
                }

                raid.Participants.Remove(charToRemove);
                dbContext.Update(raid);

                await dbContext.SaveChangesAsync();

                var msg = await e.Message.FetchAsync() as RestUserMessage;

                await WowRaidModule.CreateRaidEmbedAsync(msg, raid);
            }
        }
示例#3
0
        private async Task HandleRaidAbsentRemovedAsync(ReactionRemovedEventArgs e)
        {
            if (e.Emoji.ToString() != "👋")
            {
                return;
            }
#if DEBUG
            if (e.User.Id != 89613772372574208)
            {
                return;
            }
#else
            if (e.Channel.Id == 793661221861064715)
            {
                return;
            }
#endif
            var dbContext = this.GetRequiredService <AbfDbContext>();

            await using (dbContext)
            {
                var(_, raid, user, _) = await CheckForRaidAsync(e.Message.Id.RawValue, e.User.Id.RawValue, e.Emoji.Name, dbContext);

                if (raid is null || user is null)
                {
                    return;
                }

                var userParticipants = raid.Participants.Where(rp => rp.Character.Owner.Id == e.User.Id.RawValue);

                foreach (var participant in userParticipants)
                {
                    participant.IsAbsent = false;
                    dbContext.Update(participant);
                }
                await dbContext.SaveChangesAsync();

                var msg = await e.Message.FetchAsync() as RestUserMessage;

                await WowRaidModule.CreateRaidEmbedAsync(msg, raid);
            }
        }