private static void AddDefaultChannel(ulong id, string name, int index)
        {
            VoiceChannel newChannel = new VoiceChannel(id, name, index);

            defaultChannels.Add(id, newChannel);
            allVoiceChannels.Add(id, newChannel);
        }
        public async Task LoadNextSong()
        {
            CurrentSong?.Stop();
            CurrentSong = null;
            if (SongQueue.Count != 0)
            {
                lock (_voiceLock) {
                    CurrentSong = SongQueue[0];
                    SongQueue.RemoveAt(0);
                }
            }
            else
            {
                Stop();
                return;
            }

            try {
                if (VoiceClient == null)
                {
                    Console.WriteLine($"Joining voice channel [{DateTime.Now.Second}]");
                    //todo add a new event, to tell people nadeko is trying to join
                    VoiceClient = await Task.Run(async() => await VoiceChannel.JoinAudio());

                    Console.WriteLine($"Joined voicechannel [{DateTime.Now.Second}]");
                }
                await Task.Factory.StartNew(async() => await CurrentSong?.Start(), TaskCreationOptions.LongRunning).Unwrap();
            }
            catch (Exception ex) {
                Console.WriteLine($"Starting failed: {ex}");
                CurrentSong?.Stop();
                CurrentSong = null;
            }
        }
Exemple #3
0
        private void Speak(VoiceChannel channel)
        {
            bool done = false;

            var session = _client.JoinVoiceChannel(channel.Guild.Id, channel.Id);

            session.OnConnected += (s, args) =>
            {
                Console.WriteLine($"[{_client.User}] Speaking in channel.");

                session.SetSpeakingState(DiscordVoiceSpeakingState.Microphone);

                var stream = session.CreateStream(channel.Bitrate);
                stream.CopyFrom(Program.Audio);

                session.SetSpeakingState(DiscordVoiceSpeakingState.NotSpeaking);

                done = true;
            };

            while (!done)
            {
                Thread.Sleep(10);
            }
        }
Exemple #4
0
        private async Task Leave(Server server, VoiceChannel channel)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }

            if (Config.EnableMultiserver)
            {
                AudioClient client;
                //Potential race condition if changing channels during this call, but that's acceptable
                if (channel == null || (_voiceClients.TryGetValue(server.Id, out client) && client.Channel == channel))
                {
                    if (_voiceClients.TryRemove(server.Id, out client))
                    {
                        await client.Disconnect().ConfigureAwait(false);
                    }
                }
            }
            else
            {
                using (await _asyncLock.LockAsync().ConfigureAwait(false))
                {
                    var client = GetClient(server) as VirtualClient;
                    if (client != null && client.Channel == channel)
                    {
                        await _defaultClient.Disconnect().ConfigureAwait(false);
                    }
                }
            }
        }
