Exemple #1
0
 private void OnAddButtonClick(object sender, EventArgs e)
 {
     if (!Music.Playlists["default"].ContainsSongWithID(Music.LoadedSong.ID))
     {
         var playlist = Music.Playlists["default"];
         var songCopy = new SongData(Music.LoadedSong);
         try
         {
             playlist.AddSong(songCopy);
             BotTools.LogLine("Added current song to default playlist");
             btnAddToDefault.Enabled = false;
         }
         catch (ArgumentException)
         {
             BotTools.LogLine($"Couldn't add current song: Already in default playlist");
         }
         catch (FormatException)
         {
             BotTools.LogLine($"Couldn't add current song: Bad url");
         }
     }
     else
     {
         BotTools.LogLine("Song already in default playlist!");
     }
 }
Exemple #2
0
        private static bool GetStreamOnline()
        {
            for (int i = 20; i > 0; i--)
            {
                string         url     = "https://decapi.me/twitch/uptime/maerictv";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string result = reader.ReadToEnd();
                            if (result.Contains("offline"))
                            {
                                BotTools.LogLine($"Stream reported as offline");
                                return(false);
                            }
                            else if (result.Contains("seconds") || result.Contains("minutes") || result.Contains("hours"))
                            {
                                BotTools.LogLine($"Stream reported as online");
                                return(true);
                            }
                        }
                BotTools.LogLine($"Failed to fetch stream status. Retrying {i} more times...");
            }
            BotTools.LogLine($"Failed to fetch stream status. Treating stream as offline.");
            return(false);
        }
Exemple #3
0
 private void OnVolumeTrackbarMouseUp(object sender, MouseEventArgs e)
 {
     btnVolume.ForeColor         = Color.FromArgb(255, 35, 255);
     btnVolume.Text              = "VOL";
     BotTools.Settings["volume"] = windowsMP.settings.volume;
     BotTools.SaveSettings();
 }
Exemple #4
0
 private static void Client_OnWhisperReceived(object sender, OnWhisperReceivedArgs e)
 {
     if (e.WhisperMessage.Username == CurrentChannel || BotTools.ReadFromJson <List <string> >("resources\\moderators").Contains(e.WhisperMessage.Username))
     {
         BotTools.LogLine($"○ {e.WhisperMessage.DisplayName}: {e.WhisperMessage.Message.Trim()}");
     }
 }
Exemple #5
0
 private static void PubSub_OnListenResponse(object sender, OnListenResponseArgs e)
 {
     if (!e.Successful)
     {
         BotTools.LogLine($"Failed to listen! Response: {e.Response.Error}");
     }
 }
Exemple #6
0
 private void OnPlaylistBoxDoubleClick(object sender, EventArgs e)
 {
     if (!InPlaylist())
     {
         var selected = $"{listBoxPlaylist.SelectedItem}";
         var playlist = Music.Playlists[selected];
         if (playlist != null)
         {
             listBoxPlaylist.DataSource = playlist.Songs.Select(s => s.Title).ToList <string>();
             enteredPlaylist            = selected;
             btnLoad.Text      = "SHUFFLE";
             btnRemove.Enabled = listBoxPlaylist.Items.Count > 0;
         }
     }
     else
     {
         var selected     = $"{listBoxPlaylist.SelectedItem}";
         var playlist     = Music.GetPlaylist(enteredPlaylist);
         var selectedSong = playlist.GetSong(selected);
         if (selectedSong != null)
         {
             Music.FillSongRequest(selectedSong.URL, songRequestor: "MaericTV", bypassVet: true);
             BotTools.LogLine($"Added to request Queue: {selectedSong.Title}");
         }
     }
 }
Exemple #7
0
 private void OnFormClose(object sender, FormClosedEventArgs e)
 {
     try
     {
         BotTools.DumpToTextFile("RazBot 2.0 is Offline: Request Playing Disabled", "datasources\\now_playing");
     }
     catch { }
     try
     {
         using (StreamWriter sw = File.AppendText(BotTools.SessionLogFile))
         {
             sw.WriteLine($"\t--End of Session [{DateTime.Now:HH:mm:ss}]--\n");
         }
     }
     catch { }
     try
     {
         Music.ClearRequests();
     }
     catch { }
     try
     {
         NAudioTools.DeleteAllWavs();
     }
     catch { }
 }
