Beispiel #1
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        if (_reactions == null)
        {
            _reactions = new List <ReactionData <bool> >
            {
                new ()
                {
                    Emoji       = DiscordEmojiService.GetAddEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add level", DiscordEmojiService.GetAddEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var data = await DialogHandler.RunForm <CreateRaidExperienceLevelData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            var level = new RaidExperienceLevelEntity
                            {
                                SuperiorExperienceLevelId = data.SuperiorExperienceLevelId,
                                Description   = data.Description,
                                DiscordEmoji  = data.DiscordEmoji,
                                DiscordRoleId = data.DiscordRoleId,
                            };

                            if (dbFactory.GetRepository <RaidExperienceLevelRepository>()
                                .Add(level))
                            {
                                if (dbFactory.GetRepository <RaidExperienceLevelRepository>()
                                    .RefreshRange(obj => obj.SuperiorExperienceLevelId == data.SuperiorExperienceLevelId &&
                                                  obj.Id != level.Id,
                                                  obj => obj.SuperiorExperienceLevelId = level.Id))
                                {
                                    dbFactory.GetRepository <RaidExperienceLevelRepository>()
                                    .RefreshRanks();
                                }
                            }
                        }

                        return(true);
                    }
                }
            };

            if (GetLevels().Count > 0)
            {
                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit level", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var levelId = await RunSubElement <RaidExperienceLevelSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("ExperienceLevelId", levelId);

                        bool repeat;

                        do
                        {
                            repeat = await RunSubElement <RaidExperienceLevelEditDialogElement, bool>().ConfigureAwait(false);
                        }while (repeat);

                        return(true);
                    }
                });

                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete level", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var levelId = await RunSubElement <RaidExperienceLevelSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("ExperienceLevelId", levelId);

                        return(await RunSubElement <RaidExperienceLevelDeletionDialogElement, bool>().ConfigureAwait(false));
                    }
                });
            }

            _reactions.Add(new ReactionData <bool>
            {
                Emoji       = DiscordEmojiService.GetCrossEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)),
                Func        = () => Task.FromResult(false)
            });
        }

        return(_reactions);
    }
