public async Task HandleMoved(SocketUser user, SocketVoiceChannel newChannel, SocketVoiceChannel oldChannel)
        {
            EmbedFieldBuilder previousPlaybackField = null;

            // Remove user from old channel's playback session
            await _synthbotRestClient.RemoveUserFromChannel(oldChannel.Name);

            // Get user status
            var status = await GetDiscordUserStatus(user.Id);

            if (status == DiscordUserStatus.RegisteredWithNotify)
            {
                var oldPlayback = await _synthbotRestClient.GetCurrentPlayback(oldChannel.Name);

                FullPlaylist oldPlaylist = null;
                if (oldPlayback != null)
                {
                    oldPlaylist = _spotifyInfoService.GetFullPlaylist(oldPlayback.SpotifyPlaylistId);
                }
                if (oldPlaylist != null)
                {
                    previousPlaybackField = EmbedFactory.Notifications.PreviousPlaybackField(oldChannel, oldPlaylist);
                }
            }

            var synthbotUser = await GetSynthbotUserIfExists(user.Id.ToString(), status);

            var playlist = await GetPlaylist(newChannel.Name);

            // Start playback on new channel if auto-join is on
            if (synthbotUser?.AutoJoin ?? false)
            {
                await _synthbotRestClient.AddUserToChannel(newChannel.Name);

                if (status == DiscordUserStatus.RegisteredWithNotify)
                {
                    await user.SendMessageAsync("", false, EmbedFactory.Notifications.AutoJoinNotify(_discord.CurrentUser, newChannel, playlist, previousPlaybackField));
                }
            }
            else
            {
                if (status == DiscordUserStatus.RegisteredWithNotify)
                {
                    await user.SendMessageAsync("", false, EmbedFactory.Notifications.Notify(_discord.CurrentUser, newChannel, playlist, previousPlaybackField));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task LeaveChannel(string overrideChannelName = null)
        {
            var channelName = await GetUserVoiceChannelName(overrideChannelName);

            if (string.IsNullOrWhiteSpace(channelName))
            {
                return;
            }

            var result = await _synthbotWebClient.RemoveUserFromChannel(channelName);

            if (result == true)
            {
                await Context.Channel.SendMessageAsync("", false, EmbedFactory.Leave.LeaveTrue(Context, channelName));
            }
            else
            {
                await Context.Channel.SendMessageAsync("", false, EmbedFactory.Leave.LeaveFailed(Context, channelName));
            }
        }