void HandMessage(MatrixRoom uroom, MatrixEvent evt) { if (GameInSession) { string data = ((MatrixMRoomMessage)evt.content).body; if (data.ToLower() == "hand") { SendDeckUpdate(evt.sender); return; } if (users[currentPlayer].UserID == evt.sender) { //Do hand stuff string[] cards = data.ToUpper().Trim().Split(' '); if (cards.Length > 4) { uroom.SendNotice("Dude, think it over. How can you have more than 4 cards of the same value?"); return; } List <PlayingCard> outdeck = new List <PlayingCard>(); foreach (string scard in cards) { PlayingCard card; if (!PlayingCard.TryParse(scard, out card)) { uroom.SendNotice("I could not recognise all the cards there, please revise."); return; } outdeck.Add(card); } List <PlayingCard> player_hand = hands[evt.sender]; bool all = outdeck.All(x => player_hand.Any(y => (x.suit == y.suit && x.value == y.value))); if (all) { room.SendNotice(users[currentPlayer].DisplayName + " has put forward " + outdeck.Count + " cards. They have " + (player_hand.Count - outdeck.Count) + " cards remaining"); playerLied = !outdeck.All(x => x.value == expectedValue); deck.AddRange(outdeck); CheckForWinner(); foreach (PlayingCard card in outdeck) { player_hand.RemoveAll(x => x.suit == card.suit && x.value == card.value); } NextTurn(); } else { uroom.SendNotice("Some of the cards you listed aren't in your hand, please revise."); } } } else { room.LeaveRoom(); } }
public static void DownloadTrack(string cmd, string sender, MatrixRoom room) { try { List <string[]> videos = new List <string[]>(); if (Downloaders.YoutubeGetIDFromURL(cmd) != "") { videos = DownloadYoutube(cmd, sender, room); } else if (Uri.IsWellFormedUriString(cmd, UriKind.Absolute)) { videos = new List <string[]>(); videos.Add(DownloadGeneric(cmd, sender, room)); } else { room.SendNotice("Sorry, that type of URL isn't supported right now :/"); return; } Program.MPCClient.RequestLibraryUpdate(); //Program.MPCClient.Idle("update");//Wait for it to start Program.MPCClient.Idle("update"); //Wait for it to finish foreach (string[] res in videos) { Program.MPCClient.AddFile(res[0]); } Program.MPCClient.Status(); #if DEBUG Console.WriteLine(JObject.FromObject(Program.MPCClient.lastStatus)); #endif int position = Program.MPCClient.lastStatus.playlistlength; if (position == 1) { Program.MPCClient.Play(); room.SendNotice("Started playing " + videos[0][1] + " | " + Configuration.Config["mpc"]["streamurl"]); } else { room.SendNotice(videos[0][1] + " has been queued at position " + position + "."); } } catch (Exception e) { room.SendNotice("There was an issue with that request, " + sender + ": " + e.Message); Console.Error.WriteLine(e); } }
public static void LyricSearch(string cmd, string sender, MatrixRoom room) { string suggestion = Downloaders.GetSongNameByLyric(cmd.Replace("lyrics ", "")); if (suggestion == null) { room.SendNotice("I couldn't find any songs with that lyric :("); } else { room.SendNotice(String.Format("Matched '{0}'. Checking Youtube for it", suggestion)); SearchYTForTrack("search " + suggestion, sender, room); } }
public static void PlaylistDisplay(string cmd, string sender, MatrixRoom room) { string[] files = Program.MPCClient.Playlist(); string output = "▶ "; if (files.Length > 0) { for (int i = 0; i < files.Length; i++) { if (i > 4) { break; } string file = files [i].Substring(0, files [i].Length - 4) + '\n'; //Remove the extension file = new string(System.Text.Encoding.UTF8.GetChars(Convert.FromBase64String(file))); output += file + "\n"; } room.SendMessage(output); } else { room.SendNotice("The playlist is empty"); } }
public static void SearchYTForTrack(string cmd, string sender, MatrixRoom room) { string query = cmd.Replace("search ", ""); if (string.IsNullOrWhiteSpace(query)) { return; } try { string url = Downloaders.GetYoutubeURLFromSearch(query); if (url != null) { DownloadTrack(url, sender, room); } else { throw new Exception("No videos matching those terms were found"); } } catch (Exception e) { room.SendNotice("There was an issue with that request, " + sender + ": " + e.Message); Console.Error.WriteLine(e); } }
public override void GameStart() { playerLied = false; currentPlayer = 0; lastPlayer = -1; expectedValue = 2; base.GameStart(); //Dish out cards to players deck = PlayingCard.GetStandardDeck(); PlayingCard.ShuffleDeck(ref deck); hands = new Dictionary <string, List <PlayingCard> >(); user_rooms = new Dictionary <string, MatrixRoom>(); foreach (MatrixUser user in users) { hands.Add(user.UserID, new List <PlayingCard>()); } int i = 0; while (deck.Count > 0) { hands[users[i].UserID].Add(deck[0]); deck.RemoveAt(0); i = (i + 1) % users.Count; } foreach (KeyValuePair <string, List <PlayingCard> > deck in hands) { //Create a room and send the player their cards. Console.WriteLine(deck.Key + "'s hand:" + string.Join <PlayingCard>(" ", deck.Value)); MatrixRoom uroom = client.CreateRoom(new MatrixCreateRoom() { invite = new string[1] { deck.Key }, name = "[Card:Hand] Hand for Cheat Lobby", topic = "This room will pass you information", visibility = EMatrixCreateRoomVisibility.Private }); user_rooms.Add(deck.Key, uroom); SendDeckUpdate(deck.Key); uroom.SendNotice("To play a card, type [H,D,S,C] [2-10,J,Q,K,A] in your **private room**. You may type multiple cards seperated by a space."); uroom.SendNotice("To to check your hand, type 'hand'."); uroom.OnMessage += HandMessage; string name = (users.First(x => x.UserID == deck.Key)).DisplayName; } }
public static void GetSongName(string cmd, string sender, MatrixRoom room) { MPCCurrentSong song = Program.MPCClient.CurrentSong(); Program.MPCClient.Status(); if (song.file != null) { FileInfo file = new FileInfo(song.file); string name = file.Name.Replace(file.Extension, ""); name = new string(System.Text.Encoding.UTF8.GetChars(Convert.FromBase64String(name))); string[] time = Program.MPCClient.lastStatus.time.Split(':'); int elapsed = int.Parse(time[0]); int total = int.Parse(time[1]); name += String.Format(" {0}:{1}/{2}:{3}", elapsed / 60, elapsed % 60, total / 60, total % 60); room.SendNotice(name); } else { room.SendNotice("Nothing is currently playing"); } }
public static void StreamUrl(string cmd, string sender, MatrixRoom room) { room.SendNotice(Configuration.Config["mpc"]["streamurl"]); }