Exemplo n.º 1
0
        public async Task UnbanCommandAsync(CommandContext ctx,
                                            [Description("User to unban. Can be an ID")]
                                            DiscordUser user,

                                            [Description("Reason for unban.")]
                                            [RemainingText]
                                            string reason = "unspecified")
        {
            try
            {
                await user.UnbanAsync(ctx.Guild, reason);
            }
            catch
            {
                await RespondBasicErrorAsync($"Failed to unban {user.Id}");

                return;
            }

            var cfg = this._model.Find <GuildModeration>(ctx.Guild.Id);

            if (!(cfg is null))
            {
                // Remove a temp ban if it exsists.
                if (cfg.UserBans.TryRemove(user.Id, out _))
                {
                    this._model.Update(cfg);
                    await this._model.SaveChangesAsync();
                }
            }

            await RespondBasicSuccessAsync($"Unbanned {user.Id}");
        }
Exemplo n.º 2
0
        public async Task UnBan(CommandContext ctx, DiscordUser user, [RemainingText] string reason = "No reason given.")
        {
            if (!ctx.Member.HasPermission(Permissions.BanMembers))
            {
                await ctx.RespondAsync("[You] Can't ban, can't unban. Sorry.").ConfigureAwait(false);

                return;
            }

            if ((await ctx.Guild.GetBansAsync()).Select(b => b.User.Id).Contains(user.Id))
            {
                await user.UnbanAsync(ctx.Guild, reason);

                DiscordEmbedBuilder embed =
                    new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, "",
                                                                    $"Unbanned {user.Username}#{user.Discriminator} `({user.Id})`! ")).AddField("Reason:", reason);
                var infraction =
                    (TimedInfraction)_eventService.Events.FirstOrDefault(e => ((TimedInfraction)e).Id == user.Id);
                if (infraction is not null)
                {
                    _eventService.Events.TryRemove(infraction);
                }

                await ctx.RespondAsync(embed : embed);
            }
            else
            {
                DiscordEmbedBuilder embed =
                    new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, "", $"{user.Mention} is not banned!"))
                    .WithColor(new DiscordColor("#d11515"));

                await ctx.RespondAsync(embed : embed);
            }
        }
Exemplo n.º 3
0
        public async Task Unban(CommandContext ctx, DiscordUser user)
        {
            if (ctx.Member.PermissionsIn(ctx.Channel) == DSharpPlus.Permissions.All)
            {
                await ctx.Channel.SendMessageAsync(embed : Vembed("Successfully unbanned " + user.Username));

                await user.UnbanAsync(ctx.Guild).ConfigureAwait(false);
            }
            else
            {
                await ctx.Channel.SendMessageAsync("You do not have sufficient permissions to perform this command.");
            }
        }
Exemplo n.º 4
0
        public async Task UnbanAsync(ulong guildId, ulong userId)
        {
            try
            {
                DiscordClient shardClient = this.bot.ShardedClient.GetShard(guildId);
                DiscordUser   discordUser = await shardClient.GetUserAsync(userId);

                DiscordGuild discordGuild = await shardClient.GetGuildAsync(guildId);

                await discordUser.UnbanAsync(discordGuild);
            }
            catch (Exception e)
            {
                this.logger.LogError("Error in unbanning user", e);
            }
        }
Exemplo n.º 5
0
        public async Task UnBan(CommandContext ctx, DiscordUser user, [RemainingText] string reason = "No reason given.")
        {
            if ((await ctx.Guild.GetBansAsync()).Any(ban => ban.User.Id == user.Id))
            {
                await user.UnbanAsync(ctx.Guild, reason);

                var embed = new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, "", $"Unanned `{user.Username}#{user.Discriminator} ({user.Id})`! ")).AddField("Reason:", reason);

                await ctx.RespondAsync(embed : embed);
            }
            else
            {
                var embed = new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, "", $"{user.Mention} is not banned!")).WithColor(new DiscordColor("#d11515"));
                await ctx.RespondAsync(embed : embed);
            }
        }
Exemplo n.º 6
0
        public async Task Unban(CommandContext ctx, [Description("The user to unban.")] string userMention, [RemainingText, Description("The reason for unbanning the user.")] string reason = null)
        {
            ulong       userId = Utils.GetId(userMention);
            DiscordUser user   = await Program.discord.ShardClients.First().Value.GetUserAsync(userId);

            try
            {
                await user.UnbanAsync(ctx.Guild, reason);

                await ctx.RespondAsync($"Unbanned {user.Username}.");
            }
            catch
            {
                await ctx.RespondAsync("I can't unban that user. Maybe I don't have permission?");
            }
        }
Exemplo n.º 7
0
        public async Task Unban(CommandContext ctx, DiscordUser target, string reason = "No reason provided.")
        {
            await target.UnbanAsync(ctx.Guild, $"[Unban by {ctx.User.Username}#{ctx.User.Discriminator}] {reason}");

            await ctx.Channel.SendMessageAsync($"Succesfully unbanned **{target.Username}#{target.Discriminator}** (`{target.Id}`)");
        }
Exemplo n.º 8
0
        public async Task unban(CommandContext ctx, DiscordUser user)
        {
            await user.UnbanAsync(ctx.Guild);

            await ctx.Channel.SendMessageAsync(user.Mention + " has been unbanned.").ConfigureAwait(false);
        }