Exemple #8
0
        public static List <Dictionary <string, dynamic> > GetPosts()
        {
            string url = $"{RootUrl}/{UserId}/media?access_token={AccessToken}&fields=permalink,caption,media_url";

            var response = WebTools.GetJObjectResponse(url);

            try
            {
                if (response != null && response.HasValues && response["data"].Any())
                {
                    return(response["data"].ToObject <List <Dictionary <string, dynamic> > >());
                }
                else
                {
                    return(new List <Dictionary <string, dynamic> >()
                    {
                    });
                }
            }
            catch (Exception e)
            {
                BotTools.LogToSessionLogFile(e.ToString());
                return(new List <Dictionary <string, dynamic> >()
                {
                });
            }
        }
Exemple #9
0
        private void RemoveSelectedSong()
        {
            if (listBoxPlaylist.SelectedItems.Count == 1)
            {
                var index    = listBoxPlaylist.SelectedIndex;
                var playlist = Music.Playlists[enteredPlaylist];
                var songID   = playlist.Songs[index].ID;
                var filePath = $"{BotTools.BasePath}\\playlists\\{enteredPlaylist}\\{songID}.mp4";

                // Remove from list
                playlist.RemoveSong(index);
                Music.SavePlaylists();

                // Delete mp4 file
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                // Refresh listbox
                listBoxPlaylist.DataSource = playlist.Songs.Select(s => s.Title).ToList <string>();
                btnRemove.Enabled          = listBoxPlaylist.Items.Count > 0;

                // Load default playlist if last song in loaded playlist
                if (!Music.Playlists[enteredPlaylist].Songs.Any() && Music.LoadedPlaylist == enteredPlaylist)
                {
                    Music.LoadedPlaylist = "default";
                    BotTools.Settings["loaded_playlist"] = Music.LoadedPlaylist;
                    Music.QueuedSong = Music.DownloadedSong = Music.LoadedSong = null;
                    BotTools.SaveSettings();
                }
            }
        }
Exemple #10
0
        private static void Client_OnReSubscriber(object sender, OnReSubscriberArgs e)
        {
            int    monthCount = e.ReSubscriber.Months;
            string monthWord  = monthCount > 1 ? "months" : "month";

            BotTools.LogLine($"{e.ReSubscriber.DisplayName} subscribed ({monthCount} {monthWord})");
        }
Exemple #11
0
        private static void Client_OnGiftedSubscription(object sender, OnGiftedSubscriptionArgs e)
        {
            string giftee = e.GiftedSubscription.MsgParamRecipientDisplayName;
            string gifter = e.GiftedSubscription.DisplayName;

            BotTools.LogLine($"{gifter} gifted a sub to {giftee}");
        }
Exemple #12
0
        private static void Client_OnModeratorsReceived(object sender, OnModeratorsReceivedArgs e)
        {
            var mods = String.Join(", ", e.Moderators);

            BotTools.LogLine($"Channel Moderators: {mods}");
            BotTools.WriteToJson(e.Moderators, "resources\\moderators");
        }
Exemple #13
0
        private void OnTimer2MinTick(object sender, EventArgs e)
        {
            var posts = Instagram.GetPosts();

            if (posts.Count > 0)
            {
                bool petsExist = File.Exists($"{BotTools.BasePath}\\resources\\raz_pets.json");
                var  pastPets  = petsExist ? BotTools.ReadFromJson <List <string> >("resources\\raz_pets") : new List <string>();

                try
                {
                    var newPets = posts.Where(p => !pastPets.Contains(p["permalink"]));
                    if (newPets.Count() > 0)
                    {
                        foreach (var post in newPets)
                        {
                            BotTools.LogLine($"Saw new Raz pet -> {post["permalink"]}");
                            DiscordBot.PostToPetsChannel(post);
                            pastPets.Add(post["permalink"]);

                            using (var webClient = new System.Net.WebClient())
                            {
                                webClient.DownloadFile(post["media_url"], $"{BotTools.BasePath}\\datasources\\raz.jpg");
                            }
                        }
                        BotTools.WriteToJson(pastPets, "resources\\raz_pets");
                    }
                }
                catch (Exception petsException)
                {
                    BotTools.LogToSessionLogFile(petsException.ToString());
                    BotTools.LogLine("There was a problem loading past Raz Pets! See the session log for details.");
                }
            }
        }
Exemple #14
0
 private void OnDebugModeCheckboxCheckedChanged(object sender, EventArgs e)
 {
     BotTools.Settings["debug_output"] = cbDebug.Checked;
     cbDebug.BackColor       = cbDebug.Checked ? Color.FromArgb(30, 255, 255) : Color.FromArgb(34, 15, 34);
     cbDebug.BackgroundImage = cbDebug.Checked ? Properties.Resources.silent_mode_black : Properties.Resources.silent_mode;
     cbDebug.ForeColor       = cbDebug.Checked ? Color.FromArgb(14, 0, 20) : Color.FromArgb(255, 35, 255);
     BotTools.SaveSettings();
 }
