示例#1
0
        private async Task Client_UserBanned(SocketUser user, SocketGuild guild)
        {
            RestBan ban = await guild.GetBanAsync(user);

            RestAuditLogEntry logEntry = await GetAuditLogEntry(guild);

            if (logEntry.Action != ActionType.Ban)
            {
                return;
            }
            BanAuditLogData data           = (BanAuditLogData)logEntry.Data;
            string          targetUsername = "******" + user + "** _(" + user.Id + ")_";
            string          adminUsername  = "******" + logEntry.User + "**";
            string          msg            = targetUsername + " was banned by " + adminUsername +
                                             "\nReason: " + (string.IsNullOrEmpty(ban.Reason) ? "No reason provided." : ban.Reason);

            foreach (SocketTextChannel channel in Global.SECURITY_CHANNELS)
            {
                if (channel.Guild.Id == guild.Id)
                {
                    await SendSecurityLog(msg, new Color(255, 0, 0), channel, logEntry.Id.ToString(), logEntry.User.GetAvatarUrl());

                    break;
                }
            }
        }
示例#2
0
        public async Task UnBanUserAsync(string nameUser)
        {
            //UnBan user
            var     banList = Context.Guild.GetBansAsync().Result.ToArray();
            RestBan banUser = null;
            int     i       = 0;

            while (i < banList.Length)
            {
                if (banList[i].User.Username.ToUpper() == nameUser.ToUpper())
                {
                    banUser = banList[i];
                    break;
                }
                i++;
            }

            if (banUser != null)
            {
                await Context.Guild.RemoveBanAsync(banUser.User);

                var dmChannel = await banUser.User.GetOrCreateDMChannelAsync();

                await dmChannel.SendMessageAsync("You unbanned, thx for late. Good luck :kissing_heart: .");
            }
            else
            {
                await ReplyAsync("User not found.");
            }
        }
示例#3
0
        private async Task UserBaned(SocketUser arg1, SocketGuild arg2)
        {
            try
            {
                var guild = ConstVariables.CServer[arg2.Id];

                RestBan banned = await arg2.GetBanAsync(arg1);

                EmbedBuilder builder = new EmbedBuilder();

                Random ran = new Random();

                builder.WithFooter(arg2.Name, arg2.IconUrl)
                .WithTitle("Бан")
                .WithColor(ConstVariables.InfoColor);

                switch (ran.Next(0, 5))
                {
                case 0:
                {
                    builder.WithImageUrl("https://media.discordapp.net/attachments/462236317926031370/517352024640323584/ban_2.gif");
                    break;
                }

                case 1:
                {
                    builder.WithImageUrl("https://media.discordapp.net/attachments/462236317926031370/517352068328194059/ban_3.gif?width=405&height=475");
                    break;
                }

                case 2:
                {
                    builder.WithImageUrl("https://media.discordapp.net/attachments/462236317926031370/517352083226230794/ban_1.gif");
                    break;
                }

                default:
                {
                    builder.WithImageUrl("https://media.discordapp.net/attachments/462236317926031370/464149984619528193/tumblr_oda2o7m3NR1tydz8to1_500.gif");
                    break;
                }
                }


                builder.WithDescription($"Пользователь: {arg1.Mention} - забанен")
                .AddField($"Причина", banned.Reason ?? "неуказанно", true);

                ConstVariables.CServer[arg2.Id].EndUser = arg1.Id;

                await guild.GetDefaultChannel().SendMessageAsync("", false, builder.Build());

                ConstVariables.Logger.Info($"is func 'Ban' is Guild '{arg2.Name}' is user '{arg1.Username}#{arg1.Discriminator}' is Admin '{banned.User}' is Reason '{banned.Reason}'");
            }
            catch (Exception e)
            {
                ConstVariables.Logger.Error($"is func 'Ban' is Guild '{arg2.Name}' is user '{arg1.Username}#{arg1.Discriminator}' is error '{e}'");
            }
        }
        public static async Task UserBanned(SocketUser arg1, SocketGuild arg2)
        {
            GuildCfg guildCfg = GuildsCfgs.GetGuildCfg(arg2);
            ISocketMessageChannel modChannel = (ISocketMessageChannel)Methods.GetTextChannelByID(arg2, guildCfg.ModeratorChannelID);

            RestBan ban = arg2.GetBansAsync().Result.ToList().FirstOrDefault(x => x.User.Id == arg1.Id);

            await modChannel.SendMessageAsync($"{ban.User.Mention} ({ban.User.Id}) otrzymał bana. Powód: {ban.Reason}");
        }
