Пример #1
0
 public static async Task UserBanned(SocketUser user, SocketGuild guild)
 {
     Console.WriteLine("ReceivedBanEvent");
     if ((await guild.GetBanAsync(user.Id)).Reason.Contains(DiscordBot.client.CurrentUser.Id.ToString()) == false)
     {
         BanInfo banInfo = new BanInfo()
         {
             Source            = "Ban Event",
             Reason            = (await guild.GetBanAsync(user.Id)).Reason,
             UserId            = user.Id,
             Username          = user.Username,
             UserDiscriminator = user.Discriminator,
             UserNickname      = guild.GetUser(user.Id).Nickname,
             UserCreationDate  = user.CreatedAt,
             JoinDate          = guild.GetUser(user.Id).JoinedAt
         };
         await DiscordBot.SendBanMessage(banInfo);
     }
 }
Пример #2
0
        public async Task BanGuildMember(string user, [Remainder] string reason = null)
        {
            if (string.IsNullOrEmpty(reason))
            {
                reason = "There was no reason given.";
            }
            IGuildUser bannedUser;

            if (GeneralFunctions.CheckUlong(user) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(user)))
            {
                bannedUser = await Context.Guild.GetUserAsync(Convert.ToUInt64(user));
            }
            else if (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()))
            {
                bannedUser = await Context.Guild.GetUserAsync(Context.Message.MentionedUserIds.First());
            }
            else if ((GeneralFunctions.CheckUlong(user) == true && DiscordBot.CheckIsInGuild(Context.Guild.Id, Convert.ToUInt64(user)) == false) || (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count >= 1 && DiscordBot.CheckIsInGuild(Context.Guild.Id, Context.Message.MentionedUserIds.First()) == false))
            {
                await ReplyAsync("Error 0x2: This user was not found in this server.");

                return;
            }
            else if (GeneralFunctions.CheckUlong(user) == false || (GeneralFunctions.CheckUlong(user) == false && Context.Message.MentionedUserIds.Count == 0))
            {
                await ReplyAsync("Error 0x3: There was not a valid id or mention found.");

                return;
            }
            else
            {
                await ReplyAsync("Error 0x4: An error occured during command execution please check your input");

                return;
            }

            #region comment
            //Continue if:
            //1.  The user is in the guild.
            //2.  The user id is valid or if the mention is valid.

            //Errors:

            //Error 1: invalid mention or id
            //Error 2: User not found
            //Error 3: Given too many users
            //Error 4: Unknown Error
            #endregion

            BanInfo bannedUserInfo = new BanInfo
            {
                UserId             = bannedUser.Id,
                Username           = bannedUser.Username,
                UserDiscriminator  = bannedUser.Discriminator,
                UserNickname       = bannedUser.Nickname,
                UserCreationDate   = bannedUser.CreatedAt,
                JoinDate           = bannedUser.JoinedAt,
                StaffId            = Context.Message.Author.Id,
                StaffUsername      = Context.Message.Author.Username,
                StaffDiscriminator = Context.Message.Author.Discriminator,
                Source             = "Ban Command",
                Reason             = reason
            };
            await Context.Guild.AddBanAsync(bannedUser, 0, DiscordBot.client.CurrentUser.Id.ToString() + " - " + reason);

            if (await DiscordBot.CheckIfBanned(Context.Guild.Id, bannedUserInfo.UserId) == true)
            {
                await ReplyAsync("The user was banned.");

                await DiscordBot.SendBanMessage(bannedUserInfo);
            }
            else
            {
                await ReplyAsync("Error 0x5: User was not banned for an unknown reason.");
            }
        }