Exemple #15
0
        private static void Client_OnCommunitySubscription(object sender, OnCommunitySubscriptionArgs e)
        {
            int    giftAmount = e.GiftedSubscription.MsgParamMassGiftCount;
            string subWords   = giftAmount > 1 ? $"{giftAmount} subscriptions" : "a subscription";

            BotTools.LogLine($"{e.GiftedSubscription.DisplayName} gifted {subWords} " +
                             $"({e.GiftedSubscription.MsgParamSenderCount} total)");
        }
Exemple #16
0
 private void OnDiscordAnnounceCheckboxCheckedChanged(object sender, EventArgs e)
 {
     BotTools.Settings["announce_songs"] = cbSongAnnounce.Checked;
     BotTools.SaveSettings();
     cbSongAnnounce.BackColor = cbSongAnnounce.Checked ? Color.FromArgb(30, 225, 255) : Color.FromArgb(34, 15, 34);
     cbSongAnnounce.ForeColor = cbSongAnnounce.Checked ? Color.FromArgb(14, 0, 20) : Color.FromArgb(255, 35, 255);
     cbSongAnnounce.BackgroundImage.Dispose();
     cbSongAnnounce.BackgroundImage = cbSongAnnounce.Checked ? Properties.Resources.discord_black : Properties.Resources.discord;
 }
Exemple #17
0
 private void OnVetRequestsCheckboxCheckedChanged(object sender, EventArgs e)
 {
     BotTools.Settings["vet_requests"] = cbVetReqeusts.Checked;
     BotTools.SaveSettings();
     cbVetReqeusts.BackColor = cbVetReqeusts.Checked ? Color.FromArgb(30, 225, 255) : Color.FromArgb(34, 15, 34);
     cbVetReqeusts.ForeColor = cbVetReqeusts.Checked ? Color.FromArgb(14, 0, 20) : Color.FromArgb(255, 35, 255);
     cbVetReqeusts.BackgroundImage.Dispose();
     cbVetReqeusts.BackgroundImage = cbVetReqeusts.Checked ? Properties.Resources.vet_requests_black_noborder : Properties.Resources.vet_requests_noborder;
 }
Exemple #18
0
 private void OnRandomPlayCheckboxCheckedChanged(object sender, EventArgs e)
 {
     BotTools.Settings["random_play"] = cbRandom.Checked;
     cbRandom.BackColor = cbRandom.Checked ? Color.FromArgb(30, 225, 255) : Color.FromArgb(34, 15, 34);
     cbRandom.ForeColor = cbRandom.Checked ? Color.FromArgb(14, 0, 20) : Color.FromArgb(255, 35, 255);
     cbRandom.BackgroundImage.Dispose();
     cbRandom.BackgroundImage = cbRandom.Checked ? Properties.Resources.btn_random_black : Properties.Resources.btn_random;
     BotTools.SaveSettings();
 }
Exemple #19
0
        public static void FilesInit()
        {
            if (File.Exists($"{BasePath}\\resources\\bot_settings.json"))
            {
                Settings = BotTools.ReadFromJson <Dictionary <string, dynamic> >("resources\\bot_settings");
            }
            else
            {
                string json     = Properties.Resources.bot_options;
                var    settings = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(json);
                Settings = settings;
                WriteToJson(Settings, "resources\\bot_settings");
            }

            if (!File.Exists($"{BasePath}\\resources\\builds.json"))
            {
                string buildsJson = Properties.Resources.builds;
                var    builds     = JsonConvert.DeserializeObject <Dictionary <string, string> >(buildsJson);
                WriteToJson(builds, "resources\\builds");
            }

            if (!File.Exists($"{BasePath}\\resources\\custom_commands.json"))
            {
                string customCommandsJson = Properties.Resources.custom_commands;
                var    customCommands     = JsonConvert.DeserializeObject <Dictionary <string, string> >(customCommandsJson);
                WriteToJson(customCommands, "resources\\custom_commands");
            }

            if (!File.Exists($"{BasePath}\\resources\\inventory_data.json"))
            {
                string inventoryDataJson = Properties.Resources.inventory_data;
                var    inventoryData     = JsonConvert.DeserializeObject <Dictionary <string, Playlist> >(inventoryDataJson);
                WriteToJson(inventoryData, "resources\\inventory_data");
            }

            if (!File.Exists($"{BasePath}\\resources\\playlists.json"))
            {
                string playlistsJson = Properties.Resources.playlists;
                var    playlists     = JsonConvert.DeserializeObject <Dictionary <string, Playlist> >(playlistsJson);
                WriteToJson(playlists, "resources\\playlists");
            }

            if (!File.Exists($"{BasePath}\\resources\\raz_pets.json"))
            {
                string razPetsJson = Properties.Resources.raz_pets;
                var    razPets     = JsonConvert.DeserializeObject <List <string> >(razPetsJson);
                WriteToJson(razPets, "resources\\raz_pets");
            }

            if (!File.Exists($"{BasePath}\\resources\\moderators.json"))
            {
                string moderatorsJson = Properties.Resources.moderators;
                var    moderators     = JsonConvert.DeserializeObject <List <string> >(moderatorsJson);
                WriteToJson(moderators, "resources\\moderators");
            }
        }
