예제 #1
0
    /// <summary>
    /// Adding a one time event
    /// </summary>
    /// <param name="commandContext">Command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task AddOneTimeEvent(CommandContextContainer commandContext)
    {
        var data = await DialogHandler.RunForm <CreateOneTimeEventFormData>(commandContext, false)
                   .ConfigureAwait(false);

        if (data != null)
        {
            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                var appointmentTime = dbFactory.GetRepository <CalendarAppointmentTemplateRepository>()
                                      .GetQuery()
                                      .Where(obj => obj.Id == data.TemplateId)
                                      .Select(obj => obj.AppointmentTime)
                                      .First();

                if (dbFactory.GetRepository <CalendarAppointmentRepository>()
                    .Add(new CalendarAppointmentEntity
                {
                    CalendarAppointmentScheduleId = null,
                    CalendarAppointmentTemplateId = data.TemplateId,
                    TimeStamp = data.Day.Add(appointmentTime)
                }))
                {
                    await _messageBuilder.RefreshMessages(commandContext.Guild.Id)
                    .ConfigureAwait(false);
                }
            }
        }
    }
예제 #2
0
    /// <summary>
    /// Setting up the calendar
    /// </summary>
    /// <param name="commandContext">Command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task SetupCalendar(CommandContextContainer commandContext)
    {
        var data = await DialogHandler.RunForm <SetGuildCalendarFormData>(commandContext, true)
                   .ConfigureAwait(false);

        if (data != null)
        {
            var message = await commandContext.Channel
                          .SendMessageAsync(LocalizationGroup.GetText("CalendarBuilding", "The calendar will be build with the next refresh."))
                          .ConfigureAwait(false);

            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                var guildId = dbFactory.GetRepository <GuildRepository>()
                              .GetQuery()
                              .Where(obj => obj.DiscordServerId == commandContext.Guild.Id)
                              .Select(obj => obj.Id)
                              .FirstOrDefault();

                if (guildId > 0)
                {
                    if (dbFactory.GetRepository <GuildChannelConfigurationRepository>()
                        .AddOrRefresh(obj => obj.GuildId == guildId &&
                                      obj.Type == GuildChannelConfigurationType.CalendarOverview,
                                      obj =>
                    {
                        obj.DiscordChannelId = commandContext.Channel.Id;
                        obj.DiscordMessageId = message.Id;
                        obj.AdditionalData = JsonConvert.SerializeObject(new AdditionalCalendarChannelData
                        {
                            Title = data.Title,
                            Description = data.Description
                        });
                    }))
                    {
                        await _calendarScheduleService.CreateAppointments(commandContext.Guild.Id)
                        .ConfigureAwait(false);

                        await _calendarMessageBuilderService.RefreshMessages(commandContext.Guild.Id)
                        .ConfigureAwait(false);

                        await _calendarMessageBuilderService.RefreshMotds(commandContext.Guild.Id)
                        .ConfigureAwait(false);
                    }
                }
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Create a new guild configuration
    /// </summary>
    /// <param name="commandContext">Command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task CreateGuildConfiguration(CommandContextContainer commandContext)
    {
        var data = await DialogHandler.RunForm <CreateGuildFormData>(commandContext, true)
                   .ConfigureAwait(false);

        if (data != null)
        {
            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                dbFactory.GetRepository <GuildRepository>()
                .AddOrRefresh(obj => obj.DiscordServerId == commandContext.Guild.Id,
                              obj =>
                {
                    obj.ApiKey          = data.ApiKey;
                    obj.GuildId         = data.GuildId;
                    obj.DiscordServerId = commandContext.Guild.Id;
                });
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Setup assistant
    /// </summary>
    /// <param name="commandContext">Command context</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public async Task RunSetupAssistant(CommandContextContainer commandContext)
    {
        var dialogHandler = new DialogHandler(commandContext);

        await using (dialogHandler.ConfigureAwait(false))
        {
            var creationData = await dialogHandler.RunForm <FractalLfgCreationFormData>()
                               .ConfigureAwait(false);

            var entry = new FractalLfgConfigurationEntity
            {
                Title            = creationData.Title,
                Description      = creationData.Description,
                AliasName        = creationData.AliasName,
                DiscordChannelId = commandContext.Channel.Id,
                DiscordMessageId = (await commandContext.Channel.SendMessageAsync(LocalizationGroup.GetText("BuildingProgress", "Building...")).ConfigureAwait(false)).Id
            };

            using (var dbFactory = RepositoryFactory.CreateInstance())
            {
                dbFactory.GetRepository <FractalLfgConfigurationRepository>()
                .Add(entry);
            }

            await _messageBuilder.RefreshMessageAsync(entry.Id).ConfigureAwait(false);

            var currentBotMessage = await commandContext.Channel
                                    .SendMessageAsync(LocalizationGroup.GetText("CreationCompletedMessage", "Creation completed! All creation messages will be deleted in 30 seconds.")).ConfigureAwait(false);

            dialogHandler.DialogContext.Messages.Add(currentBotMessage);

            await Task.Delay(TimeSpan.FromSeconds(30)).ConfigureAwait(false);

            await dialogHandler.DeleteMessages()
            .ConfigureAwait(false);
        }
    }
예제 #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 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);
    }
예제 #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 <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);
    }
예제 #7
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);
    }
예제 #8
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);
    }
예제 #9
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);
    }