Exemple #5
0
        public void Start()
        {
            Running = true;

            Task.Run(() =>
            {
                var voiceClient = _client.GetVoiceClient(_guildId);

                while (voiceClient.State == MediaConnectionState.Ready && Tracks.Count > 0)
                {
                    var currentSong = Tracks[0];

                    var manifest = Program.YouTubeClient.Videos.Streams.GetManifestAsync(currentSong.Id).Result;

                    if (_stream == null)
                    {
                        VoiceChannel currentChannel = (VoiceChannel)_client.GetChannel(voiceClient.Channel.Id);
                        _stream = DiscordVoiceUtils.GetAudioStream(GetVideoUrl(currentSong.Id, currentChannel.Bitrate));
                    }

                    if (voiceClient.Microphone.CopyFrom(_stream, currentSong.CancellationTokenSource.Token))
                    {
                        _stream = null;
                        Tracks.RemoveAt(0);
                    }
                    else if (currentSong.CancellationTokenSource.IsCancellationRequested)
                    {
                        _stream = null;
                    }
                }

                Running = false;
            });
        }
        public static void GetTags(VoiceChannel channel)
        {
            List <VoiceChannelTag> tags = voiceChannelTags.ToList();

            for (int i = 0; i < tags.Count; i++)
            {
                VoiceChannelTag curTag = tags [i];

                VoiceChannelTag.ActionData data = new VoiceChannelTag.ActionData(channel);
                try {
                    if (curTag.enabled)
                    {
                        curTag.run(data);
                    }
                }catch (Exception e) {
                    Logging.DebugLog(Logging.LogType.EXCEPTION, e.StackTrace);
                }

                if (data.hasTag)
                {
                    if (!channel.currentTags.Contains(curTag))
                    {
                        channel.currentTags.Add(curTag);
                    }
                }
                else
                {
                    if (channel.currentTags.Contains(curTag))
                    {
                        channel.currentTags.Remove(curTag);
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async ValueTask DisposeAsync()
        {
            Queue.Clear();
            await VoiceChannel.DisconnectAsync().ConfigureAwait(false);

            GC.SuppressFinalize(this);
        }
Exemple #8
0
        public async Task Join(VoiceChannel channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            if (channel.Type != ChannelType.Voice)
            {
                throw new ArgumentException("Channel must be a voice channel.", nameof(channel));
            }
            if (channel == VoiceSocket.Channel)
            {
                return;
            }
            var server = channel.Server;

            if (server != VoiceSocket.Server)
            {
                throw new ArgumentException("This is channel is not part of the current server.", nameof(channel));
            }
            if (VoiceSocket.Server == null)
            {
                throw new InvalidOperationException("This client has been closed.");
            }

            SendVoiceUpdate(channel.Server.Id, channel.Id);
            using (await _connectionLock.LockAsync().ConfigureAwait(false))
                await Task.Run(() => VoiceSocket.WaitForConnection(CancelToken)).ConfigureAwait(false);
        }
        public async Task PlayAudioAsync()
        {
            var audioClient = await VoiceChannel.ConnectAsync(selfDeaf : true);

            while (Queue.Count != 0)
            {
                CurrentlyPlaying = Queue.Dequeue(); //dequeue the latest video
                await DownloadVideo(CurrentlyPlaying);

                using (var ffmpeg = CreateStream($"{id}.mp3"))
                    using (var output = ffmpeg.StandardOutput.BaseStream)
                        using (var discord = audioClient.CreatePCMStream(AudioApplication.Mixed))
                        {
                            FFmpegId = ffmpeg.Id;
                            try
                            {
                                await output.CopyToAsync(discord);
                            }
                            finally
                            {
                                await discord.FlushAsync();

                                CurrentlyPlaying = null;
                            }
                        }
            }
            await audioClient.StopAsync();
        }
 public static void ResetData()
 {
     allVoiceChannels = new Dictionary <ulong, VoiceChannel> ();
     defaultChannels  = new Dictionary <ulong, VoiceChannel> ();
     awaitingChannels = new List <string> ();
     afkChannel       = null;
     hasChecked       = false;
     nameQueue        = new Dictionary <string, bool> ();
 }
        public static async Task <VoiceChannel> CreateTemporaryChannel(string channelName, TimeSpan lifeTime)
        {
            RestVoiceChannel channel = await Utility.GetServer().CreateVoiceChannelAsync(channelName);

            VoiceChannel newVoice = new VoiceChannel(channel.Id, channelName, allVoiceChannels.Count);

            newVoice.lifeTime = lifeTime;
            AddTemporaryChannel(channel.Id, newVoice);
            return(allVoiceChannels [channel.Id]);
        }
Exemple #12
0
        public async Task <IAudioClient> Join(VoiceChannel channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }

            var server = channel.Server;

            using (await _asyncLock.LockAsync().ConfigureAwait(false))
            {
                if (Config.EnableMultiserver)
                {
                    AudioClient client;
                    if (!_voiceClients.TryGetValue(server.Id, out client))
                    {
                        client = new AudioClient(Client, server, unchecked (++_nextClientId));
                        _voiceClients[server.Id] = client;

                        await client.Connect().ConfigureAwait(false);

                        /*voiceClient.VoiceSocket.FrameReceived += (s, e) =>
                         * {
                         *  OnFrameReceieved(e);
                         * };
                         * voiceClient.VoiceSocket.UserIsSpeaking += (s, e) =>
                         * {
                         *  var user = server.GetUser(e.UserId);
                         *  OnUserIsSpeakingUpdated(user, e.IsSpeaking);
                         * };*/
                    }

                    await client.Join(channel).ConfigureAwait(false);

                    return(client);
                }
                else
                {
                    if (_defaultClient.Server != server)
                    {
                        await _defaultClient.Disconnect().ConfigureAwait(false);

                        _defaultClient.VoiceSocket.Server = server;
                        await _defaultClient.Connect().ConfigureAwait(false);
                    }
                    var client = new VirtualClient(_defaultClient, server);
                    _currentClient = client;

                    await client.Join(channel).ConfigureAwait(false);

                    return(client);
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Restricts the voice channel to _role only
        /// </summary>
        /// <returns></returns>
        public async Task RestrictVoiceChannel()
        {
            var perms = new OverwritePermissions();

            perms.Modify(speak: PermValue.Allow, connect: PermValue.Allow);
            await VoiceChannel.AddPermissionOverwriteAsync(_role, perms);

            perms.Modify(speak: PermValue.Deny, connect: PermValue.Deny);
            var everyoneRole = _context.Guild.EveryoneRole;
            await VoiceChannel.AddPermissionOverwriteAsync(everyoneRole, perms);
        }
        internal BindableVoiceChannel(
            IMessenger messenger,
            IClipboardService clipboardService,
            IDiscordService discordService,
            QuarrelClient quarrelClient,
            IDispatcherService dispatcherService,
            VoiceChannel channel,
            GuildMember selfMember,
            BindableCategoryChannel?parent = null) :
            base(messenger, clipboardService, discordService, quarrelClient, dispatcherService, channel, selfMember, parent)
        {
            SelectionCommand  = new RelayCommand(Select);
            OpenChatCommand   = new RelayCommand(OpenChat);
            JoinCallCommand   = new RelayCommand(JoinCall);
            MarkAsReadCommand = new RelayCommand(MarkRead);

            VoiceMembers = new ObservableCollection <BindableVoiceState>(
                channel.GetVoiceStates()
                .Select(x => new BindableVoiceState(messenger, discordService, quarrelClient, dispatcherService, x)));

            _messenger.Register <MyVoiceStateUpdatedMessage>(this, (_, m) =>
            {
                IsConnected = m.VoiceState.Channel?.Id == Id;
            });
            _messenger.Register <VoiceStateAddedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        var state = new BindableVoiceState(
                            _messenger,
                            _discordService,
                            _quarrelClient,
                            _dispatcherService,
                            m.VoiceState);

                        VoiceMembers.Add(state);
                    });
                }
            });
            _messenger.Register <VoiceStateRemovedMessage>(this, (_, m) =>
            {
                if (m.VoiceState.Channel?.Id == Id)
                {
                    _dispatcherService.RunOnUIThread(() =>
                    {
                        VoiceMembers.Remove(VoiceMembers.FirstOrDefault(x =>
                                                                        x.State.User?.Id == m.VoiceState.User?.Id));
                    });
                }
            });
        }
Exemple #15
0
        /// <summary>
        /// Destroys the rolls and the voice channel
        /// </summary>
        /// <param name="source"></param>
        private async void Destroy(Object source)
        {
            try
            {
                await VoiceChannel.DeleteAsync();

                await _role.DeleteAsync();

                await _context.Channel.SendMessageAsync("Voice channel expired!");
            } catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #16
0
 public async Task GuildDeleteVoiceChannel([Remainder] string name)
 {
     foreach (var VoiceChannel in Context.Guild.VoiceChannels)
     {
         if (VoiceChannel.Name == name)
         {
             VoiceChannel.DeleteAsync();
             embed.WithTitle("Voice Channel Deleted");
             embed.WithDescription($"{Context.User.Mention} Successfully deleted the voice channel `{VoiceChannel.Name}`!");
             embed.WithColor(Pink);
             BE();
         }
     }
 }
 /// <summary>
 /// Reset things upon level load.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="scenemode"></param>
 void OnLevelFinishedLoading(Scene scene, LoadSceneMode scenemode)
 {
     if (this != null && this.gameObject != null)
     {
         locview  = GetComponent <PhotonView>();
         locaudio = GetComponent <AudioSource>();
         if (locview)
         {
             locview.onSerializeTransformOption = OnSerializeTransform.All;
         }
         transformview = GetComponent <PhotonTransformView>();
         if (locview)
         {
             locview.World = GameObject.Find("Objects");
         }
         if (transformview)
         {
             transformview.World = GameObject.Find("Objects");
         }
         if (scene.name != "mptest")
         {
             curchannel     = VoiceChannel.All;
             locview.ingame = false;
         }
         else
         {
             if (crossvar == null)
             {
                 if (GameObject.Find("CrossLevelVariables"))
                 {
                     crossvar = GameObject.Find("CrossLevelVariables").GetComponent <CrossLevelVariableHolder>();
                 }
             }
             if (crossvar.Gamemode == CrossLevelVariableHolder.gamemode.TeamDeathMatch || crossvar.Gamemode == CrossLevelVariableHolder.gamemode.CapitalShip)
             {
                 curchannel = VoiceChannel.TeamOnly;
             }
             else
             {
                 curchannel = VoiceChannel.All;
             }
             if (PhotonNetwork.playerList.Length == 2)
             {
                 curchannel = VoiceChannel.All;
             }
             locview.ingame = true;
         }
     }
 }
Exemple #18
0
        /// <summary>
        /// Makes a new instance of <see cref="DiscordServer"/> class.
        /// </summary>
        public DiscordServer(SocketGuild handler, IConfigurationRoot config, Random rand, ServiceProvider services)
        {
            DiscordHandler = handler;
            Configuration  = config;
            Rand           = rand;
            Services       = services;

            DiscordClient = Services.GetService <DiscordSocketClient>();
            var youtube = Services.GetService <Youtube>();

            BotChannel     = new BotChannel(this);
            AudioModule    = new VoiceChannel(this);
            CocoritaModule = new Cocorita(this);
            Player         = new MusicPlayer(this, youtube);
        }
 void SetCurrentChannel(int input)
 {
     if (input == 0)
     {
         curchannel = VoiceChannel.Muteall;
     }
     else if (input == 1)
     {
         curchannel = VoiceChannel.TeamOnly;
     }
     else if (input == 2)
     {
         curchannel = VoiceChannel.All;
     }
 }
Exemple #20
0
        /// <summary>
        /// Disposes <see cref="LavaPlayer"/>, sends a stop and destroy request to Lavalink server and disconnects from <see cref="VoiceChannel"/>.
        /// </summary>
        public async ValueTask DisposeAsync()
        {
            IsPlaying = false;
            Queue.Clear();
            Queue        = null;
            CurrentTrack = null;
            var stopPayload    = new StopPayload(VoiceChannel.GuildId);
            var destroyPayload = new DestroyPayload(VoiceChannel.GuildId);
            await _socketHelper.SendPayloadAsync(stopPayload);

            await _socketHelper.SendPayloadAsync(destroyPayload);

            await VoiceChannel.DisconnectAsync().ConfigureAwait(false);

            GC.SuppressFinalize(this);
        }
Exemple #21
0
        public async Task GuildDeleteVoiceChannel([Remainder] string name)
        {
            stopWatch.Start();
            foreach (var VoiceChannel in Context.Guild.VoiceChannels)
            {
                if (VoiceChannel.Name == name)
                {
                    await VoiceChannel.DeleteAsync();

                    embed.WithTitle("Voice Channel Deleted");
                    embed.WithDescription($"{Context.User.Mention} Successfully deleted the voice channel `{VoiceChannel.Name}`!");
                    embed.WithColor(Pink);
                    await BE(); stopWatch.Stop();
                    logger.ConsoleCommandLog(Context, stopWatch.ElapsedMilliseconds);
                }
            }
        }
        public static void TestAndRemoveTemporaryChannels()
        {
            foreach (var pair in allVoiceChannels)
            {
                VoiceChannel voiceChannel = pair.Value;

                if (voiceChannel.lifeTime.Ticks > 0)
                {
                    if (voiceChannel.creationTime.Add(voiceChannel.lifeTime) < DateTime.Now && Utility.ForceGetUsers(voiceChannel.id).Count == 0)
                    {
                        defaultChannels.Remove(voiceChannel.id);
                        allVoiceChannels.Remove(voiceChannel.id);
                        voiceChannel.GetChannel().DeleteAsync();
                        return;
                    }
                }
            }
        }
        public void LoadConfiguration()
        {
            ResetData();
            extraChannelNames      = BotConfiguration.GetSetting <string []> ("Voice.ExtraChannelNames", this, new string [] { "EXTRA_CHANNEL_1;EXTRA_CHANNEL_SHORT_NAME_1", "EXTRA_CHANNEL_1;EXTRA_CHANNEL_SHORT_NAME_2" });
            loadedChannels         = BotConfiguration.GetSetting("Voice.DefaultChannels", this, new VoiceChannel [] { new VoiceChannel(0, "DEFAULT_CHANNEL_NAME_1;SHORT_NAME_1", 0), new VoiceChannel(1, "DEFAULT_CHANNEL_NAME_2;SHORT_NAME_2", 0) });
            afkChannel             = BotConfiguration.GetSetting("Voice.AFKChannel", this, new VoiceChannel(2, "AFK_CHANNEL_NAME", int.MaxValue - 1));
            autoAddChannels        = BotConfiguration.GetSetting("Voice.AutoAddChannels", this, autoAddChannels);
            autoRenameChannels     = BotConfiguration.GetSetting("Voice.AutoRenameChannels", this, autoRenameChannels);
            shortenChannelNames    = BotConfiguration.GetSetting("Voice.ShortenChannelNames", this, shortenChannelNames);
            enableVoiceChannelTags = BotConfiguration.GetSetting("Voice.ChannelTagsEnabled", this, enableVoiceChannelTags);
            younglingRoleID        = BotConfiguration.GetSetting("Roles.YounglingID", this, younglingRoleID);
            internationalRoleID    = BotConfiguration.GetSetting("Roles.InternationalID", this, internationalRoleID);
            musicBotID             = BotConfiguration.GetSetting("Misc.MusicBotID", this, musicBotID);
            postRebootChannelName  = BotConfiguration.GetSetting("Voice.PostRebootChannelName", this, postRebootChannelName);
            randomizeNameQueue     = BotConfiguration.GetSetting("Voice.RandomizeNameQueue", this, randomizeNameQueue);

            gameNameReplacements.Add("Game name 1", "Game name replacement 1");
            gameNameReplacements.Add("Game name 2", "Game name replacement 2");
            gameNameReplacements = BotConfiguration.GetSetting("Voice.GameNameReplacements", this, gameNameReplacements);

            foreach (VoiceChannelTag tag in voiceChannelTags)
            {
                tag.enabled  = BotConfiguration.GetSetting("Voice.Tags." + tag.name + ".Enabled", this, tag.enabled);
                tag.tagEmoji = BotConfiguration.GetSetting("Voice.Tags." + tag.name + ".Emoji", this, tag.tagEmoji);
            }

            foreach (VoiceChannel channel in loadedChannels)
            {
                AddDefaultChannel(channel);
            }
            addChannelsIndex = defaultChannels.Count;
            AddDefaultChannel(afkChannel);

            for (int i = 0; i < extraChannelNames.Length; i++)
            {
                nameQueue.Add(extraChannelNames [i], false);
            }
        }
        public static async Task UpdateVoiceChannel(SocketVoiceChannel voice)
        {
            Game highestGame = new Game("", "", StreamType.NotStreaming);

            if (voice != null && allVoiceChannels.ContainsKey(voice.Id))
            {
                VoiceChannel           voiceChannel = allVoiceChannels [voice.Id];
                List <SocketGuildUser> users        = Utility.ForceGetUsers(voice.Id);

                if (voiceChannel.ignore)
                {
                    return;
                }

                if (voice.Users.Count() == 0)
                {
                    voiceChannel.Reset();
                }
                else
                {
                    if (voiceChannel.desiredMembers > 0)
                    {
                        if (users.Count >= voiceChannel.desiredMembers)
                        {
                            voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Full, false);
                        }
                        else
                        {
                            voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Looking, false);
                        }
                    }
                }

                Dictionary <Game, int> numPlayers = new Dictionary <Game, int> ();
                foreach (SocketGuildUser user in users)
                {
                    if (UserConfiguration.GetSetting <bool> (user.Id, "AutoLooking") && users.Count == 1)
                    {
                        voiceChannel.SetStatus(VoiceChannel.VoiceChannelStatus.Looking, false);
                    }

                    if (user.Game.HasValue && user.IsBot == false)
                    {
                        if (numPlayers.ContainsKey(user.Game.Value))
                        {
                            numPlayers [user.Game.Value]++;
                        }
                        else
                        {
                            numPlayers.Add(user.Game.Value, 1);
                        }
                    }
                }

                int highest = int.MinValue;

                for (int i = 0; i < numPlayers.Count; i++)
                {
                    KeyValuePair <Game, int> value = numPlayers.ElementAt(i);

                    if (value.Value > highest)
                    {
                        highest     = value.Value;
                        highestGame = value.Key;
                    }
                }

                if (enableVoiceChannelTags)
                {
                    GetTags(voiceChannel);
                }

                string tagsString = "";
                foreach (VoiceChannelTag tag in voiceChannel.currentTags)
                {
                    tagsString += tag.tagEmoji;
                }
                tagsString += tagsString.Length > 0 ? " " : "";

                string [] splitVoice      = voiceChannel.name.Split(';');
                string    possibleShorten = shortenChannelNames && splitVoice.Length > 1 ? splitVoice [1] : splitVoice [0];
                int       mixedLimit      = highest >= 2 ? 2 : Utility.ForceGetUsers(voice.Id).Count == 1 ? int.MaxValue : 1;                                                                                                         // Nested compact if statements? What could go wrong!

                string gameName = numPlayers.Where(x => x.Value >= mixedLimit).Count() > mixedLimit ? "Mixed Games" : gameNameReplacements.ContainsKey(highestGame.Name) ? gameNameReplacements[highestGame.Name] : highestGame.Name; // What even is this

                string newName;
                if (autoRenameChannels)
                {
                    newName = gameName != "" ? tagsString + possibleShorten + " - " + gameName : tagsString + splitVoice [0];
                }
                else
                {
                    newName = tagsString + splitVoice [0];
                }

                if (voiceChannel.customName != "")
                {
                    newName = tagsString + possibleShorten + " - " + voiceChannel.customName;
                }

                // Trying to optimize API calls here, just to spare those poor souls at the Discord API HQ stuff
                if (voice.Name != newName)
                {
                    Logging.Log(Logging.LogType.BOT, "Channel name updated: " + newName);
                    await voice.ModifyAsync((delegate(VoiceChannelProperties properties) {
                        properties.Name = newName;
                    }));
                }
                voiceChannel.CheckLocker();
            }
        }