Exemple #20
0
 private static Dictionary <string, Dictionary <string, dynamic> > LoadInventoryData()
 {
     if (File.Exists($"{BotTools.BasePath}\\resources\\inventory_data.json"))
     {
         return(BotTools.ReadFromJson <Dictionary <string, Dictionary <string, dynamic> > >("resources\\inventory_data"));
     }
     else
     {
         return(new Dictionary <string, Dictionary <string, dynamic> >());
     }
 }
Exemple #21
0
        private void OnQuestionBoxCheckedChanged(object sender, EventArgs e)
        {
            cbQuestions.ForeColor = cbQuestions.Checked ? Color.FromArgb(14, 0, 20) : Color.FromArgb(255, 35, 255);
            cbQuestions.BackgroundImage.Dispose();
            cbQuestions.BackgroundImage = cbQuestions.Checked ? Properties.Resources.question_mark_black : Properties.Resources.question_mark;
            var state = cbQuestions.Checked ? "is" : "is not";

            toolTip1.SetToolTip(cbQuestions, $"WitAi {state} fielding questions.");
            BotTools.Settings["handle_questions"] = cbQuestions.Checked;
            BotTools.SaveSettings();
        }
Exemple #22
0
 public static void PostToDJChannel(string postContent)
 {
     if (BotTools.Settings["announce_songs"] && !BotTools.Settings["debug_output"])
     {
         DJChannelWebhook.SendMessageAsync(text: postContent);
     }
     else
     {
         BotTools.LogLine("[D] RazBot: " + postContent);
     }
 }
Exemple #23
0
 private Dictionary <string, string> LoadCustomCommands()
 {
     if (File.Exists($"{BotTools.BasePath}\\resources\\custom_commands.json"))
     {
         var functionDict = BotTools.ReadFromJson <Dictionary <string, string> >("resources\\custom_commands");
         return(functionDict);
     }
     else
     {
         return(new Dictionary <string, string>());
     }
 }
Exemple #24
0
        public static string FillSongRequest(string requestBody, string songRequestor = "RazBot", bool bypassVet = false)
        {
            SongData songData = YTE.GetSongData(requestBody, requestor: songRequestor);

            if (songData.Duration <= TimeSpan.FromMinutes(10))
            {
                if (BotTools.Settings["vet_requests"] && !bypassVet)
                {
                    DiscordBot.PostVetRequestToDJChannel(songData);
                    return($"@{songData.Requestor}, Your request has been submitted for review! razBot");
                }
                else
                {
                    try
                    {
                        Music.GetPlaylist("request").AddSong(songData);
                        var placement = Music.GetPlaylist("request").Songs.Count;
                        if (DownloadedSong != null && placement == 1)
                        {
                            if (DownloadedSong.IsRequest)
                            {
                                placement++;
                            }
                            else
                            {
                                DownloadedSong = null;
                                GetPlaylist(LoadedPlaylist).CycleBack();
                            }
                        }
                        var placementWord = BotTools.GetPlacementWord(placement);

                        Music.SavePlaylists();
                        return($"@{songData.Requestor}, Your request is {placementWord} in the queue! razCool");
                    }
                    catch (ArgumentException)
                    {
                        BotTools.LogLine($"{songRequestor}'s request rejected: Already in queue");
                        return($"Sorry @{songRequestor}, that request is already queued!");
                    }
                    catch (FormatException e)
                    {
                        BotTools.LogToSessionLogFile(e.ToString());
                        BotTools.LogLine($"{songRequestor}'s request rejected: Bad url");
                        return($"Sorry @{songRequestor}, I can't access a YouTube video from that link! It may not be available in my region, or the url may not be properly formatted.");
                    }
                }
            }
            else
            {
                return($"{songData.Requestor}'s request was rejected: The audio was over 10 minutes long! razS");
            }
        }
