Exemple #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 rank", DiscordEmojiService.GetAddEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var data = await DialogHandler.RunForm <CreateGuildSpecialRankData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            var rank = new GuildSpecialRankConfigurationEntity
                            {
                                GuildId = dbFactory.GetRepository <GuildRepository>()
                                          .GetQuery()
                                          .Where(obj => obj.DiscordServerId == CommandContext.Guild.Id)
                                          .Select(obj => obj.Id)
                                          .First(),
                                Description     = data.Description,
                                DiscordRoleId   = data.DiscordRoleId,
                                MaximumPoints   = data.MaximumPoints,
                                GrantThreshold  = data.GrantThreshold,
                                RemoveThreshold = data.RemoveThreshold
                            };

                            if (dbFactory.GetRepository <GuildSpecialRankConfigurationRepository>()
                                .Add(rank))
                            {
                                DialogContext.SetValue("RankId", rank.Id);

                                bool repeat;

                                do
                                {
                                    repeat = await RunSubElement <GuildSpecialRankEditDialogElement, 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 <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("RankId", levelId);

                        bool repeat;

                        do
                        {
                            repeat = await RunSubElement <GuildSpecialRankEditDialogElement, 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 <GuildSpecialRankSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("RankId", rankId);

                        return(await RunSubElement <GuildSpecialRankDeletionDialogElement, 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);
    }
Exemple #2
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 schedule", DiscordEmojiService.GetAddEmoji(CommandContext.Client)),
                    Func        = async() =>
                    {
                        var data = await DialogHandler.RunForm <CreateCalendarScheduleData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            var level = new CalendarAppointmentScheduleEntity
                            {
                                DiscordServerId = CommandContext.Guild.Id,
                                Description     = data.Description,
                                CalendarAppointmentTemplateId = data.TemplateId,
                                Type           = data.Schedule.Type,
                                AdditionalData = data.Schedule.AdditionalData
                            };

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

                        return(true);
                    }
                }
            };

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

                        DialogContext.SetValue("CalendarScheduleId", levelId);

                        bool repeat;

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

                        return(true);
                    }
                });

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

                        DialogContext.SetValue("CalendarScheduleId", levelId);

                        return(await RunSubElement <CalendarScheduleDeletionDialogElement, 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);
    }
Exemple #3
0
    /// <summary>
    /// Converting the response message
    /// </summary>
    /// <param name="message">Message</param>
    /// <returns>Result</returns>
    public override string ConvertMessage(DiscordMessage message)
    {
        DialogContext.SetValue("ApiKey", message.Content);

        return(base.ConvertMessage(message));
    }
Exemple #4
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 <CreateRaidTemplateFormData>(CommandContext, false)
                                   .ConfigureAwait(false);

                        using (var dbFactory = RepositoryFactory.CreateInstance())
                        {
                            dbFactory.GetRepository <RaidDayTemplateRepository>()
                            .Add(new RaidDayTemplateEntity
                            {
                                AliasName   = data.AliasName,
                                Title       = data.Title,
                                Description = data.Description,
                                Thumbnail   = data.Thumbnail
                            });
                        }

                        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 templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("TemplateId", templateId);

                        bool repeat;

                        do
                        {
                            repeat = await RunSubElement <RaidTemplateEditDialogElement, 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 templateId = await RunSubElement <RaidTemplateSelectionDialogElement, long>().ConfigureAwait(false);

                        DialogContext.SetValue("TemplateId", templateId);

                        return(await RunSubElement <RaidTemplateDeletionElementBase, 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);
    }
Exemple #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 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);
    }
Exemple #6
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);
    }
Exemple #7
0
    /// <summary>
    /// Returning task with the result
    /// </summary>
    /// <param name="dayOfWeek">Day of week</param>
    /// <returns>Task Day of week</returns>
    private Task <DayOfWeek> GetReturnValue(DayOfWeek dayOfWeek)
    {
        DialogContext.SetValue("DayOfWeek", dayOfWeek);

        return(Task.FromResult(dayOfWeek));
    }