private async void addToBlacklist(string search) { //Check if the string is empty if (string.IsNullOrEmpty(search)) { return; } // If the API is not connected just don't do anything? if (APIHandler.spotify == null) { MessageDialogResult msgResult = await this.ShowMessageAsync("Notification", "Spotify is not connected. You need to connect to Spotify in order to fill the blacklist.", MessageDialogStyle.Affirmative); return; } // Perform a search via the spotify API SpotifyAPI.Web.Models.SearchItem searchItem = APIHandler.GetArtist(search); if (searchItem.Artists.Items.Count <= 0) { return; } SpotifyAPI.Web.Models.FullArtist fullartist = searchItem.Artists.Items[0]; foreach (object item in ListView_Blacklist.Items) { if (item.ToString() == fullartist.Name) { return; } } ListView_Blacklist.Items.Add(fullartist.Name); SaveBlacklist(); }
private static void AddSong(string trackID, OnMessageReceivedArgs e) { // loads the blacklist from settings string[] Blacklist = Settings.ArtistBlacklist.Split(new[] { "|||" }, StringSplitOptions.None); string response; // gets the track information using spotify api FullTrack track = APIHandler.GetTrack(trackID); // checks if one of the artist in the requested song is on the blacklist foreach (string s in Blacklist) { if (Array.IndexOf(track.Artists.Select(x => x.Name).ToArray(), s) != -1) { // if artist is on blacklist, skip and inform requester response = Settings.Bot_Resp_Blacklist; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", s); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); response = CleanFormatString(response); _client.SendMessage(e.ChatMessage.Channel, response); return; } } // checks if song length is longer or equal to 10 minutes if (track.DurationMs >= TimeSpan.FromMinutes(10).TotalMilliseconds) { // if track length exceeds 10 minutes skip and inform requster response = Settings.Bot_Resp_Length; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); response = CleanFormatString(response); _client.SendMessage(e.ChatMessage.Channel, response); return; } // checks if the song is already in the queue if (isInQueue(track.Id)) { // if the song is already in the queue skip and inform requester response = Settings.Bot_Resp_IsInQueue; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); response = CleanFormatString(response); _client.SendMessage(e.ChatMessage.Channel, response); return; } // checks if the user has already the max amount of songs in the queue if (MaxQueueItems(e.ChatMessage.DisplayName)) { // if the user reached max requests in the queue skip and inform requester response = Settings.Bot_Resp_MaxReq; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", Settings.TwSRMaxReq.ToString()); response = response.Replace("{errormsg}", ""); response = CleanFormatString(response); _client.SendMessage(e.ChatMessage.Channel, response); return; } // generate the spotifyURI using the track id string SpotifyURI = "spotify:track:" + trackID; // try adding the song to the queue using the URI SpotifyAPI.Web.Models.ErrorResponse error = APIHandler.AddToQ(SpotifyURI); if (error.Error != null) { // if an error has been encountered, log it, inform the requester and skip Logger.LogStr(error.Error.Message + "\n" + error.Error.Status); response = Settings.Bot_Resp_Error; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", error.Error.Message); _client.SendMessage(e.ChatMessage.Channel, response); return; } // if everything workes so far, inform the user that the song has been added to the queue response = Settings.Bot_Resp_Success; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", track.Artists[0].Name); response = response.Replace("{title}", track.Name); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); _client.SendMessage(e.ChatMessage.Channel, response); // Upload the track and who requested it to the queue on the server UploadToQueue(track, e.ChatMessage.DisplayName); // Add the song to the internal queue and update the queue window if its open Application.Current.Dispatcher.Invoke(new Action(() => { Window mw = null, qw = null; foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(MainWindow)) { mw = window; } if (window.GetType() == typeof(Window_Queue)) { qw = window; } } if (mw != null) { (mw as MainWindow).ReqList.Add(new RequestObject { Requester = e.ChatMessage.DisplayName, TrackID = track.Id, Title = track.Name, Artists = track.Artists[0].Name, Length = FormattedTime(track.DurationMs) }); } if (qw != null) { //(qw as Window_Queue).dgv_Queue.ItemsSource. (qw as Window_Queue).dgv_Queue.Items.Refresh(); } })); }
private static void _client_OnMessageReceived(object sender, OnMessageReceivedArgs e) { if (Settings.MsgLoggingEnabled) { // If message logging is enabled and the reward was triggered, save it to the settings (if settings window is open, write it to the textbox) if (e.ChatMessage.CustomRewardId != null) { Settings.TwRewardID = e.ChatMessage.CustomRewardId; Application.Current.Dispatcher.Invoke(new Action(() => { foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(Window_Settings)) { (window as Window_Settings).txtbx_RewardID.Text = e.ChatMessage.CustomRewardId; } } })); } } // if the reward is the same with the desired reward for the requests if (Settings.TwSRReward && e.ChatMessage.CustomRewardId == Settings.TwRewardID) { if (IsUserBlocked(e.ChatMessage.DisplayName)) { _client.SendWhisper(e.ChatMessage.Username, "You are blocked from making Songrequests"); return; } if (APIHandler.spotify == null) { _client.SendMessage(e.ChatMessage.Channel, "It seems that Spotify is not connected right now."); return; } // if Spotify is connected and working manipulate the string and call methods to get the song info accordingly if (e.ChatMessage.Message.StartsWith("spotify:track:")) { // search for a track with the id string TrackID = e.ChatMessage.Message.Replace("spotify:track:", ""); // add the track to the spotify queue and pass the OnMessageReceivedArgs (contains user who requested the song etc) AddSong(TrackID, e); } else if (e.ChatMessage.Message.StartsWith("https://open.spotify.com/track/")) { string trackid = e.ChatMessage.Message.Replace("https://open.spotify.com/track/", ""); trackid = trackid.Split('?')[0]; AddSong(trackid, e); } else { // search for a track with a search string from chat SearchItem searchItem = APIHandler.FindTrack(e.ChatMessage.Message); if (searchItem.Tracks.Items.Count > 0) { // if a track was found convert the object to FullTrack (easier use than searchItem) FullTrack fullTrack = searchItem.Tracks.Items[0]; // add the track to the spotify queue and pass the OnMessageReceivedArgs (contains user who requested the song etc) AddSong(fullTrack.Id, e); } else { string response; // if no track has been found inform the requester response = Settings.Bot_Resp_Error; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); _client.SendMessage(e.ChatMessage.Channel, response); return; } } return; } // Same code from above but it reacts to a command instead of rewards if (Settings.TwSRCommand && e.ChatMessage.Message.StartsWith("!ssr")) { // Do nothing if the user is blocked, don't even reply if (IsUserBlocked(e.ChatMessage.DisplayName)) { _client.SendWhisper(e.ChatMessage.DisplayName, "You are blocked from making Songrequests"); return; } // if onCooldown skip if (onCooldown) { return; } if (APIHandler.spotify == null) { _client.SendMessage(e.ChatMessage.Channel, "It seems that Spotify is not connected right now."); return; } // if Spotify is connected and working manipulate the string and call methods to get the song info accordingly string[] msgSplit = e.ChatMessage.Message.Split(' '); // Prevent crash on command without args if (msgSplit.Length <= 1) { _client.SendMessage(e.ChatMessage.Channel, "@" + e.ChatMessage.DisplayName + " please specify a song to add to the queue."); StartCooldown(); return; } if (msgSplit[1].StartsWith("spotify:track:")) { // search for a track with the id string trackID = msgSplit[1].Replace("spotify:track:", ""); // add the track to the spotify queue and pass the OnMessageReceivedArgs (contains user who requested the song etc) AddSong(trackID, e); } else if (msgSplit[1].StartsWith("https://open.spotify.com/track/")) { string trackid = msgSplit[1].Replace("https://open.spotify.com/track/", ""); trackid = trackid.Split('?')[0]; AddSong(trackid, e); } else { string searchString = e.ChatMessage.Message.Replace("!ssr ", ""); // search for a track with a search string from chat SearchItem searchItem = APIHandler.FindTrack(searchString); if (searchItem.Tracks.Items.Count > 0) { // if a track was found convert the object to FullTrack (easier use than searchItem) FullTrack fullTrack = searchItem.Tracks.Items[0]; // add the track to the spotify queue and pass the OnMessageReceivedArgs (contains user who requested the song etc) AddSong(fullTrack.Id, e); } else { string response; // if no track has been found inform the requester response = Settings.Bot_Resp_Error; response = response.Replace("{user}", e.ChatMessage.DisplayName); response = response.Replace("{artist}", ""); response = response.Replace("{title}", ""); response = response.Replace("{maxreq}", ""); response = response.Replace("{errormsg}", ""); _client.SendMessage(e.ChatMessage.Channel, response); return; } } // start the command cooldown StartCooldown(); return; } }
private void MetroWindowLoaded(object sender, RoutedEventArgs e) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); if (File.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + "/log.log")) { File.Delete(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + "/log.log"); } if (Settings.AutoClearQueue) { ReqList.Clear(); WebHelper.UpdateWebQueue("", "", "", "", "", "1", "c"); } Settings.MsgLoggingEnabled = false; // Load Config file if one exists if (File.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + "/config.xml")) { ConfigHandler.LoadConfig(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) + "/config.xml"); } // Add sources to combobox AddSourcesToSourceBox(); // Create systray menu and icon and show it _menuItem1.Text = @"Exit"; _menuItem1.Click += MenuItem1Click; _menuItem2.Text = @"Show"; _menuItem2.Click += MenuItem2Click; _contextMenu.MenuItems.AddRange(new[] { _menuItem2, _menuItem1 }); NotifyIcon.Icon = Properties.Resources.songify; NotifyIcon.ContextMenu = _contextMenu; NotifyIcon.Visible = true; NotifyIcon.DoubleClick += MenuItem2Click; NotifyIcon.Text = @"Songify"; // set the current theme ThemeHandler.ApplyTheme(); // start minimized in systray (hide) if (WindowState == WindowState.Minimized) { MinimizeToSysTray(); } // get the software version from assembly Assembly assembly = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); Version = fvi.FileVersion; // generate UUID if not exists, expand the window and show the telemetrydisclaimer if (Settings.Uuid == "") { Width = 588 + 200; Height = 247.881 + 200; Settings.Uuid = Guid.NewGuid().ToString(); TelemetryDisclaimer(); } else { // start the timer that sends telemetry every 5 Minutes TelemetryTimer(); } // check for update WorkerUpdate.RunWorkerAsync(); // set the cbx index to the correct source cbx_Source.SelectedIndex = Settings.Source; _selectedSource = cbx_Source.SelectedValue.ToString(); cbx_Source.SelectionChanged += Cbx_Source_SelectionChanged; // text in the bottom right LblCopyright.Content = "Songify v" + Version.Substring(0, 5) + " Copyright © Jan \"Inzaniity\" Blömacher"; if (_selectedSource == PlayerType.SpotifyWeb) { if (string.IsNullOrEmpty(Settings.AccessToken) && string.IsNullOrEmpty(Settings.RefreshToken)) { TxtblockLiveoutput.Text = "Please link your Spotify account\nSettings -> Integration"; } else { APIHandler.DoAuthAsync(); } img_cover.Visibility = Visibility.Visible; } else { img_cover.Visibility = Visibility.Hidden; } if (Settings.TwAutoConnect) { TwitchHandler.BotConnect(); } // automatically start fetching songs SetFetchTimer(); }