public async Task <Result> ShowSettingsAsync()
        {
            var getSettings = await _autoroles.GetOrCreateServerSettingsAsync(_context.GuildID.Value);

            if (!getSettings.IsSuccess)
            {
                return(Result.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            var notificationChannelValue = settings.AffirmationRequiredNotificationChannelID.HasValue
                ? $"<#{settings.AffirmationRequiredNotificationChannelID.Value}"
                : "None";

            var embed = new Embed
            {
                Colour = _feedback.Theme.Secondary,
                Title  = "Autorole Settings",
                Fields = new[] { new EmbedField("Confirmation Notification Channel", notificationChannelValue) }
            };

            var send = await _feedback.SendContextualEmbedAsync(embed, ct : this.CancellationToken);

            return(send.IsSuccess
                ? Result.FromSuccess()
                : Result.FromError(send));
        }
            public async Task <RuntimeResult> ShowSettingsAsync()
            {
                var getSettings = await _autoroles.GetOrCreateServerSettingsAsync(this.Context.Guild);

                if (!getSettings.IsSuccess)
                {
                    return(getSettings.ToRuntimeResult());
                }

                var settings = getSettings.Entity;

                var notificationChannelValue = settings.AffirmationRequiredNotificationChannelID.HasValue
                    ? MentionUtils.MentionChannel((ulong)settings.AffirmationRequiredNotificationChannelID.Value)
                    : "None";

                var embed = _feedback.CreateEmbedBase()
                            .WithTitle("Autorole Settings")
                            .AddField("Confirmation Notification Channel", notificationChannelValue);

                await _feedback.SendEmbedAsync(this.Context.Channel, embed.Build());

                return(RuntimeCommandResult.FromSuccess());
            }
Ejemplo n.º 3
0
        private async Task NotifyUserNeedsAffirmation
        (
            AutoroleService autoroles,
            AutoroleConfiguration autorole,
            IGuildUser user
        )
        {
            var getAutoroleConfirmation = await autoroles.GetOrCreateAutoroleConfirmationAsync(autorole, user);

            if (!getAutoroleConfirmation.IsSuccess)
            {
                this.Log.LogError(getAutoroleConfirmation.Exception, getAutoroleConfirmation.ErrorReason);
                return;
            }

            var autoroleConfirmation = getAutoroleConfirmation.Entity;

            if (autoroleConfirmation.HasNotificationBeenSent)
            {
                return;
            }

            var getSettings = await autoroles.GetOrCreateServerSettingsAsync(user.Guild);

            if (!getSettings.IsSuccess)
            {
                this.Log.LogError(getSettings.Exception, getSettings.ErrorReason);
                return;
            }

            var settings = getSettings.Entity;

            var notificationChannelID = settings.AffirmationRequiredNotificationChannelID;

            if (notificationChannelID is null)
            {
                return;
            }

            var notificationChannel = await user.Guild.GetTextChannelAsync((ulong)notificationChannelID.Value);

            if (notificationChannel is null)
            {
                return;
            }

            var embed = _feedback.CreateEmbedBase()
                        .WithTitle("Confirmation Required")
                        .WithDescription
                        (
                $"{MentionUtils.MentionUser(user.Id)} has met the requirements for the " +
                $"{MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} role.\n" +
                $"\n" +
                $"Use \"!at affirm {MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} " +
                $"{MentionUtils.MentionUser(user.Id)}\" to affirm and give the user the role."
                        )
                        .WithColor(Color.Green);

            try
            {
                await _feedback.SendEmbedAsync(notificationChannel, embed.Build());

                autoroleConfirmation.HasNotificationBeenSent = true;
                await autoroles.SaveChangesAsync();
            }
            catch (HttpException hex) when(hex.WasCausedByMissingPermission())
            {
            }
        }
        private async Task <OperationResult> NotifyUserNeedsAffirmation
        (
            AutoroleService autoroles,
            SocketGuild guild,
            AutoroleConfiguration autorole,
            IUser user
        )
        {
            var getAutoroleConfirmation = await autoroles.GetOrCreateAutoroleConfirmationAsync(autorole, user);

            if (!getAutoroleConfirmation.IsSuccess)
            {
                return(OperationResult.FromError(getAutoroleConfirmation));
            }

            var autoroleConfirmation = getAutoroleConfirmation.Entity;

            if (autoroleConfirmation.HasNotificationBeenSent)
            {
                return(OperationResult.FromSuccess());
            }

            var getSettings = await autoroles.GetOrCreateServerSettingsAsync(guild);

            if (!getSettings.IsSuccess)
            {
                return(OperationResult.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            var notificationChannelID = settings.AffirmationRequiredNotificationChannelID;

            if (notificationChannelID is null)
            {
                return(OperationResult.FromError("There's no notification channel set."));
            }

            var notificationChannel = guild.GetTextChannel((ulong)notificationChannelID.Value);

            if (notificationChannel is null)
            {
                return(OperationResult.FromError("The notification channel is set, but does not exist."));
            }

            var embed = _feedback.CreateEmbedBase()
                        .WithTitle("Confirmation Required")
                        .WithDescription
                        (
                $"{MentionUtils.MentionUser(user.Id)} has met the requirements for the " +
                $"{MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} role.\n" +
                $"\n" +
                $"Use \"!at affirm {MentionUtils.MentionRole((ulong)autorole.DiscordRoleID)} " +
                $"{MentionUtils.MentionUser(user.Id)}\" to affirm and give the user the role."
                        )
                        .WithColor(Color.Green);

            try
            {
                await _feedback.SendEmbedAsync(notificationChannel, embed.Build());

                var setResult = await autoroles.SetHasNotificationBeenSentAsync(autoroleConfirmation, true);

                if (!setResult.IsSuccess)
                {
                    return(OperationResult.FromError(setResult));
                }
            }
            catch (HttpException hex) when(hex.WasCausedByMissingPermission())
            {
                return(OperationResult.FromError(hex));
            }

            return(OperationResult.FromSuccess());
        }