public async Task ScheduleGuildEvent(
            CommandContext context,
            [Description("The channel to announce the event in")]
            DiscordChannel announcementChannel,
            [Description("The role to announce the event to")]
            DiscordRole role,
            [Description("The date to schedule the event for")]
            [RemainingText]
            string datetimeString
            )
        {
            using IBotAccessProvider provider = this.accessBuilder.Build();

            if (!context.User.TryGetDateTimeZone(provider, this.timeZoneProvider, out DateTimeZone schedulerTimeZone))
            {
                await context.RespondAsync(StringConstants.NoTimeZoneErrorMessage);

                return;
            }

            DiscordMember botMember = await context.Guild.GetMemberAsync(context.Client.CurrentUser.Id);

            if (!announcementChannel.PermissionsFor(botMember).HasPermission(Permissions.SendMessages | Permissions.MentionEveryone))
            {
                await context.RespondAsync($"{context.Member.Mention}, I don't have permission to send messages and mention `@everyone` in that channel.");

                return;
            }

            LocalDateTime datetime = Recognizers.RecognizeDateTime(datetimeString, DateTimeV2Type.DateTime)
                                     .First().Values.Select(value => (LocalDateTime)value.Value).OrderBy(key => key).First();
            DiscordMessage msg = await context.RespondAsync($":wave: Hi, {context.User.Mention}! You want to schedule an event for {datetime:g} in your timezone?");

            InteractivityExtension interactivity = context.Client.GetInteractivity();
            Reaction reaction = await interactivity.AddAndWaitForYesNoReaction(msg, context.User);

            if (reaction != Reaction.Yes)
            {
                return;
            }

            DiscordEmbedBuilder scheduleEmbedBase = new DiscordEmbedBuilder()
                                                    .WithTitle("Select an event by typing: <event number>")
                                                    .WithColor(context.Member.Color);

            GuildEvent selectedEvent = await SelectPredefinedEvent(context, provider, msg, interactivity, scheduleEmbedBase);

            Instant      eventDateTime = datetime.InZoneStrictly(schedulerTimeZone).ToInstant();
            DiscordEmbed embed         = new DiscordEmbedBuilder()
                                         .WithAuthor(context.Member.DisplayName, iconUrl: context.Member.AvatarUrl)
                                         .WithDescription(selectedEvent.EventDesc)
                                         .WithTitle(selectedEvent.EventName)
                                         .Build();
            await msg.ModifyAsync($"You have scheduled the following event for {datetime:g} in your time zone to be output in the {announcementChannel.Mention} channel.", embed : embed);

            this.ScheduleEventsForRole(context, announcementChannel, provider, selectedEvent, eventDateTime, role);
        }
        public async Task RandomEventForRole(CommandContext context,
                                             [Description("Role to mention")]
                                             DiscordRole role)
        {
            DiscordMessage msg = await context.RespondAsync(
                $":wave: Hi, {context.User.Mention}! You want to `@everyone` and announce a random event?");

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_y:"));

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_n:"));

            InteractivityExtension interactivity = context.Client.GetInteractivity();

            InteractivityResult <MessageReactionAddEventArgs> interactivityResult =
                await interactivity.WaitForReactionAsync(msg, context.User);

            if (interactivityResult.TimedOut ||
                !interactivityResult.Result.Emoji.Equals(
                    DiscordEmoji.FromName(context.Client, ":regional_indicator_y:")))
            {
                DiscordMessage snark = await context.RespondAsync($"{context.User.Mention}, well then why did you get my attention! Thanks for wasting my time. Now I have to clean up your mess.");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark, context.Message
                });

                return;
            }

            await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                context.Message, msg
            });

            using IBotAccessProvider provider = this.accessBuilder.Build();
            List <GuildEvent>   guildEvents       = provider.GetAllAssociatedGuildEvents(context.Guild.Id).ToList();
            GuildEvent          selectedEvent     = guildEvents[Random.Next(guildEvents.Count)];
            DiscordEmbedBuilder eventEmbedBuilder = new DiscordEmbedBuilder();

            eventEmbedBuilder
            .WithTitle(selectedEvent.EventName)
            .WithDescription(selectedEvent.EventDesc);
            await context.RespondAsync(role.Mention, embed : eventEmbedBuilder.Build());
        }
        public static JsonPlayer BuildJsonPlayer(AbstractSingleActor player, ParsedEvtcLog log, RawFormatSettings settings, Dictionary <string, JsonLog.SkillDesc> skillDesc, Dictionary <string, JsonLog.BuffDesc> buffDesc, Dictionary <string, JsonLog.DamageModDesc> damageModDesc, Dictionary <string, HashSet <long> > personalBuffs)
        {
            var jsonPlayer = new JsonPlayer();

            JsonActorBuilder.FillJsonActor(jsonPlayer, player, log, settings, skillDesc, buffDesc);
            IReadOnlyList <PhaseData> phases = log.FightData.GetNonDummyPhases(log);

            //
            jsonPlayer.Account     = player.Account;
            jsonPlayer.Weapons     = player.GetWeaponSets(log).ToArray();
            jsonPlayer.Group       = player.Group;
            jsonPlayer.Profession  = player.Spec.ToString();
            jsonPlayer.FriendlyNPC = player is NPC;
            jsonPlayer.NotInSquad  = player is PlayerNonSquad;
            GuildEvent guildEvent = log.CombatData.GetGuildEvents(player.AgentItem).FirstOrDefault();

            if (guildEvent != null)
            {
                jsonPlayer.GuildID = guildEvent.APIString;
            }
            jsonPlayer.ActiveTimes     = phases.Select(x => player.GetActiveDuration(log, x.Start, x.End)).ToList();
            jsonPlayer.HasCommanderTag = player is Player p && p.IsCommander(log);
            //
            jsonPlayer.Support = phases.Select(phase => JsonStatisticsBuilder.BuildJsonPlayerSupport(player.GetToPlayerSupportStats(log, phase.Start, phase.End))).ToArray();
            var targetDamage1S          = new IReadOnlyList <int> [log.FightData.Logic.Targets.Count][];
            var targetPowerDamage1S     = new IReadOnlyList <int> [log.FightData.Logic.Targets.Count][];
            var targetConditionDamage1S = new IReadOnlyList <int> [log.FightData.Logic.Targets.Count][];
            var targetBreakbarDamage1S  = new IReadOnlyList <double> [log.FightData.Logic.Targets.Count][];
            var dpsTargets       = new JsonStatistics.JsonDPS[log.FightData.Logic.Targets.Count][];
            var statsTargets     = new JsonStatistics.JsonGameplayStats[log.FightData.Logic.Targets.Count][];
            var targetDamageDist = new IReadOnlyList <JsonDamageDist> [log.FightData.Logic.Targets.Count][];

            for (int j = 0; j < log.FightData.Logic.Targets.Count; j++)
            {
                AbstractSingleActor target     = log.FightData.Logic.Targets[j];
                var graph1SDamageList          = new IReadOnlyList <int> [phases.Count];
                var graph1SPowerDamageList     = new IReadOnlyList <int> [phases.Count];
                var graph1SConditionDamageList = new IReadOnlyList <int> [phases.Count];
                var graph1SBreakbarDamageList  = new IReadOnlyList <double> [phases.Count];
                var targetDamageDistList       = new IReadOnlyList <JsonDamageDist> [phases.Count];
                for (int i = 0; i < phases.Count; i++)
                {
                    PhaseData phase = phases[i];
                    if (settings.RawFormatTimelineArrays)
                    {
                        graph1SDamageList[i]          = player.Get1SDamageList(log, phase.Start, phase.End, target, DamageType.All);
                        graph1SPowerDamageList[i]     = player.Get1SDamageList(log, phase.Start, phase.End, target, DamageType.Power);
                        graph1SConditionDamageList[i] = player.Get1SDamageList(log, phase.Start, phase.End, target, DamageType.Condition);
                        graph1SBreakbarDamageList[i]  = player.Get1SBreakbarDamageList(log, phase.Start, phase.End, target);
                    }
                    targetDamageDistList[i] = JsonDamageDistBuilder.BuildJsonDamageDistList(
                        player.GetJustActorDamageEvents(target, log, phase.Start, phase.End).GroupBy(x => x.SkillId).ToDictionary(x => x.Key, x => x.ToList()),
                        player.GetJustActorBreakbarDamageEvents(target, log, phase.Start, phase.End).GroupBy(x => x.SkillId).ToDictionary(x => x.Key, x => x.ToList()),
                        log,
                        skillDesc,
                        buffDesc
                        );
                }
                if (settings.RawFormatTimelineArrays)
                {
                    targetDamage1S[j]          = graph1SDamageList;
                    targetPowerDamage1S[j]     = graph1SPowerDamageList;
                    targetConditionDamage1S[j] = graph1SConditionDamageList;
                    targetBreakbarDamage1S[j]  = graph1SBreakbarDamageList;
                }
                targetDamageDist[j] = targetDamageDistList;
                dpsTargets[j]       = phases.Select(phase => JsonStatisticsBuilder.BuildJsonDPS(player.GetDPSStats(target, log, phase.Start, phase.End))).ToArray();
                statsTargets[j]     = phases.Select(phase => JsonStatisticsBuilder.BuildJsonGameplayStats(player.GetOffensiveStats(target, log, phase.Start, phase.End))).ToArray();
            }
            if (settings.RawFormatTimelineArrays)
            {
                jsonPlayer.TargetDamage1S          = targetDamage1S;
                jsonPlayer.TargetPowerDamage1S     = targetPowerDamage1S;
                jsonPlayer.TargetConditionDamage1S = targetConditionDamage1S;
                jsonPlayer.TargetBreakbarDamage1S  = targetBreakbarDamage1S;
                Dictionary <long, BuffsGraphModel> buffGraphs = player.GetBuffGraphs(log);
                if (buffGraphs.TryGetValue(SkillIDs.NumberOfClones, out BuffsGraphModel states))
                {
                    jsonPlayer.ActiveClones = JsonBuffsUptimeBuilder.GetBuffStates(states);
                }
            }
            jsonPlayer.TargetDamageDist = targetDamageDist;
            jsonPlayer.DpsTargets       = dpsTargets;
            jsonPlayer.StatsTargets     = statsTargets;
            if (!log.CombatData.HasBreakbarDamageData)
            {
                jsonPlayer.TargetBreakbarDamage1S = null;
            }
            //
            jsonPlayer.BuffUptimes   = GetPlayerJsonBuffsUptime(player, phases.Select(phase => player.GetBuffs(BuffEnum.Self, log, phase.Start, phase.End)).ToList(), log, settings, buffDesc, personalBuffs);
            jsonPlayer.SelfBuffs     = GetPlayerBuffGenerations(phases.Select(phase => player.GetBuffs(BuffEnum.Self, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.GroupBuffs    = GetPlayerBuffGenerations(phases.Select(phase => player.GetBuffs(BuffEnum.Group, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.OffGroupBuffs = GetPlayerBuffGenerations(phases.Select(phase => player.GetBuffs(BuffEnum.OffGroup, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.SquadBuffs    = GetPlayerBuffGenerations(phases.Select(phase => player.GetBuffs(BuffEnum.Squad, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            //
            jsonPlayer.BuffUptimesActive   = GetPlayerJsonBuffsUptime(player, phases.Select(phase => player.GetActiveBuffs(BuffEnum.Self, log, phase.Start, phase.End)).ToList(), log, settings, buffDesc, personalBuffs);
            jsonPlayer.SelfBuffsActive     = GetPlayerBuffGenerations(phases.Select(phase => player.GetActiveBuffs(BuffEnum.Self, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.GroupBuffsActive    = GetPlayerBuffGenerations(phases.Select(phase => player.GetActiveBuffs(BuffEnum.Group, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.OffGroupBuffsActive = GetPlayerBuffGenerations(phases.Select(phase => player.GetActiveBuffs(BuffEnum.OffGroup, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            jsonPlayer.SquadBuffsActive    = GetPlayerBuffGenerations(phases.Select(phase => player.GetActiveBuffs(BuffEnum.Squad, log, phase.Start, phase.End)).ToList(), log, buffDesc);
            //
            IReadOnlyList <Consumable> consumables = player.GetConsumablesList(log, 0, log.FightData.FightEnd);

            if (consumables.Any())
            {
                var consumablesJSON = new List <JsonConsumable>();
                foreach (Consumable food in consumables)
                {
                    if (!buffDesc.ContainsKey("b" + food.Buff.ID))
                    {
                        buffDesc["b" + food.Buff.ID] = JsonLogBuilder.BuildBuffDesc(food.Buff, log);
                    }
                    consumablesJSON.Add(JsonConsumableBuilder.BuildJsonConsumable(food));
                }
                jsonPlayer.Consumables = consumablesJSON;
            }
            //
            IReadOnlyList <DeathRecap> deathRecaps = player.GetDeathRecaps(log);

            if (deathRecaps.Any())
            {
                jsonPlayer.DeathRecap = deathRecaps.Select(x => JsonDeathRecapBuilder.BuildJsonDeathRecap(x)).ToList();
            }
            //
            jsonPlayer.DamageModifiers       = JsonDamageModifierDataBuilder.GetDamageModifiers(phases.Select(x => player.GetDamageModifierStats(null, log, x.Start, x.End)).ToList(), log, damageModDesc);
            jsonPlayer.DamageModifiersTarget = JsonDamageModifierDataBuilder.GetDamageModifiersTarget(player, log, damageModDesc, phases);
            if (log.CombatData.HasEXTHealing)
            {
                jsonPlayer.EXTHealingStats = EXTJsonPlayerHealingStatsBuilder.BuildPlayerHealingStats(player, log, settings, skillDesc, buffDesc);
            }
            if (log.CombatData.HasEXTBarrier)
            {
                jsonPlayer.EXTBarrierStats = EXTJsonPlayerBarrierStatsBuilder.BuildPlayerBarrierStats(player, log, settings, skillDesc, buffDesc);
            }
            return(jsonPlayer);
        }
Ejemplo n.º 4
0
        public void NotifyGuildStatus(WcHandlerCharacter.CharacterObject objCharacter, GuildEvent status)
        {
            if (objCharacter.Guild is null)
            {
                return;
            }
            var statuspacket = new PacketClass(Opcodes.SMSG_GUILD_EVENT);

            statuspacket.AddInt8((byte)status);
            statuspacket.AddInt8(1);
            statuspacket.AddString(objCharacter.Name);
            statuspacket.AddInt8(0);
            statuspacket.AddInt8(0);
            statuspacket.AddInt8(0);
            BroadcastToGuild(statuspacket, objCharacter.Guild, objCharacter.Guid);
            statuspacket.Dispose();
        }
Ejemplo n.º 5
0
 public Delete(GuildEvent e)
 {
     this.Event = e;
 }
        public async Task RemoveGuildEvent(CommandContext context)
        {
            using IBotAccessProvider provider = this.accessBuilder.Build();
            DiscordMessage msg = await context.RespondAsync(
                $":wave: Hi, {context.User.Mention}! You want to remove an event from your guild list?");

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_y:"));

            await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_n:"));

            InteractivityExtension interactivity = context.Client.GetInteractivity();

            InteractivityResult <MessageReactionAddEventArgs> interactivityResult =
                await interactivity.WaitForReactionAsync(msg, context.User);

            if (interactivityResult.TimedOut ||
                !interactivityResult.Result.Emoji.Equals(
                    DiscordEmoji.FromName(context.Client, ":regional_indicator_y:")))
            {
                DiscordMessage snark = await context.RespondAsync("Well, thanks for wasting my time. Have a good day.");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark, context.Message
                });

                return;
            }

            DiscordEmbedBuilder removeEventEmbed = new DiscordEmbedBuilder()
                                                   .WithTitle("Select an event to remove by typing: <event number>")
                                                   .WithColor(context.Member.Color);

            Task <(bool, int)> messageValidationAndReturn(MessageCreateEventArgs messageE)
            {
                if (messageE.Author.Equals(context.User) && int.TryParse(messageE.Message.Content, out int eventToChoose))
                {
                    return(Task.FromResult((true, eventToChoose)));
                }
                else
                {
                    return(Task.FromResult((false, -1)));
                }
            }

            List <GuildEvent> guildEvents = provider.GetAllAssociatedGuildEvents(context.Guild.Id).ToList();

            await msg.DeleteAllReactionsAsync();

            CustomResult <int> result = await context.WaitForMessageAndPaginateOnMsg(
                GetGuildEventsPages(guildEvents, interactivity, removeEventEmbed),
                messageValidationAndReturn,
                msg : msg);

            if (result.TimedOut || result.Cancelled)
            {
                DiscordMessage snark = await context.RespondAsync("You never gave me a valid input. Thanks for wasting my time. :triumph:");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark
                });

                return;
            }

            GuildEvent selectedEvent = guildEvents[result.Result - 1];

            provider.DeleteGuildEvent(selectedEvent);
            await msg.ModifyAsync($"You have deleted the \"{selectedEvent.EventName}\" event from the guild", embed : null);
        }
        private void ScheduleEventsForRole(CommandContext context, DiscordChannel announcementChannel, IBotAccessProvider provider, GuildEvent selectedEvent, Instant eventDateTime, DiscordRole role)
        {
            Duration eventScheduleDuration = eventDateTime - this.clock.GetCurrentInstant();
            string   scheduledJobId        = BackgroundJob.Schedule <EventService>(
                eventService =>
                eventService.SendEmbedWithMessageToChannelAsUser(
                    context.Guild.Id,
                    context.Member.Id,
                    announcementChannel.Id,
                    $"{(role == null ? "@everyone" : role.Mention)}, this event is starting now!",
                    selectedEvent.EventName,
                    selectedEvent.EventDesc),
                eventScheduleDuration.ToTimeSpan());

            provider.AddGuildBackgroundJob(scheduledJobId, context.Guild.Id, $"{selectedEvent.EventName} - Announcement", eventDateTime, GuildJobType.SCHEDULED_EVENT);

            scheduledJobId = BackgroundJob.Schedule <EventService>(
                eventService
                => eventService.SendEmbedWithMessageToChannelAsUser(
                    context.Guild.Id,
                    context.Member.Id,
                    announcementChannel.Id,
                    $"{(role == null ? "@everyone" : role.Mention)}, this event is starting in 10 minutes!",
                    selectedEvent.EventName,
                    selectedEvent.EventDesc
                    ),
                (eventScheduleDuration - Duration.FromMinutes(10)).ToTimeSpan());

            provider.AddGuildBackgroundJob(scheduledJobId, context.Guild.Id, $"{selectedEvent.EventName} - 10 Min Announcement", eventDateTime - Duration.FromMinutes(10), GuildJobType.SCHEDULED_EVENT);
        }