Beispiel #2
0
    /// <summary>
    /// Starting the roles assistant
    /// </summary>
    /// <param name="commandContextContainer">Current command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task RunAssistantAsync(CommandContextContainer commandContextContainer)
    {
        var builder = new DiscordEmbedBuilder();

        builder.WithTitle(LocalizationGroup.GetText("AssistantTitle", "Raid role configuration"));
        builder.WithDescription(LocalizationGroup.GetText("AssistantDescription", "With this assistant you are able to configure the raid roles. The following roles are already created:"));

        var areRolesAvailable = false;

        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var mainRoles = dbFactory.GetRepository <RaidRoleRepository>()
                            .GetQuery()
                            .Where(obj => obj.MainRoleId == null &&
                                   obj.IsDeleted == false)
                            .Select(obj => new
            {
                obj.DiscordEmojiId,
                obj.Description,
                SubRoles = obj.SubRaidRoles
                           .Where(obj2 => obj2.IsDeleted == false)
                           .Select(obj2 => new
                {
                    obj2.DiscordEmojiId,
                    obj2.Description
                })
            })
                            .OrderBy(obj => obj.Description)
                            .ToList();

            if (mainRoles.Count > 0)
            {
                areRolesAvailable = true;

                foreach (var role in mainRoles)
                {
                    var roles = new StringBuilder(1024, 1024);

                    foreach (var subRole in role.SubRoles)
                    {
                        roles.Append("> ");
                        roles.Append(DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, subRole.DiscordEmojiId));
                        roles.Append(' ');
                        roles.Append(subRole.Description);
                        roles.Append('\n');
                    }

                    roles.Append('\n');

                    builder.AddField($"{DiscordEmojiService.GetGuildEmoji(commandContextContainer.Client, role.DiscordEmojiId)} {role.Description}", roles.ToString());
                }
            }
        }

        var addEmoji    = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client);
        var editEmoji   = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client);
        var deleteEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client);
        var cancelEmoji = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client);

        var commands = new StringBuilder();

        commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantAddCommand", "{0} Add role", addEmoji));

        if (areRolesAvailable)
        {
            commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantEditCommand", "{0} Edit role", editEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantDeleteCommand", "{0} Delete role", deleteEmoji));
        }

        commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji));

        builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString());

        var message = await commandContextContainer.Channel
                      .SendMessageAsync(builder)
                      .ConfigureAwait(false);

        var userReactionTask = commandContextContainer.Client
                               .GetInteractivity()
                               .WaitForReactionAsync(message, commandContextContainer.User);

        await message.CreateReactionAsync(addEmoji).ConfigureAwait(false);

        await message.CreateReactionAsync(editEmoji).ConfigureAwait(false);

        if (areRolesAvailable)
        {
            await message.CreateReactionAsync(deleteEmoji).ConfigureAwait(false);

            await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false);
        }

        var userReaction = await userReactionTask.ConfigureAwait(false);

        if (userReaction.TimedOut == false)
        {
            if (userReaction.Result.Emoji.Id == addEmoji.Id)
            {
                await RunAddAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
            else if (userReaction.Result.Emoji.Id == editEmoji.Id && areRolesAvailable)
            {
                await RunEditAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
            else if (userReaction.Result.Emoji.Id == deleteEmoji.Id)
            {
                await RunDeleteAssistantAsync(commandContextContainer).ConfigureAwait(false);
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        if (_reactions == null)
        {
            _reactions = new List <ReactionData <bool> >
            {
                new ()
                {
                    Emoji       = DiscordEmojiService.GetAddEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add rank", DiscordEmojiService.GetAddEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var data = await DialogHandler.RunForm <CreateGuildRankFormData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            var rank = new GuildRankEntity
                            {
                                GuildId = dbFactory.GetRepository <GuildRepository>()
                                          .GetQuery()
                                          .Where(obj => obj.DiscordServerId == CommandContext.Guild.Id)
                                          .Select(obj => obj.Id)
                                          .First(),
                                DiscordRoleId = data.DiscordRoleId,
                                InGameName    = data.InGameName,
                                Percentage    = data.Percentage,
                                Order         = data.SuperiorId != null
                                                                           ? dbFactory.GetRepository <GuildRankRepository>()
                                                .GetQuery()
                                                .Where(obj => obj.Id == data.SuperiorId)
                                                .Select(obj => obj.Order)
                                                .First() + 1
                                                                           : 0,
                            };

                            if (dbFactory.GetRepository <GuildRankRepository>()
                                .Add(rank))
                            {
                                var order = rank.Order + 1;

                                foreach (var currentRankId in dbFactory.GetRepository <GuildRankRepository>()
                                         .GetQuery()
                                         .Where(obj => obj.Order >= rank.Order)
                                         .OrderBy(obj => obj.Order)
                                         .Select(obj => obj.Id))
                                {
                                    dbFactory.GetRepository <GuildRankRepository>()
                                    .Refresh(obj => obj.Id == currentRankId,
                                             obj => obj.Order = order);
                                    order++;
                                }

                                DialogContext.SetValue("RankId", rank.Id);

                                bool repeat;

                                do
                                {
                                    repeat = await RunSubElement <GuildRankEditDialogElement, bool>().ConfigureAwait(false);
                                }while (repeat);
                            }
                        }

                        return(true);
                    }
                }
            };

            if (GetRanks().Count > 0)
            {
                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit rank", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var levelId = await RunSubElement <GuildRankSelectionDialogElement, int>().ConfigureAwait(false);

                        DialogContext.SetValue("RankId", levelId);

                        bool repeat;

                        do
                        {
                            repeat = await RunSubElement <GuildRankEditDialogElement, bool>().ConfigureAwait(false);
                        }while (repeat);

                        return(true);
                    }
                });

                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete rank", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var rankId = await RunSubElement <GuildRankSelectionDialogElement, int>().ConfigureAwait(false);

                        DialogContext.SetValue("RankId", rankId);

                        return(await RunSubElement <GuildRankDeletionDialogElement, bool>().ConfigureAwait(false));
                    }
                });
            }

            _reactions.Add(new ReactionData <bool>
            {
                Emoji       = DiscordEmojiService.GetCrossEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)),
                Func        = () => Task.FromResult(false)
            });
        }

        return(_reactions);
    }
