Пример #1
0
        private async Task OnUserBanned(SocketUser user, SocketGuild server)
        {
            var banData     = server.GetBanAsync(user.Id);
            var banningUser = GetBanningUserFromAuditLog(server, user.Id);
            var banReason   = banData.Result.Reason ?? StringConstants.NoReasonGiven;

            _banningService.StoreBan(
                banData.Result.User.Id,
                banData.Result.User.Username,
                banningUser.Id,
                banningUser.Username,
                0,
                banReason
                );

            try
            {
                var dmChannel = await user.GetOrCreateDMChannelAsync();

                dmChannel.SendMessageAsync($"You have been banned from **{server.Name}**. This ban is permanent.");
            }
            catch (Exception e)
            {
                Logger.Write($"Failed to send ban notification to {user.Username}: {e.Message}");
            }

            Logger.Write($"[OnUserBanned] {banningUser.Username} banned {user.Username} for {banReason}");
        }
Пример #2
0
        public async Task Ban(
            IUser user            = null,
            int days              = 0,
            int hours             = 0,
            int sendMessageToUser = 0,
            [RemainderAttribute] string reason = StringConstants.NoReasonGiven)
        {
            if (Context.Channel.Id != _adminChannelId)
            {
                return;
            }

            if (user == null)
            {
                ReplyAsync("`/ban [@]<user> [days] [hours] [send ban message] [reason]` - Issues a discord ban" +
                           "\n" +
                           "Set **days** & **hours** to 0 for a permanent ban" +
                           "\n" +
                           "Set **send ban message** to 1 to direct message the user the ban reason and expire time, 0 not to: <https://i.imgur.com/2RUOa7L.png>");
                return;
            }

            var guildUser = Context.Guild.GetUser(user.Id);

            if (guildUser == null)
            {
                ReplyAsync(StringConstants.UserNotFound);
                return;
            }

            if (days < 0 || hours < 0)
            {
                ReplyAsync("Invalid duration.");
                return;
            }

            if (sendMessageToUser != 0 && sendMessageToUser != 1)
            {
                ReplyAsync("Set send user message to either 0 or 1.");
                return;
            }

            int daysToSeconds  = (days * 86400);
            int hoursToSeconds = (hours * 3600);
            int timeToAdd      = daysToSeconds + hoursToSeconds;
            int isTimedBan     = (days == 0 && hours == 0) ? 0 : 1;
            var dmChannel      = await guildUser.GetOrCreateDMChannelAsync();

            if (isTimedBan == 1)
            {
                var expiresOn = _timeProvider.UtcNow.AddSeconds(timeToAdd);
                ReplyAsync($"Banned <@{guildUser.Id}> ({guildUser.Username}) for {reason}. Ban will expire on **{expiresOn.ToHumanReadableString()}**.");

                if (sendMessageToUser == 1)
                {
                    dmChannel.SendMessageAsync($"You have been banned from **{Context.Guild.Name}** for **{reason}**. This ban will expire on **{expiresOn.ToHumanReadableString()}**.");
                }
            }
            else
            {
                ReplyAsync($"Banned <@{guildUser.Id}> ({guildUser.Username}) for {reason}. Ban is permanent.");

                if (sendMessageToUser == 1)
                {
                    dmChannel.SendMessageAsync($"You have been banned from **{Context.Guild.Name}** for **{reason}**. This ban is permanent.");
                }
            }

            _banningService.StoreBan(
                guildUser.Id,
                guildUser.Username,
                Context.User.Id,
                Context.User.Username,
                timeToAdd * isTimedBan, reason
                );
            Context.Guild.AddBanAsync(guildUser, 0, $"By {Context.User.Username} for {reason}");
        }