Beispiel #1
0
 public async Task UnbanGuildMember(ulong user, [Remainder] string reason = null)
 {
     if (GeneralFunctions.CheckUlong(user) == true)
     {
         if (await DiscordBot.CheckIfBanned(Context.Guild.Id, user) == true)
         {
             await Context.Guild.RemoveBanAsync(user);
             await ReplyAsync($"The user with ID: {user} is unbanned.");
         }
         else
         {
             await ReplyAsync("Error 0x3: This user doesn't seem to be banned. Please check your command input.");
         }
     }
     else
     {
         await ReplyAsync("Error 0x2: This doesn't seem like a valid user id. Please check your command input.");
     }
 }
Beispiel #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.");
            }
        }