Exemple #25
0
 private string[] SkipSong(TwitchMessage message)
 {
     if (message.HasModPrivileges && CooldownDone("skip", 2))
     {
         MainWindow.SkipSong();
         BotTools.LogLine($"Song skipped by {message.DisplayName}");
         return(new string[] { });
     }
     else
     {
         return(null);
     }
 }
Exemple #26
0
 public string[] TryInvoke(string token, TwitchMessage message)
 {
     if (Map.ContainsKey(token))
     {
         string invokeReport = $"{message.DisplayName} invoked \"{token}\" ->";
         if (message.HasInvokation)
         {
             invokeReport += $"\n\t|| TOKEN: {message.Token}";
         }
         if (message.HasQuestion)
         {
             invokeReport += $"\n\t|| QUESTION: {message.Message}";
         }
         if (message.Intent != null)
         {
             invokeReport += $"\n\t|| INTENT: {message.Intent}";
         }
         if (message.Args != null && message.Args.Length > 0)
         {
             invokeReport += $"\n\t|| ARGS: [{String.Join(", ", message.Args)}]";
         }
         BotTools.LogLine(invokeReport);
         return(Map[token](message));
     }
     else if (CustomMap.ContainsKey(token))
     {
         string invokeReport = $"{message.DisplayName} invoked \"{token}\" ->";
         if (message.HasInvokation)
         {
             invokeReport += $"\n\t|| TOKEN: {message.Token}";
         }
         if (message.HasQuestion)
         {
             invokeReport += $"\n\t|| QUESTION: {message.Message}";
         }
         if (message.Intent != null)
         {
             invokeReport += $"\n\t|| INTENT: {message.Intent}";
         }
         if (message.Args != null && message.Args.Length > 0)
         {
             invokeReport += $"\n\t|| ARGS: [{String.Join(", ", message.Args)}]";
         }
         BotTools.LogLine(invokeReport);
         return(new string[] { TwitchBot.Commands.CustomMap[token].Replace("{user}", message.DisplayName) });
     }
     else
     {
         return(null);
     }
 }
Exemple #27
0
        public void RemoveSong(SongData songData)
        {
            var idx = Songs.FindIndex(s => s.ID == songData.ID);

            if (idx >= 0)
            {
                BotTools.LogLine($"Removing \"{songData.Title}\" from \"{Name}\"");
                RemoveSong(idx);
            }
            else
            {
                BotTools.LogLine($"\"{songData.Title}\" doesn't exist in \"{Name}\"");
            }
        }
Exemple #28
0
 public static void SendMessage(string message)
 {
     if (Client.IsConnected)
     {
         if (BotTools.Settings["debug_output"] == true)
         {
             BotTools.LogLine($"[T] RazBot: {message}");
         }
         else
         {
             Client.SendMessage(CurrentChannel, $"/me ~ {message}");
         }
     }
 }
Exemple #29
0
        private void RemoveSongFromPlaylist()
        {
            var loadedPlaylist = Music.Playlists[Music.LoadedPlaylist];

            if (loadedPlaylist.ContainsSong(Music.LoadedSong))
            {
                loadedPlaylist.RemoveSong(Music.LoadedSong);
            }
            if (!loadedPlaylist.Songs.Any())
            {
                BotTools.LogLine("Loaded playlist is empty, loading default");
                Music.LoadedPlaylist = "default";
                BotTools.Settings["loaded_playlist"] = Music.LoadedPlaylist;
                BotTools.SaveSettings();
            }
            SkipSong();
        }
Exemple #30
0
        private void NormalizeDownloadedAudio(object sender, DoWorkEventArgs e)
        {
            normalizingAudio = true;
            string songID       = Music.DownloadedSong.ID;
            string playlistName = Music.DownloadedSong.IsRequest ? "request" : Music.LoadedPlaylist;

            NAudioTools.Mp4ToWav($"playlists\\{playlistName}\\{songID}");
            NAudioTools.Normalize($"playlists\\{playlistName}\\{songID}");
            File.Delete($"{BotTools.BasePath}\\playlists\\{playlistName}\\{songID}.wav");
            if (unloadPath != null)
            {
                File.Delete(unloadPath);
                unloadPath = null;
            }
            normalizingAudio = false;
            BotTools.LogLine($"Normalized {Music.DownloadedSong.Title}");
        }