public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) =>
 Task.Run(() => BotUsers.IsBotMod(context.User) ?
          PreconditionResult.FromSuccess() :
          PreconditionResult.FromError($"{context.User.Username} is not a bot mod"));
 public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) =>
 Task.Run(() => BotUsers.IsIgnored(context.User) ?
          //PreconditionResult.FromError($"{context.User.Username} is an ignored user") :
          PreconditionResult.FromError("Did you hear something?") :
          PreconditionResult.FromSuccess());
Esempio n. 3
0
        public async Task TP([Remainder] string content)
        {
            if (content == null) // Exit if there wasn't an argument
            {
                return;
            }
            if (Context.Guild == null) // Checks if the message was sent in a guild
            {
                return;
            }
            // Mentioned channel ids
            var channelID = Context.Message.MentionedChannelIds;
            // Mentioned role ids
            var roleID = Context.Message.MentionedRoleIds;
            // Mentioned member ids
            var memberID = Context.Message.MentionedUserIds;

            // Splits the content by spaces
            string[] splitContent = content.Split(new char[] { ' ' });
            // Gets the last argument
            string lastArg = splitContent.LastOrDefault();

            if (string.IsNullOrEmpty(lastArg))
            {
                return;
            }

            // The message author as a guild user
            IGuildUser author = Context.Message.Author as IGuildUser;
            // The destination user
            IGuildUser destUser = null;
            // The destination channel
            IVoiceChannel destChannel = null;

            // Attempts to parse the last argument, removing non-digit chars, to an id
            ulong.TryParse(new string(lastArg.Where(character => char.IsLetterOrDigit(character)).ToArray()), out ulong lastArgID);

            // Attempt to find destination user based on lastArgID
            destUser = await Context.Guild.GetUserAsync(lastArgID);

            // Attempt to find destination channel based on lastArgID
            destChannel = await Context.Guild.GetVoiceChannelAsync(lastArgID);

            if (destChannel == null)  // If the destination channel is null
            {
                if (destUser == null) // If the destination user is ALSO null, exit
                {
                    await ReplyAsync("No voice channel or user found.");

                    return;
                }
                if (destUser.VoiceChannel == null) // If the destination user is not in a voice channel
                {
                    await ReplyAsync($"Specified user, {destUser.Username}, is not in a voice channel.");

                    return;
                }
                // Destination user must be not null and in a voice channel, set their channel to the destination channel
                destChannel = destUser.VoiceChannel;
            }

            // Potential teleport candidates
            var candidates = await Context.Guild.GetUsersAsync();

            // A list of IGuildUser to teleport
            List <IGuildUser> teleport = new List <IGuildUser>();
            // The afk voice channel of the server
            IVoiceChannel afkChannel = await Context.Guild.GetAFKChannelAsync();

            foreach (ulong id in memberID) // Add every mentioned user to the teleport list
            {
                teleport.Add(await Context.Guild.GetUserAsync(id));
            }

            if (splitContent.Length == 1) // If there was only one argument, add the author to the teleport list
            {
                teleport.Add(author);
            }

            if (BotUsers.IsBotMod(author))                        // If the author is a bot mod
            {
                if (splitContent.Length == 1 && destUser == null) // If there wasn't a user specified and there was only one argument, teleport everyone in voice
                {
                    foreach (IGuildUser user in candidates.Where(a => !string.IsNullOrEmpty(a.VoiceSessionId)))
                    {
                        teleport.Add(user);
                    }
                }

                if (roleID.Count > 0)// If a role was specified, teleport every user with specified role who is in voice
                {
                    foreach (ulong id in roleID)
                    {
                        foreach (IGuildUser user in candidates.Where(a => !string.IsNullOrEmpty(a.VoiceSessionId) && a.RoleIds.Any(b => b == id)))
                        {
                            teleport.Add(user);
                        }
                    }
                }
            }

            // Removes duplicates
            teleport = teleport.Distinct().ToList();

            // Removes the destination user and any user in the afk channel from the teleport list
            teleport.RemoveAll(user => user == destUser || user.VoiceChannel == afkChannel || user.VoiceChannel == destChannel);

            if (!author.GetPermissions(destChannel).MoveMembers) // If the author doesn't have move permissions for the destination channel, exit
            {
                await ReplyAsync($"You do not have move permission for channel \"{destChannel.Name}\"");

                return;
            }

            foreach (var user in teleport) // Teleport every user in the list
            {
                await user.ModifyAsync(userVoiceProperty => userVoiceProperty.Channel = new Optional <IVoiceChannel>(destChannel));
            }

            await ReplyAsync($"Teleported {teleport.Count} user(s) to \"{destChannel.Name}\"");
        }