public virtual async Task AddUserCommand(CommandContext ctx, [RemainingText][Description("Your username")]
                                             string username)
    {
        this.Logger.LogInformation("Trying to add {ProviderUsername} {Member} to {Name} update provider", username, ctx.Member, UserService.Name);
        BaseUser user;

        try
        {
            user = await this.UserService.AddUserAsync(username, ctx.Member.Id, ctx.Member.Guild.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is UserProcessingException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed.Build()).ConfigureAwait(false);

            this.Logger.LogError(ex, "Failed to add {ProviderUsername} {Member} to {Name} update provider", username, ctx.Member, UserService.Name);
            throw;
        }

        this.Logger.LogInformation("Successfully added {ProviderUsername} {Member} to {Name} update provider", username, ctx.Member, UserService.Name);

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx,
                                                                  $"Successfully added {user.Username} to {this.UserService.Name} update checker")).ConfigureAwait(false);
    }
示例#2
0
    public async Task ForceCheckCommand(CommandContext context, [RemainingText, Description("Update provider name")]
                                        string name)
    {
        name = name.Trim();
        BaseUpdateProvider?baseUpdateProvider;

        if (this._providersConfigurationService.Providers.TryGetValue(name, out var provider) && provider is BaseUpdateProvider bup)
        {
            baseUpdateProvider = bup;
        }
        else
        {
            var upc = this._providersConfigurationService.Providers.Values.FirstOrDefault(p => p.Name.Where(char.IsUpper).ToString() == name);
            baseUpdateProvider = upc as BaseUpdateProvider;
        }

        if (baseUpdateProvider != null)
        {
            baseUpdateProvider.RestartTimer(TimeSpan.Zero);
            await context.RespondAsync(embed : EmbedTemplate.SuccessEmbed(context, "Success")).ConfigureAwait(false);
        }
        else
        {
            await context.RespondAsync(embed : EmbedTemplate.ErrorEmbed(context, "Haven't found such update provider")).ConfigureAwait(false);
        }
    }
    public virtual async Task ListUsersCommand(CommandContext ctx)
    {
        var sb = new StringBuilder();

        try
        {
            var i = 1;
            await foreach (var user in this.UserService.ListUsersAsync(ctx.Guild.Id))
            {
                if (sb.Length + user.Username.Length > 2048)
                {
                    if (sb.Length + "...".Length > 2048)
                    {
                        break;
                    }

                    sb.Append("...");
                    break;
                }

                sb.AppendLine(
                    $"{i++.ToString()}{user.Username} {(user.DiscordUser == null ? "" : Helpers.ToDiscordMention(user.DiscordUser.DiscordUserId))}");
            }
        }
        catch (Exception ex)
        {
            var embed = ex is UserProcessingException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            throw;
        }

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx, "Users").WithDescription(sb.ToString())).ConfigureAwait(false);
    }
    public virtual async Task DisableFeatureCommand(CommandContext context, params T[] features)
    {
        if (!features.Any())
        {
            return;
        }
        this.Logger.LogInformation("Trying to disable {Features} feature for {Username}", features, context.Member.DisplayName);
        try
        {
            await this.UserFeaturesService.DisableFeaturesAsync(features, context.User.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is UserFeaturesException ufe
                                ? EmbedTemplate.ErrorEmbed(context, ufe.Message, $"Failed disabling {features.Humanize().ToLowerInvariant()}")
                                : EmbedTemplate.UnknownErrorEmbed(context);

            await context.RespondAsync(embed : embed.Build()).ConfigureAwait(false);

            this.Logger.LogError(ex, "Failed to disable {Features} for {Username}", features, context.Member.DisplayName);
            throw;
        }

        this.Logger.LogInformation("Successfully disabled {Features} feature for {Username}", features, context.Member.DisplayName);
        await context.RespondAsync(embed : EmbedTemplate.SuccessEmbed(context,
                                                                      $"Successfully disabled {features.Humanize()} for you")).ConfigureAwait(false);
    }
示例#5
0
    public async Task UpdateChannelCommand(CommandContext ctx, [Description("New channel where updates should be posted")]
                                           DiscordChannel?channel = null)
    {
        if (channel == null)
        {
            channel = ctx.Channel;
        }
        try
        {
            var perms = channel.PermissionsFor(ctx.Guild.CurrentMember);
            if (!perms.HasPermission(Permissions.SendMessages))
            {
                throw new GuildManagementException(
                          $"Bot wouldn't be able to send updates to channel {channel} because it lacks permission to send messages");
            }
            await this._managementService.UpdateChannelAsync(channel.GuildId !.Value, channel.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is GuildManagementException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            throw;
        }

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx, $"Successfully updated to {channel}")).ConfigureAwait(false);
    }
    public virtual async Task RemoveUserHereCommand(CommandContext ctx)
    {
        try
        {
            await this.UserService.RemoveUserHereAsync(ctx.User.Id, ctx.Guild.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is UserProcessingException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            throw;
        }

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx, $"Now your updates won't appear in this server")).ConfigureAwait(false);
    }
示例#7
0
    public async Task RemoveGuildCommand(CommandContext ctx)
    {
        try
        {
            await this._managementService.RemoveGuildAsync(ctx.Guild.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is GuildManagementException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            throw;
        }

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx, "Successfully removed this server from being tracked"))
        .ConfigureAwait(false);
    }
示例#8
0
    public async Task ForceRemoveUserCommand(CommandContext ctx, [Description("Discord user's id which should be to removed from being tracked")]
                                             ulong userId)
    {
        try
        {
            await this._managementService.RemoveUserAsync(ctx.Guild.Id, userId).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is GuildManagementException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            throw;
        }

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx, $"Successfully removed {userId.ToString()} this server from being tracked"))
        .ConfigureAwait(false);
    }
    public virtual async Task RemoveUserInGuildCommand(CommandContext ctx)
    {
        this.Logger.LogInformation("Trying to remove {Member} from {Name} update provider", ctx.Member, UserService.Name);
        BaseUser user;

        try
        {
            user = await this.UserService.RemoveUserAsync(ctx.User.Id).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            var embed = ex is UserProcessingException?EmbedTemplate.ErrorEmbed(ctx, ex.Message) : EmbedTemplate.UnknownErrorEmbed(ctx);

            await ctx.RespondAsync(embed : embed).ConfigureAwait(false);

            this.Logger.LogError(ex, "Failed to remove {Member} from {Name} update provider", ctx.Member, UserService.Name);

            throw;
        }
        this.Logger.LogInformation("Successfully removed {Member} from {Name} update provider", ctx.Member, UserService.Name);

        await ctx.RespondAsync(embed : EmbedTemplate.SuccessEmbed(ctx,
                                                                  $"Successfully removed {user.Username} from {this.UserService.Name} update checker")).ConfigureAwait(false);
    }