Beispiel #4
0
    /// <summary>
    /// Starting the role editing assistant
    /// </summary>
    /// <param name="commandContextContainer">Current command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    private async Task RunEditAssistantAsync(CommandContextContainer commandContextContainer)
    {
        var roleId = await SelectRoleAsync(commandContextContainer, null).ConfigureAwait(false);

        if (roleId != null)
        {
            var builder = new DiscordEmbedBuilder();
            builder.WithTitle(LocalizationGroup.GetText("RoleEditTitle", "Raid role configuration"));

            var areRolesAvailable = false;

            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                var rolesFieldText = new StringBuilder();
                var roles          = dbFactory.GetRepository <RaidRoleRepository>()
                                     .GetQuery()
                                     .Where(obj => obj.Id == roleId.Value &&
                                            obj.IsDeleted == false)
                                     .Select(obj => new
                {
                    obj.DiscordEmojiId,
                    obj.Description,
                    SubRoles = obj.SubRaidRoles
                               .Where(obj2 => obj2.IsDeleted == false)
                               .Select(obj2 => new
                    {
                        obj2.DiscordEmojiId,
                        obj2.Description
                    })
                })
                                     .OrderBy(obj => obj.Description)
                                     .First();

                builder.WithDescription($"{DiscordEmoji.FromGuildEmote(commandContextContainer.Client, roles.DiscordEmojiId)} - {roles.Description}");

                if (roles.SubRoles.Any())
                {
                    areRolesAvailable = true;

                    foreach (var role in roles.SubRoles)
                    {
                        rolesFieldText.Append(DiscordEmoji.FromGuildEmote(commandContextContainer.Client, role.DiscordEmojiId));
                        rolesFieldText.Append(" - ");
                        rolesFieldText.Append(role.Description);
                        rolesFieldText.Append('\n');
                    }

                    builder.AddField(LocalizationGroup.GetText("AssistantRolesField", "Roles"), rolesFieldText.ToString());
                }
            }

            var addSubRoleEmoji    = DiscordEmojiService.GetAddEmoji(commandContextContainer.Client);
            var descriptionEmoji   = DiscordEmojiService.GetEditEmoji(commandContextContainer.Client);
            var editSubRoleEmoji   = DiscordEmojiService.GetEdit2Emoji(commandContextContainer.Client);
            var emojiEmoji         = DiscordEmojiService.GetEmojiEmoji(commandContextContainer.Client);
            var deleteSubRoleEmoji = DiscordEmojiService.GetTrashCanEmoji(commandContextContainer.Client);
            var cancelEmoji        = DiscordEmojiService.GetCrossEmoji(commandContextContainer.Client);

            var commands = new StringBuilder();
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditDescriptionCommand", "{0} Edit description", descriptionEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditEmojiCommand", "{0} Edit emoji", emojiEmoji));
            commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditAddSubRoleCommand", "{0} Add sub role", addSubRoleEmoji));

            if (areRolesAvailable)
            {
                commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditEditSubRoleCommand", "{0} Edit sub role", editSubRoleEmoji));
                commands.AppendLine(LocalizationGroup.GetFormattedText("RoleEditDeleteSubRoleCommand", "{0} Delete sub role", deleteSubRoleEmoji));
            }

            commands.AppendLine(LocalizationGroup.GetFormattedText("AssistantCancelCommand", "{0} Cancel", cancelEmoji));

            builder.AddField(LocalizationGroup.GetText("AssistantCommandsField", "Commands"), commands.ToString());

            var message = await commandContextContainer.Channel
                          .SendMessageAsync(builder)
                          .ConfigureAwait(false);

            var userReactionTask = commandContextContainer.Client
                                   .GetInteractivity()
                                   .WaitForReactionAsync(message, commandContextContainer.User);

            await message.CreateReactionAsync(descriptionEmoji).ConfigureAwait(false);

            await message.CreateReactionAsync(emojiEmoji).ConfigureAwait(false);

            await message.CreateReactionAsync(addSubRoleEmoji).ConfigureAwait(false);

            if (areRolesAvailable)
            {
                await message.CreateReactionAsync(editSubRoleEmoji).ConfigureAwait(false);

                await message.CreateReactionAsync(deleteSubRoleEmoji).ConfigureAwait(false);
            }

            await message.CreateReactionAsync(cancelEmoji).ConfigureAwait(false);

            var userReaction = await userReactionTask.ConfigureAwait(false);

            if (userReaction.TimedOut == false)
            {
                if (userReaction.Result.Emoji.Id == addSubRoleEmoji.Id)
                {
                    await RunAddSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == descriptionEmoji.Id)
                {
                    await RunEditDescriptionAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == editSubRoleEmoji.Id)
                {
                    await RunEditSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == emojiEmoji.Id)
                {
                    await RunEditEmojiAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
                else if (userReaction.Result.Emoji.Id == deleteSubRoleEmoji.Id)
                {
                    await RunDeleteSubRoleAssistantAsync(commandContextContainer, roleId.Value).ConfigureAwait(false);
                }
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// Returns the reactions which should be added to the message
    /// </summary>
    /// <returns>Reactions</returns>
    public override IReadOnlyList <ReactionData <bool> > GetReactions()
    {
        if (_reactions == null)
        {
            _reactions = new List <ReactionData <bool> >
            {
                new ()
                {
                    Emoji       = DiscordEmojiService.GetAddEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("AddCommand", "{0} Add template", DiscordEmojiService.GetAddEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var data = await DialogHandler.RunForm <CreateCalendarTemplateData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            var level = new CalendarAppointmentTemplateEntity
                            {
                                DiscordServerId        = CommandContext.Guild.Id,
                                Description            = data.Description,
                                AppointmentTime        = data.AppointmentTime,
                                Uri                    = data.Uri,
                                ReminderMessage        = data.Reminder?.Message,
                                ReminderTime           = data.Reminder?.Time,
                                GuildPoints            = data.GuildPoints?.Points,
                                IsRaisingGuildPointCap = data.GuildPoints?.IsRaisingPointCap
                            };

                            dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                            .Add(level);
                        }

                        return(true);
                    }
                }
            };

            if (GetTemplates().Count > 0)
            {
                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetEditEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("EditCommand", "{0} Edit template", DiscordEmojiService.GetEditEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var levelId = await RunSubElement <CalendarTemplateSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("CalendarTemplateId", levelId);

                        bool repeat;

                        do
                        {
                            repeat = await RunSubElement <CalendarTemplateEditDialogElement, bool>().ConfigureAwait(false);
                        }while (repeat);

                        return(true);
                    }
                });

                _reactions.Add(new ReactionData <bool>
                {
                    Emoji       = DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client),
                    CommandText = LocalizationGroup.GetFormattedText("DeleteCommand", "{0} Delete template", DiscordEmojiService.GetTrashCanEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var levelId = await RunSubElement <CalendarTemplateSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("CalendarTemplateId", levelId);

                        return(await RunSubElement <CalendarTemplateDeletionDialogElement, bool>().ConfigureAwait(false));
                    }
                });
            }

            _reactions.Add(new ReactionData <bool>
            {
                Emoji       = DiscordEmojiService.GetCrossEmoji(CommandContext.Client),
                CommandText = LocalizationGroup.GetFormattedText("CancelCommand", "{0} Cancel", DiscordEmojiService.GetCrossEmoji(CommandContext.Client)),
                Func        = () => Task.FromResult(false)
            });
        }

        return(_reactions);
    }
    public Task Info(CommandContext commandContext)
    {
        return(InvokeAsync(commandContext,
                           async commandContextContainer =>
        {
            var build = new DiscordEmbedBuilder()
                        .WithColor(DiscordColor.Green)
                        .WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64")
                        .WithTimestamp(DateTime.Now)
                        .WithTitle(LocalizationGroup.GetText("GeneralInformationTitle", "General information"))
                        .WithDescription(LocalizationGroup.GetFormattedText("GeneralInformationDescription", "All data collected by {0} is used only for the administration of the guild. The individual areas where data is collected are discussed below.", commandContextContainer.Client.CurrentUser.Mention))
                        .AddField(LocalizationGroup.GetText("GuildWars2ApiTitle", "Guild Wars 2 - API-Token"), LocalizationGroup.GetFormattedText("GuildWars2ApiDescription", "The following data is determined via the specified API token:\n\n - With how many characters is the guild represented?\n - When was the last login?\n - Which server is the account assigned to?\n\nAll other data is only determined temporarily when you request {0} to execute a command. You only ever have access to your own API token.", commandContextContainer.Client.CurrentUser.Mention))
                        .AddField(LocalizationGroup.GetText("DiscordTitle", "Discord"), LocalizationGroup.GetFormattedText("DiscordDescription", "Part of the guild ranking system is the activity in Discord. For this, how many messages are written and how many minutes you are in the voice chat are saved. The content of the posts is irrelevant and is not saved.", commandContextContainer.Client.CurrentUser.Mention))
                        .AddField(LocalizationGroup.GetText("RefreshTitle", "State"), LocalizationGroup.GetFormattedText("RefreshDescription", "As of: {0}", new DateTime(2021, 10, 17).ToString("d", LocalizationGroup.CultureInfo)));

            await commandContextContainer.Channel
            .SendMessageAsync(build)
            .ConfigureAwait(false);
        }));
    }