示例#5
0
        public static async Task <bool> CheckIfBanned(ulong guildId, ulong UserId)
        {
            try
            {
                RestBan ban = await client.GetGuild(guildId).GetBanAsync(UserId);

                return(true);
            }
            catch (HttpException e) when(e.DiscordCode == 10026)
            {
                return(false);
            }
        }
示例#6
0
        public async Task <CommandResult> UnbanAsync(RestBan ban, [Remainder] string reason = null)
        {
            await Context.Guild.RemoveBanAsync(ban.User);

            try
            {
                await _databaseService.CreateNewCaseAsync(Context.Guild, reason, ActionType.Unban, 0, Context.User, ban.User);
            }
            catch (InvalidOperationException ex)
            {
                return(new QuiccbanFailResult(ex.Message));
            }
            return(new QuiccbanSuccessResult(string.Format(_responseService.Get("unban_success"), ban.User.ToString(), ban.User.Mention)));
        }
示例#7
0
        public void CanCreateBan()
        {
            IRestBan ban = new RestBan(
                1,
                BanType.Job,
                new CKey("Bobbahbrown"),
                DateTimeOffset.Now,
                new CKey("Pomf"),
                "Test ban please ignore",
                null,
                null,
                new[] { new RestJobBan("Janitor") });

            Assert.NotNull(ban);
        }
示例#8
0
        private async Task LogUserBanned(SocketUser user, SocketGuild guild)
        {
            RestBan ban = await guild.GetBanAsync((IUser)user);

            var embed = new EmbedBuilder()
                        .WithTitle("User Banned")
                        .WithColor(Color.DarkRed)
                        .WithCurrentTimestamp()
                        .WithDescription($"User: {user.Username}\nUser ID: {user.Id}\nBot User: {isBotUser(user)}" +
                                         $"\nReason for ban: ```{((ban?.Reason != null) ? ban?.Reason : "No reason given")}```").Build();

            if (Global.userEventLogChannel != null)
            {
                await Global.userEventLogChannel.SendMessageAsync(embed : embed);
            }
        }
示例#9
0
        public void CanSerializeBan()
        {
            IRestBan ban = new RestBan(
                1,
                BanType.Job,
                new CKey("Bobbahbrown"),
                DateTimeOffset.Now,
                new CKey("Pomf"),
                "Test ban please ignore",
                null,
                null,
                new[] { new RestJobBan("Janitor") });

            var options      = GetOptions();
            var serialized   = JsonSerializer.Serialize(ban, options);
            var deserialized = JsonSerializer.Deserialize <IRestBan>(serialized, options);

            Assert.NotNull(deserialized);
        }
示例#10
0
        public async Task UnbanUser(ulong targetId, [Remainder] string reason = "No reason provided.")
        {
            try
            {
                RestBan restBan = null;
                try { restBan = await Context.Guild.GetBanAsync(targetId); }
                catch { throw new InvalidOperationException($"User is not banned"); }

                await Context.Guild.RemoveBanAsync(targetId);
                await ReplyAsync(await EmbedHandler.CreateBasicEmbed(ModuleName, $"Unbanned {restBan.User.Mention} - `{reason}`.", Color.Orange));

                if (!restBan.User.IsBot)
                {
                    await restBan.User.SendMessageAsync(embed : await EmbedHandler.CreateBasicEmbed(ModuleName,
                                                                                                    $"You have been unbanned from {Context.Guild.Name} for '{reason}'", Color.Green));
                }
            }
            catch (InvalidOperationException ex) { await ReplyAsync(EmbedHandler.CreateErrorEmbed(ModuleName, ex.Message)); }
        }