Exemple #25
0
        private static void DuplicateChannels(Guild targetGuild, Guild ourGuild, List <RoleDupe> ourRoles)
        {
            OrganizedChannelList channels = new OrganizedChannelList(targetGuild.GetChannels());

            Console.WriteLine("Duplicating categories...");

            //duplicate category channels
            List <CategoryDupe> ourCategories = new List <CategoryDupe>();

            foreach (var category in channels.Categories)
            {
                //create the category
                GuildChannel ourCategory = ourGuild.CreateChannel(category.Name, ChannelType.Category);
                ourCategory.Modify(new GuildChannelProperties()
                {
                    Position = category.Position
                });

                foreach (var overwrite in category.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourCategory.AddPermissionOverwrite(ourOverwrite);
                }

                CategoryDupe dupe = new CategoryDupe
                {
                    TargetCategory = category,
                    OurCategory    = ourCategory
                };
                ourCategories.Add(dupe);

                Console.WriteLine($"Duplicated {category.Name}");
            }

            Console.WriteLine("Duplicating channels...");

            //duplicate text channels
            foreach (var c in channels.TextChannels)
            {
                TextChannel channel = c.ToTextChannel();

                TextChannel ourChannel = ourGuild.CreateChannel(channel.Name, ChannelType.Text, channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null).ToTextChannel();
                ourChannel.Modify(new TextChannelProperties()
                {
                    Nsfw = channel.Nsfw, Position = channel.Position, Topic = channel.Topic, SlowMode = channel.SlowMode
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");
            }

            //duplicate voice channels
            foreach (var channel in channels.VoiceChannels)
            {
                //create voice channels
                VoiceChannel ourChannel = ourGuild.CreateChannel(channel.Name, ChannelType.Voice, channel.ParentId != null ? (ulong?)ourCategories.First(ca => ca.TargetCategory.Id == channel.ParentId).OurCategory.Id : null).ToVoiceChannel();
                ourChannel.Modify(new VoiceChannelProperties()
                {
                    Bitrate = channel.Bitrate, Position = channel.Position, UserLimit = channel.UserLimit
                });

                foreach (var overwrite in channel.PermissionOverwrites)
                {
                    if (overwrite.Type == PermissionOverwriteType.Member)
                    {
                        continue;
                    }

                    DiscordPermissionOverwrite ourOverwrite = overwrite;
                    ourOverwrite.Id = ourRoles.First(ro => ro.TargetRole.Id == overwrite.Id).OurRole.Id;
                    ourChannel.AddPermissionOverwrite(ourOverwrite);
                }

                Console.WriteLine($"Duplicated {channel.Name}");
            }
        }
Exemple #26
0
 public static Task LeaveAudio(this VoiceChannel channel) => channel.Client.GetService <AudioService>().Leave(channel);
Exemple #27
0
 public static Task <IAudioClient> JoinAudio(this VoiceChannel channel) => channel.Client.GetService <AudioService>().Join(channel);
 public Task Join(VoiceChannel channel) => _client.Join(channel);
 public ActionData(VoiceChannel c)
 {
     channel = c;
 }
 public static void AddTemporaryChannel(ulong id, VoiceChannel newVoice)
 {
     defaultChannels.Add(id, newVoice);
     allVoiceChannels.Add(id, newVoice);
 }