Ejemplo n.º 1
0
 public void QueueChatMessage(string message)
 {
     if (ChatHandler.Connected)
     {
         ChatHandler.Send($"{RequestBotConfig.Instance.BotPrefix}\uFEFF{message}");
     }
     //else
     //{
     //    Plugin.Log($"Message sent before twitch connected! \"{message}\"");
     //}
 }
Ejemplo n.º 2
0
// if (!silence) QueueChatMessage($"{request.Key.song["songName"].Value}/{request.Key.song["authorName"].Value} ({songId}) added to the blacklist.");
        private void SendChatMessage(string message)
        {
            try
            {
                Plugin.Log($"Sending message: \"{message}\"");
                //TwitchWebSocketClient.SendMessage($"PRIVMSG #{TwitchLoginConfig.Instance.TwitchChannelName} :{message}");
                ChatHandler.Send(message);
                //TwitchMessage tmpMessage = new TwitchMessage();
                //tmpMessage.Sender = ChatHandler.Self;
                //MessageParser.Parse(new ChatMessage(message, tmpMessage)); // This call is obsolete, when sending a message through TwitchWebSocketClient, the message should automatically appear in chat.
            }
            catch (Exception e)
            {
                Plugin.Log($"Exception was caught when trying to send bot message. {e.ToString()}");
            }
        }
Ejemplo n.º 3
0
        public void Enter(KEY key)
        {
            var typedtext = key.kb.KeyboardText.text;

            if (typedtext != "")
            {
                if (RequestBot.COMMAND.aliaslist.ContainsKey(RequestBot.ParseState.GetCommand(ref typedtext)))
                {
                    RequestBot.COMMAND.Parse(ChatHandler.Self, typedtext, RequestBot.CmdFlags.Local);
                }
                else
                {
                    ChatHandler.Send(typedtext, typedtext.StartsWith("/"));
                }

                key.kb.KeyboardText.text = "";
            }
        }
Ejemplo n.º 4
0
        private static async void ProcessSongRequest(int index, bool fromHistory = false)
        {
            if ((RequestQueue.Songs.Count > 0 && !fromHistory) || (RequestHistory.Songs.Count > 0 && fromHistory))
            {
                SongRequest request = null;
                if (!fromHistory)
                {
                    SetRequestStatus(index, RequestStatus.Played);
                    request = DequeueRequest(index);
                }
                else
                {
                    request = RequestHistory.Songs.ElementAt(index);
                }

                if (request == null)
                {
                    Plugin.Log("Can't process a null request! Aborting!");
                    return;
                }
                else
                {
                    Plugin.Log($"Processing song request {request.song["songName"].Value}");
                }


                string songName  = request.song["songName"].Value;
                string songIndex = $"{request.song["id"].Value} ({request.song["songName"].Value} - {request.song["levelAuthor"].Value})";
                songIndex = normalize.RemoveDirectorySymbols(ref songIndex); // Remove invalid characters.

                string currentSongDirectory = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data\\CustomLevels", songIndex);
                string songHash             = request.song["hash"].Value.ToUpper();


                // Check to see if level exists, download if not.

                // Replace with level check.
                //CustomLevel[] levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();
                //if (levels.Length == 0)

                var  rat       = SongCore.Collections.levelIDsForHash(songHash);
                bool mapexists = (rat.Count > 0) && (rat[0] != "");


                if (!SongCore.Loader.CustomLevels.ContainsKey(currentSongDirectory) && !mapexists)
                {
                    EmptyDirectory(".requestcache", false);


                    //SongMap map;
                    //if (MapDatabase.MapLibrary.TryGetValue(songIndex, out map))
                    //{
                    //    if (map.path != "")
                    //    {
                    //        songIndex = map.song["version"].Value;
                    //        songName = map.song["songName"].Value;
                    //        currentSongDirectory = Path.Combine(Environment.CurrentDirectory, "CustomSongs", songIndex);
                    //        songHash = map.song["hashMd5"].Value.ToUpper();

                    //        Directory.CreateDirectory(currentSongDirectory);
                    //        // HACK to allow playing alternate songs not in custom song directory
                    //        CopyFilesRecursively(new DirectoryInfo(map.path),new DirectoryInfo( currentSongDirectory));

                    //        goto here;
                    //    }
                    //}

                    //Plugin.Log("Downloading");

                    if (Directory.Exists(currentSongDirectory))
                    {
                        EmptyDirectory(currentSongDirectory, true);
                        Plugin.Log($"Deleting {currentSongDirectory}");
                    }

                    string localPath = Path.Combine(Environment.CurrentDirectory, ".requestcache", $"{request.song["id"].Value}.zip");
                    //string dl = $"https://beatsaver.com {request.song["downloadURL"].Value}";
                    //Instance.QueueChatMessage($"Download url: {dl}, {request.song}");



                    // Insert code to replace local path with ZIP path here
                    //SongMap map;
                    //if (MapDatabase.MapLibrary.TryGetValue(songIndex, out map))
                    //{
                    //    if (map.path != "")
                    //    {
                    //        songIndex = map.song["version"].Value;
                    //        songName = map.song["songName"].Value;
                    //        currentSongDirectory = Path.Combine(Environment.CurrentDirectory, "CustomSongs", songIndex);
                    //        songHash = map.song["hashMd5"].Value.ToUpper();

                    //        Directory.CreateDirectory(currentSongDirectory);
                    //        // HACK to allow playing alternate songs not in custom song directory
                    //        CopyFilesRecursively(new DirectoryInfo(map.path),new DirectoryInfo( currentSongDirectory));

                    //        goto here;
                    //    }
                    //}


#if UNRELEASED
                    // Direct download hack
                    var ext = Path.GetExtension(request.song["coverURL"].Value);
                    var k   = request.song["coverURL"].Value.Replace(ext, ".zip");

                    var songZip = await Plugin.WebClient.DownloadSong($"https://beatsaver.com{k}", System.Threading.CancellationToken.None);
#else
                    var songZip = await Plugin.WebClient.DownloadSong($"https://beatsaver.com{request.song["downloadURL"].Value}", System.Threading.CancellationToken.None);
#endif

                    Stream zipStream = new MemoryStream(songZip);
                    try
                    {
                        // open zip archive from memory stream
                        ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Read);
                        archive.ExtractToDirectory(currentSongDirectory);
                        archive.Dispose();
                    }
                    catch (Exception e)
                    {
                        Plugin.Log($"Unable to extract ZIP! Exception: {e}");
                        return;
                    }
                    zipStream.Close();

here:

                    await Task.Run(async() =>
                    {
                        while (!SongCore.Loader.AreSongsLoaded && SongCore.Loader.AreSongsLoading)
                        {
                            await Task.Delay(25);
                        }
                    });

                    Loader.Instance.RefreshSongs();

                    await Task.Run(async() =>
                    {
                        while (!SongCore.Loader.AreSongsLoaded && SongCore.Loader.AreSongsLoading)
                        {
                            await Task.Delay(25);
                        }
                    });

                    EmptyDirectory(".requestcache", true);
                    //levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();
                }
                else
                {
                    //Instance.QueueChatMessage($"Directory exists: {currentSongDirectory}");

                    Plugin.Log($"Song {songName} already exists!");
                }

                // Dismiss the song request viewcontroller now
                //_songRequestMenu.Dismiss();
                _flowCoordinator.Dismiss();

                if (true)
                {
                    //Plugin.Log($"Scrolling to level {levels[0].levelID}");

                    bool success = false;

                    Dispatcher.RunCoroutine(SongListUtils.ScrollToLevel(request.song["hash"].Value.ToUpper(), (s) => success = s, false));

                    // Redownload the song if we failed to scroll to it
                }
                else
                {
                    Plugin.Log("Failed to find new level!");
                }

                if (!request.song.IsNull && RequestBotConfig.Instance.SendNextSongBeingPlayedtoChat)
                {
                    new DynamicText().AddUser(ref request.requestor).AddSong(request.song).QueueMessage(NextSonglink.ToString()); // Display next song message
                }

                #if UNRELEASED
                if (!request.song.IsNull) // Experimental!
                {
                    ChatHandler.Send("marker " + new DynamicText().AddUser(ref request.requestor).AddSong(request.song).Parse(NextSonglink.ToString()), true);
                }
                #endif
            }
        }