示例#11
0
        private async Task ShardOnUserBanned(SocketUser user, SocketGuild socketGuild)
        {
            GuildBson guild = await this.database.LoadRecordsByGuildId(socketGuild.Id);

            if (GetRestTextChannel(this.shard, guild.UserBannedEvent, out RestTextChannel restTextChannel))
            {
                RestBan ban = await socketGuild.GetBanAsync(user.Id);

                List <EmbedFieldBuilder> fields = new()
                {
                    new EmbedFieldBuilder
                    {
                        Name  = "Username",
                        Value = user.Username
                    },
                    new EmbedFieldBuilder
                    {
                        Name  = "User Id",
                        Value = user.Id
                    },
                    new EmbedFieldBuilder
                    {
                        Name  = "Ban reason",
                        Value = ban.Reason
                    }
                };

                EmbedBuilder embedBuilder = new()
                {
                    Color    = Color.Red,
                    Fields   = fields,
                    ImageUrl = user.GetAvatarUrl(),
                    Footer   = new EmbedFooterBuilder {
                        Text = $"Banned on {DateTime.UtcNow} UTC"
                    }
                };

                await restTextChannel.SendMessageAsync("", false, embedBuilder.Build());
            }
        }
    }
}
示例#12
0
        private async Task OnUserBanned(SocketUser user, SocketGuild guild)
        {
            Server server;

            if (!this.Client.Servers.ContainsKey(guild.Id) || (server = this.Client.Servers[guild.Id]) == null ||
                this.RecentlyBannedUserIDs.Contains(user.Id))
            {
                return;
            }

            BanAuditLogData   auditData  = null;
            RestAuditLogEntry auditEntry = null;

            if (guild.CurrentUser.GuildPermissions.ViewAuditLog)
            {
                await Task.Delay(500);

                try
                {
                    auditEntry = await guild.GetAuditLogsAsync(10)?.Flatten()?.FirstOrDefault(e => e != null && e.Action == ActionType.Ban && (auditData = e.Data as BanAuditLogData) != null && auditData.Target.Id == user.Id);

                    //One huge line because black magic from .NET Core?
                }
                catch (Exception) { }
            }

            string  reason = "unknown";
            RestBan ban    = await server.Guild.GetBanAsync(user);

            if (ban != null)
            {
                reason = ban.Reason;
                await this.Client.Events.AddBan(guild.Id, user.Id, TimeSpan.Zero, reason);
            }
            await LogBan(server, user.GetUsername(), user.Id, reason, "permanently", auditEntry?.User as SocketGuildUser);
        }
