Exemplo n.º 1
0
                public async Task ModifyConditionAsync
                (
                    AutoroleConfiguration autorole,
                    long conditionID,
                    IRole role
                )
                {
                    var getCondition = _autoroles.GetCondition <RoleCondition>
                                       (
                        autorole,
                        conditionID
                                       );

                    if (!getCondition.IsSuccess)
                    {
                        await _feedback.SendErrorAsync(this.Context, getCondition.ErrorReason);

                        return;
                    }

                    var condition = getCondition.Entity;

                    condition.RoleID = (long)role.Id;

                    await _autoroles.SaveChangesAsync();

                    await _feedback.SendConfirmationAsync(this.Context, "Condition updated.");
                }
                public async Task ModifyConditionAsync
                (
                    AutoroleConfiguration autorole,
                    long conditionID,
                    ITextChannel channel,
                    long count
                )
                {
                    var getCondition = _autoroles.GetCondition <MessageCountInChannelCondition>
                                       (
                        autorole,
                        conditionID
                                       );

                    if (!getCondition.IsSuccess)
                    {
                        await _feedback.SendErrorAsync(this.Context, getCondition.ErrorReason);

                        return;
                    }

                    var condition = getCondition.Entity;

                    condition.RequiredCount = count;
                    condition.SourceID      = (long)channel.Id;

                    await _autoroles.SaveChangesAsync();

                    await _feedback.SendConfirmationAsync(this.Context, "Condition updated.");
                }
Exemplo n.º 3
0
                public async Task ModifyConditionAsync
                (
                    AutoroleConfiguration autorole,
                    long conditionID,
                    TimeSpan time
                )
                {
                    var getCondition = _autoroles.GetCondition <TimeSinceJoinCondition>
                                       (
                        autorole,
                        conditionID
                                       );

                    if (!getCondition.IsSuccess)
                    {
                        await _feedback.SendErrorAsync(this.Context, getCondition.ErrorReason);

                        return;
                    }

                    var condition = getCondition.Entity;

                    condition.RequiredTime = time;

                    await _autoroles.SaveChangesAsync();

                    await _feedback.SendConfirmationAsync(this.Context, "Condition updated.");
                }
Exemplo n.º 4
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())
            {
            }
        }