Beispiel #7
0
    /// <summary>
    /// Refreshing all calendars
    /// </summary>
    /// <param name="serverId">Id of the server</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task RefreshMotds(ulong?serverId)
    {
        using (var dbFactory = RepositoryFactory.CreateInstance())
        {
            var now = DateTime.Now;

            var templates = dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                            .GetQuery()
                            .Select(obj => obj);

            var channels = dbFactory.GetRepository <GuildChannelConfigurationRepository>()
                           .GetQuery()
                           .Select(obj => obj);

            foreach (var calendar in dbFactory.GetRepository <GuildRepository>()
                     .GetQuery()
                     .Where(obj => serverId == null || obj.DiscordServerId == serverId)
                     .Select(obj => new
            {
                Channel = channels.Where(obj2 => obj2.GuildId == obj.Id &&
                                         obj2.Type == GuildChannelConfigurationType.CalendarMessageOfTheDay)
                          .Select(obj2 => new
                {
                    ChannelId = obj2.DiscordChannelId,
                    MessageId = obj2.DiscordMessageId
                })
                          .FirstOrDefault(),
                Appointments = templates.Where(obj2 => obj2.DiscordServerId == obj.DiscordServerId)
                               .SelectMany(obj2 => obj2.CalendarAppointments
                                           .Where(obj3 => obj3.TimeStamp > now &&
                                                  obj2.CalendarAppointments.Any(obj4 => obj4.TimeStamp > now &&
                                                                                obj4.TimeStamp < obj3.TimeStamp) == false)
                                           .Select(obj3 => new
                {
                    obj3.TimeStamp,
                    obj2.Description
                }))
                               .OrderBy(obj2 => obj2.TimeStamp)
                               .ToList()
            })
                     .Where(obj => obj.Channel.ChannelId > 0)
                     .ToList())
            {
                var messageBuilder = new StringBuilder();

                messageBuilder.AppendLine("--------------------");

                foreach (var appointment in calendar.Appointments)
                {
                    var currentLine = LocalizationGroup.GetFormattedText("MotdFormat",
                                                                         "{0} - {1}, {2:dd.MM.} at {2:HH:mm}",
                                                                         appointment.Description,
                                                                         LocalizationGroup.CultureInfo.DateTimeFormat.GetDayName(appointment.TimeStamp.DayOfWeek),
                                                                         appointment.TimeStamp);

                    if (messageBuilder.Length + currentLine.Length > 900)
                    {
                        break;
                    }

                    messageBuilder.AppendLine(currentLine);
                }

                messageBuilder.Append("--------------------");

                var channel = await _discordClient.GetChannelAsync(calendar.Channel.ChannelId)
                              .ConfigureAwait(false);

                if (channel != null)
                {
                    await channel.SendMessageAsync(new DiscordEmbedBuilder().WithTitle(LocalizationGroup.GetText("Motd", "Message of the day:"))
                                                   .WithDescription(Formatter.BlockCode(messageBuilder.ToString()))
                                                   .WithColor(DiscordColor.Green)
                                                   .WithFooter("Scruffy", "https://cdn.discordapp.com/app-icons/838381119585648650/823930922cbe1e5a9fa8552ed4b2a392.png?size=64")
                                                   .WithTimestamp(DateTime.Now)
                                                   .Build())
                    .ConfigureAwait(false);
                }
            }
        }
    }
Beispiel #8
0
 /// <summary>
 /// Return the message of element
 /// </summary>
 /// <returns>Message</returns>
 public override string GetMessage() => LocalizationGroup.GetFormattedText("Message", "Please enter on which {0} of the month the appointment should be created or zero if it should be created every week.", LocalizationGroup.CultureInfo.DateTimeFormat.GetDayName(DialogContext.GetValue <DayOfWeek>("DayOfWeek")));