示例#13
0
        public static async Task CheckTempActs(DiscordSocketClient client, bool debug = false, CancellationToken?ct = null)
        {
            RequestOptions requestOptions = RequestOptions.Default;

            requestOptions.RetryMode = RetryMode.AlwaysRetry;
            try
            {
                currentInfo.checkedGuilds = 0;
                foreach (SocketGuild sockGuild in client.Guilds)
                {
                    ct?.ThrowIfCancellationRequested();
                    currentInfo.checkedMutes = 0;
                    if (currentInfo.checkedGuilds > client.Guilds.Count)
                    {
                        await new LogMessage(LogSeverity.Error, "TempAct", $"Check went past all guilds (at #{currentInfo.checkedGuilds}) but has been stopped. This doesn't seem physically possible.").Log();
                        return;
                    }
                    RestGuild restGuild = await client.Rest.SuperGetRestGuild(sockGuild.Id);

                    if (debug)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write($"\nChecking {sockGuild.Name} discord ");
                    }
                    TempActionList actions  = sockGuild.LoadFromFile <TempActionList>(false);
                    bool           needSave = false;
                    currentInfo.checkedGuilds++;
                    if (actions != null)
                    {
                        if (actions.tempBans?.Count is not null or 0)
                        {
                            currentInfo.editedBans = new List <TempAct>(actions.tempBans);
                            foreach (TempAct tempBan in actions.tempBans)
                            {
                                try
                                {
                                    RestBan ban = await sockGuild.GetBanAsync(tempBan.User, requestOptions);

                                    if (ban == null)
                                    { //If manual unban
                                        var user = await client.Rest.GetUserAsync(tempBan.User);

                                        currentInfo.editedBans.Remove(tempBan);
                                        user?.TryNotify($"As you might know, you have been manually unbanned in {sockGuild.Name} discord");
                                        //_ = new LogMessage(LogSeverity.Warning, "TempAction", "Tempbanned person isn't banned").Log();
                                        if (user == null)
                                        {
                                            DiscordLogging.LogManualEndTempAct(sockGuild, tempBan.User, "bann", tempBan.DateBanned);
                                        }
                                        else
                                        {
                                            DiscordLogging.LogManualEndTempAct(sockGuild, user, "bann", tempBan.DateBanned);
                                        }
                                    }
                                    else if (DateTime.UtcNow >= tempBan.DateBanned.Add(tempBan.Length))
                                    {
                                        RestUser rUser = ban.User;
                                        await sockGuild.RemoveBanAsync(tempBan.User, requestOptions);

                                        currentInfo.editedBans.Remove(tempBan);
                                        DiscordLogging.LogEndTempAct(sockGuild, rUser, "bann", tempBan.Reason, tempBan.Length);
                                    }
                                }
                                catch (Exception e)
                                {
                                    await new LogMessage(LogSeverity.Error, "TempAct", "Something went wrong unbanning someone, continuing", e).Log();
                                }
                            }

                            //if all tempbans DON'T equal all edited tempbans (basically if there was a change
                            if (currentInfo.editedBans.Count != actions.tempBans.Count)
                            {
                                if (debug)
                                {
                                    Console.Write($"{actions.tempBans.Count - currentInfo.editedBans.Count} tempbans are over, ");
                                }
                                needSave         = true;
                                actions.tempBans = currentInfo.editedBans;
                            }
                            else if (debug)
                            {
                                Console.Write($"tempbans checked, none over, ");
                            }
                        }
                        else if (debug)
                        {
                            Console.Write($"no tempbans, ");
                        }
                        ModerationSettings settings = sockGuild.LoadFromFile <ModerationSettings>();
                        if (settings is not null && sockGuild.GetRole(settings.mutedRole) != null && actions.tempMutes?.Count is not null or 0)
                        {
                            var            mutedRole   = sockGuild.GetRole(settings.mutedRole);
                            List <TempAct> editedMutes = new List <TempAct>(actions.tempMutes);
                            foreach (TempAct tempMute in actions.tempMutes)
                            {
                                currentInfo.checkedMutes++;
                                try
                                {
                                    IGuildUser gUser = sockGuild.GetUser(tempMute.User) ?? await restGuild.SuperGetUser(tempMute.User);

                                    if (gUser != null && !gUser.RoleIds.Contains(settings.mutedRole))
                                    { //User missing muted role, must have been manually unmuted
                                        _ = gUser.TryNotify($"As you might know, you have been manually unmuted in {sockGuild.Name} discord");
                                        editedMutes.Remove(tempMute);
                                        DiscordLogging.LogManualEndTempAct(sockGuild, gUser, "mut", tempMute.DateBanned);
                                        _ = (!editedMutes.Contains(tempMute)).AssertAsync("Tempmute not removed?!");
                                    }
                                    else if (DateTime.UtcNow >= tempMute.DateBanned.Add(tempMute.Length))
                                    { //Normal mute end
                                        if (gUser != null)
                                        {
                                            await gUser.RemoveRoleAsync(mutedRole, requestOptions);
                                        } // if user not in guild || if user doesn't contain muted role (successfully removed?
                                        if (gUser == null || !gUser.RoleIds.Contains(settings.mutedRole))
                                        { //Doesn't remove tempmute if unmuting fails
                                            IUser user = gUser; //Gets user to try to message
                                            user ??= await client.SuperGetUser(tempMute.User);

                                            if (user != null)
                                            { // if possible to message, message and log
                                                DiscordLogging.LogEndTempAct(sockGuild, user, "mut", tempMute.Reason, tempMute.Length);
                                                _ = user.Notify("auto untempmuted", tempMute.Reason, sockGuild, client.CurrentUser);
                                            }
                                            editedMutes.Remove(tempMute);
                                        }
                                        else if (gUser != null)
                                        {
                                            await new LogMessage(LogSeverity.Warning, "TempAct", "User should've had role removed").Log();
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    await new LogMessage(LogSeverity.Error, "TempAct", "Something went wrong unmuting someone, continuing", e).Log();
                                }
                            }

                            //NOTE: Assertions fail if NOT true
                            _ = (currentInfo.checkedMutes == actions.tempMutes.Count).AssertAsync($"Checked incorrect number tempmutes ({currentInfo.checkedMutes}/{actions.tempMutes.Count}) in guild {sockGuild} owned by {sockGuild.Owner}");

                            if (editedMutes.Count != actions.tempMutes.Count)
                            {
                                if (debug)
                                {
                                    Console.Write($"{actions.tempMutes.Count - editedMutes.Count}/{actions.tempMutes.Count} tempmutes are over");
                                }
                                actions.tempMutes = editedMutes;
                                needSave          = true;
                            }
                            else if (debug)
                            {
                                Console.Write($"none of {actions.tempMutes.Count} tempmutes over");
                            }
                        }
                        else if (debug)
                        {
                            Console.Write("no tempmutes to check or no settings");
                        }
                        if (needSave)
                        {
                            actions.SaveToFile();
                        }
                    }