Esempio n. 1
0
        public async Task LockAsync()
        {
            var user = Context.User;
            var vc   = (user as IVoiceState)?.VoiceChannel;

            if (vc != null)
            { // Make sure the users is actually in a voice channel
                if (!VoiceWhitelist.check(Context.Guild.Id, vc.Name))
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Mention} That channel is not available through that command");

                    return;
                }

                var count = (await vc.GetUsersAsync().FlattenAsync()).Count(); // Get number of users in the current voice channel
                await vc.ModifyAsync(x =>
                {
                    x.UserLimit = count; // Set the user limit of the channel equal to the current number of users
                });

                Console.WriteLine($"{user.Username}#{user.Discriminator} locked {vc.Name} with {count} users");
                await Context.Channel.SendMessageAsync($"{vc.Name} has been locked by " + user.Mention);
            }
            else
            {
                await Context.Channel.SendMessageAsync("You must be in a voice channel to perform this command");
            }
        }
        private static VoiceWhitelist GetInstance()
        {
            if (instance == null)
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = JsonConvert.DeserializeObject <VoiceWhitelist>(File.ReadAllText("VoiceWhitelist.json"));
                    }
                }
            }

            return(instance);
        }
 public static bool check(ulong guildId, string vc)
 {
     foreach (GuildWhitelist guild in VoiceWhitelist.GetInstance().whitelist)
     {
         if (guild.guildId == guildId)
         {
             foreach (string channel in guild.whitelistChannels)
             {
                 if (channel.Equals(Voice.ProcessName(vc).name))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }