public void QueueChatMessage(string message) { if (ChatHandler.Connected) { ChatHandler.Send($"{RequestBotConfig.Instance.BotPrefix}\uFEFF{message}"); } //else //{ // Plugin.Log($"Message sent before twitch connected! \"{message}\""); //} }
// 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()}"); } }
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 = ""; } }
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 } }
protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { if (firstActivation) { if (!SongCore.Loader.AreSongsLoaded) { SongCore.Loader.SongsLoadedEvent += SongLoader_SongsLoadedEvent; } Plugin.Log("DidActivate 001"); // get table cell instance _requestListTableCellInstance = Resources.FindObjectsOfTypeAll <LevelListTableCell>().First((LevelListTableCell x) => x.name == "LevelListTableCell"); // initialize Yes/No modal YesNoModal.instance.Setup(); Plugin.Log("DidActivate 002"); _songPreviewPlayer = Resources.FindObjectsOfTypeAll <SongPreviewPlayer>().FirstOrDefault(); RectTransform container = new GameObject("RequestBotContainer", typeof(RectTransform)).transform as RectTransform; container.SetParent(rectTransform, false); #region TableView Setup and Initialization var go = new GameObject("SongRequestTableView", typeof(RectTransform)); go.SetActive(false); go.AddComponent <ScrollRect>(); go.AddComponent <Touchable>(); go.AddComponent <EventSystemListener>(); ScrollView scrollView = go.AddComponent <ScrollView>(); _songListTableView = go.AddComponent <TableView>(); go.AddComponent <RectMask2D>(); _songListTableView.transform.SetParent(container, false); _songListTableView.SetField("_preallocatedCells", new TableView.CellsGroup[0]); _songListTableView.SetField("_isInitialized", false); _songListTableView.SetField("_scrollView", scrollView); var viewport = new GameObject("Viewport").AddComponent <RectTransform>(); viewport.SetParent(go.GetComponent <RectTransform>(), false); go.GetComponent <ScrollRect>().viewport = viewport; (viewport.transform as RectTransform).sizeDelta = new Vector2(70f, 70f); RectTransform content = new GameObject("Content").AddComponent <RectTransform>(); content.SetParent(viewport, false); scrollView.SetField("_contentRectTransform", content); scrollView.SetField("_viewport", viewport); _songListTableView.SetDataSource(this, false); _songListTableView.LazyInit(); go.SetActive(true); (_songListTableView.transform as RectTransform).sizeDelta = new Vector2(70f, 70f); (_songListTableView.transform as RectTransform).anchoredPosition = new Vector2(3f, 0f); _songListTableView.didSelectCellWithIdxEvent += DidSelectRow; _pageUpButton = UIHelper.CreateUIButton("SRMPageUpButton", container, "PracticeButton", new Vector2(0f, 38.5f), new Vector2(15f, 7f), () => { scrollView.PageUpButtonPressed(); }, "˄"); Destroy(_pageUpButton.GetComponentsInChildren <ImageView>().FirstOrDefault(x => x.name == "Underline")); _pageDownButton = UIHelper.CreateUIButton("SRMPageDownButton", container, "PracticeButton", new Vector2(0f, -38.5f), new Vector2(15f, 7f), () => { scrollView.PageDownButtonPressed(); }, "˅"); Destroy(_pageDownButton.GetComponentsInChildren <ImageView>().FirstOrDefault(x => x.name == "Underline")); #endregion CenterKeys = new KEYBOARD(container, "", false, -15, 15); #if UNRELEASED // BUG: Need additional modes disabling one shot buttons // BUG: Need to make sure the buttons are usable on older headsets Plugin.Log("DidActivate 005"); _CurrentSongName = BeatSaberUI.CreateText(container, "", new Vector2(-35, 37f)); _CurrentSongName.fontSize = 3f; _CurrentSongName.color = Color.cyan; _CurrentSongName.alignment = TextAlignmentOptions.Left; _CurrentSongName.enableWordWrapping = false; _CurrentSongName.text = ""; _CurrentSongName2 = BeatSaberUI.CreateText(container, "", new Vector2(-35, 34f)); _CurrentSongName2.fontSize = 3f; _CurrentSongName2.color = Color.cyan; _CurrentSongName2.alignment = TextAlignmentOptions.Left; _CurrentSongName2.enableWordWrapping = false; _CurrentSongName2.text = ""; //CenterKeys.AddKeys(SONGLISTKEY); if (!RequestBot.AddKeyboard(CenterKeys, "mainpanel.kbd")) { CenterKeys.AddKeys(SONGLISTKEY); } ColorDeckButtons(CenterKeys, Color.white, Color.magenta); #endif RequestBot.AddKeyboard(CenterKeys, "CenterPanel.kbd"); CenterKeys.DefaultActions(); #region History button // History button _historyButton = UIHelper.CreateUIButton("SRMHistory", container, "PracticeButton", new Vector2(53f, 30f), new Vector2(25f, 15f), () => { isShowingHistory = !isShowingHistory; RequestBot.SetTitle(isShowingHistory ? "Song Request History" : "Song Request Queue"); if (NumberOfCells() > 0) { _songListTableView.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false); _songListTableView.SelectCellWithIdx(0); _selectedRow = 0; } else { _selectedRow = -1; } UpdateRequestUI(true); SetUIInteractivity(); _lastSelection = -1; }, "History"); _historyButton.ToggleWordWrapping(false); _historyHintText = UIHelper.AddHintText(_historyButton.transform as RectTransform, ""); #endregion #region Blacklist button // Blacklist button _blacklistButton = UIHelper.CreateUIButton("SRMBlacklist", container, "PracticeButton", new Vector2(53f, 10f), new Vector2(25f, 15f), () => { if (NumberOfCells() > 0) { void _onConfirm() { RequestBot.Blacklist(_selectedRow, isShowingHistory, true); if (_selectedRow > 0) { _selectedRow--; } confirmDialogActive = false; } // get song var song = SongInfoForRow(_selectedRow).song; // indicate dialog is active confirmDialogActive = true; // show dialog YesNoModal.instance.ShowDialog("Blacklist Song Warning", $"Blacklisting {song["songName"].Value} by {song["authorName"].Value}\r\nDo you want to continue?", _onConfirm, () => { confirmDialogActive = false; }); } }, "Blacklist"); _blacklistButton.ToggleWordWrapping(false); UIHelper.AddHintText(_blacklistButton.transform as RectTransform, "Block the selected request from being queued in the future."); #endregion #region Skip button // Skip button _skipButton = UIHelper.CreateUIButton("SRMSkip", container, "PracticeButton", new Vector2(53f, 0f), new Vector2(25f, 15f), () => { if (NumberOfCells() > 0) { // get song var song = SongInfoForRow(_selectedRow).song; void _onConfirm() { // get selected song currentsong = SongInfoForRow(_selectedRow); // skip it RequestBot.Skip(_selectedRow); // select previous song if not first song if (_selectedRow > 0) { _selectedRow--; } // indicate dialog is no longer active confirmDialogActive = false; } // indicate dialog is active confirmDialogActive = true; // show dialog YesNoModal.instance.ShowDialog("Skip Song Warning", $"Skipping {song["songName"].Value} by {song["authorName"].Value}\r\nDo you want to continue?", _onConfirm, () => { confirmDialogActive = false; }); } }, "Skip"); _skipButton.ToggleWordWrapping(false); UIHelper.AddHintText(_skipButton.transform as RectTransform, "Remove the selected request from the queue."); #endregion #region Play button // Play button _playButton = UIHelper.CreateUIButton("SRMPlay", container, "ActionButton", new Vector2(53f, -10f), new Vector2(25f, 15f), () => { if (NumberOfCells() > 0) { currentsong = SongInfoForRow(_selectedRow); RequestBot.played.Add(currentsong.song); RequestBot.WriteJSON(RequestBot.playedfilename, ref RequestBot.played); SetUIInteractivity(false); RequestBot.Process(_selectedRow, isShowingHistory); _selectedRow = -1; } }, "Play"); ((RectTransform)_playButton.transform).localScale = Vector3.one; _playButton.GetComponent <NoTransitionsButton>().enabled = true; _playButton.ToggleWordWrapping(false); _playButton.interactable = ((isShowingHistory && RequestHistory.Songs.Count > 0) || (!isShowingHistory && RequestQueue.Songs.Count > 0)); UIHelper.AddHintText(_playButton.transform as RectTransform, "Download and scroll to the currently selected request."); #endregion #region Queue button // Queue button _queueButton = UIHelper.CreateUIButton("SRMQueue", container, "PracticeButton", new Vector2(53f, -30f), new Vector2(25f, 15f), () => { RequestBotConfig.Instance.RequestQueueOpen = !RequestBotConfig.Instance.RequestQueueOpen; RequestBotConfig.Instance.Save(); RequestBot.WriteQueueStatusToFile(RequestBotConfig.Instance.RequestQueueOpen ? "Queue is open." : "Queue is closed."); RequestBot.Instance.QueueChatMessage(RequestBotConfig.Instance.RequestQueueOpen ? "Queue is open." : "Queue is closed."); UpdateRequestUI(); }, RequestBotConfig.Instance.RequestQueueOpen ? "Queue Open" : "Queue Closed"); _queueButton.ToggleWordWrapping(true); _queueButton.SetButtonUnderlineColor(RequestBotConfig.Instance.RequestQueueOpen ? Color.green : Color.red); _queueButton.SetButtonTextSize(3.5f); UIHelper.AddHintText(_queueButton.transform as RectTransform, "Open/Close the queue."); #endregion #region Websocket Connect Button // Websocket Connect button _websocketConnectButton = UIHelper.CreateUIButton("WSConnect", container, "PracticeButton", new Vector2(53f, -20f), new Vector2(25f, 15f), () => { ChatHandler.WebsocketHandlerConnect(); }, "Connect WS"); _websocketConnectButton.ToggleWordWrapping(true); _websocketConnectButton.SetButtonUnderlineColor(Color.red); _websocketConnectButton.SetButtonTextSize(3.5f); UIHelper.AddHintText(_websocketConnectButton.transform as RectTransform, "Connects the Websocket"); #endregion // Set default RequestFlowCoordinator title RequestBot.SetTitle(isShowingHistory ? "Song Request History" : "Song Request Queue"); } base.DidActivate(firstActivation, addedToHierarchy, screenSystemEnabling); if (addedToHierarchy) { _selectedRow = -1; _songListTableView.ClearSelection(); } UpdateRequestUI(); SetUIInteractivity(true); }