Exemplo n.º 1
0
        public ImageUploadResult UploadImage(string path, out string UrlOfImage)
        {
            string ApiKey = botInstance.GetImgBBKey();

            if (ApiKey == "")
            {
                UrlOfImage = "";
                return(ImageUploadResult.NotConfigured);
            }

            if (!File.Exists(path))
            {
                UrlOfImage = "";
                return(ImageUploadResult.FileNotFound);
            }

            try
            {
                FileStream fstream = File.OpenRead(path);
                byte[]     data    = new byte[fstream.Length];
                fstream.Read(data, 0, data.Length);
                fstream.Close();

                HttpWebRequest wRequest = (HttpWebRequest)HttpWebRequest.Create(string.Format("{0}?key={1}", ImageUploadEndPoint, ApiKey));
                wRequest.Method      = "POST";
                wRequest.ContentType = "application/x-www-form-urlencoded";

                wRequest.ServicePoint.Expect100Continue = false;
                NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
                outgoingQueryString.Add("image", Convert.ToBase64String(data));
                string postdata = outgoingQueryString.ToString();

                StreamWriter streamWriter = new StreamWriter(wRequest.GetRequestStream());
                streamWriter.Write(postdata);
                streamWriter.Close();

                WebResponse  response       = wRequest.GetResponse();
                Stream       responseStream = response.GetResponseStream();
                StreamReader responseReader = new StreamReader(responseStream);
                string       responseString = responseReader.ReadToEnd();

                var responseData = JObject.Parse(responseString)["data"];
                if (responseData == null)
                {
                    UrlOfImage = "";
                    return(ImageUploadResult.FailedToParse);
                }

                UrlOfImage = responseData["url_viewer"].ToString();
                return(ImageUploadResult.OK);
            }
            catch (Exception e)
            {
                ErrorLogging.WriteLine(e.ToString());
                UrlOfImage = "";
                return(ImageUploadResult.Fail);
            }
        }
Exemplo n.º 2
0
        private void IrcClient_OnConnected(object sender, EventArgs e)
        {
            Console.WriteLine("Connected!");
            ErrorLogging.WriteLine("Connected!");
            MeebyIrcClient.Login(BotConnectionConfig.Username, BotConnectionConfig.Username, 4, BotConnectionConfig.Username, "oauth:" + BotConnectionConfig.Password);
            Thread.Sleep(2000);

            //Request capabilities - https://dev.twitch.tv/docs/irc/guide/#twitch-irc-capabilities
            MeebyIrcClient.WriteLine("CAP REQ :twitch.tv/tags twitch.tv/commands twitch.tv/membership");
            Thread.Sleep(2000);

            foreach (var channel in BotCoreConfig.ChannelsToJoin)
            {
                ConnectToChannel(channel, Storage.ChannelConfig.Load(channel));
                Thread.Sleep(2000);                    //Since Twitch doesn't like mass joining
            }
        }
Exemplo n.º 3
0
 private void MeebyIrcClient_OnRawMessage(object sender, IrcEventArgs e)
 {
     try
     {
         if (e.Data.Channel != null && e.Data.Nick != null && e.Data.Message != null && ActiveChannels.ContainsKey(e.Data.Channel))
         {
             LastMessage.Update(GetRoleFromTags(e), e.Data.Nick, e.Data.Message,
                                e.Data.Tags.ContainsKey("msg-id") ? e.Data.Tags["msg-id"] == "highlighted-message" : false,   //if message is highlighted using Twitch points
                                e.Data.Tags.ContainsKey("custom-reward-id") ? e.Data.Tags["custom-reward-id"] : null          //custom reward using viewer points
                                );
             this.OnChatMessageReceived?.Invoke(e.Data.Channel, LastMessage);
             ActiveChannels[e.Data.Channel].DoWork(LastMessage);
         }
     }
     catch (Exception ex)
     {
         ErrorLogging.WriteLine("Exception on raw message " + ex.Message);
     }
 }
Exemplo n.º 4
0
        public void GetStatus()
        {
            if (JsonGrabber.GrabJson(sUrlTwitchStatus, RequestHeaders, "application/json", "application/vnd.twitchtv.v3+json", "GET", out string res))
            {
                try
                {
                    var response = JObject.Parse(res);
                    if (response["data"] != null && response["data"].Children().Count() > 0)
                    {
                        var dataNode = response["data"].First;
                        if (dataNode["title"] != null)
                        {
                            isOnline = true;
                            var title = dataNode["title"].ToString();
                            TitleHasChanged = OldTitle != title;
                            OldTitle        = title;

                            if (dataNode["type"] != null)
                            {
                                var streamType = dataNode["type"].ToString();
                                if (streamType == "live")
                                {
                                    isOnline = true;
                                }
                                else
                                {
                                    isOnline = false;
                                }
                            }

                            if (dataNode["started_at"] != null)
                            {
                                var dateTimeStartAsstring = dataNode["started_at"].ToString();
                                //"2020-02-25t13:42:32z"
                                if (DateTime.TryParse(dateTimeStartAsstring, out DateTime ParsedTime))
                                {
                                    StartTime = ParsedTime.ToUniversalTime();
                                }
                                else
                                {
                                    StartTime = DateTime.MinValue;
                                }
                            }

                            if (dataNode["game_id"] != null)
                            {
                                var gameIdAsString = dataNode["game_id"].ToString();
                                game = ResolveNameFromId(gameIdAsString);
                                if (game == "ul")
                                {
                                    game = String.Empty;
                                }
                                Console.WriteLine(string.Format("{0} - Checked stream status. Is online, playing {1}", channelName, game));
                            }
                            else
                            {
                                Console.WriteLine(string.Format("{0} - Checked stream status. Is online (no game?)", channelName));
                            }

                            if (dataNode["viewer_count"] != null)
                            {
                                var viewers = dataNode["viewer_count"].ToString();
                                if (uint.TryParse(viewers, out uint Value))
                                {
                                    this.LastViewers = Value;
                                }
                            }
                        }
                        else
                        {
                            isOnline = false;
                            Console.WriteLine(string.Format("{0} - Checked stream status. Is offline.", channelName));
                        }
                    }
                    else
                    {
                        isOnline = false;
                        Console.WriteLine(string.Format("{0} - Checked stream status. Is offline.", channelName));
                    }
                }
                catch (Exception e)
                {
                    ErrorLogging.WriteLine("Error trying to parse Json when doing stream update request: " + e.Message);
                    isOnline = false;
                }
            }
            else
            {
                Console.WriteLine("Error checking Json");
            }
        }
Exemplo n.º 5
0
 public void Shutdown()
 {
     ErrorLogging.WriteLine("Planned shutdown performed ");
     Close();
     ErrorLogging.Close();
 }
Exemplo n.º 6
0
 private void IrcClient_OnError(object sender, ErrorEventArgs e)
 {
     Console.WriteLine("Error: !" + e.ErrorMessage);
     ErrorLogging.WriteLine("Error: !" + e.ErrorMessage);
 }
Exemplo n.º 7
0
 private void IrcClient_OnErrorMessage(object sender, IrcEventArgs e)
 {
     ErrorLogging.WriteLine("Error: !" + e.Data.Message);
     Console.WriteLine("Error: " + e.Data.Message);
 }
Exemplo n.º 8
0
 private void IrcClient_OnConnecting(object sender, EventArgs e)
 {
     ErrorLogging.WriteLine("Connecting...");
 }
Exemplo n.º 9
0
 private void IrcClient_OnAutoConnectError(object sender, AutoConnectErrorEventArgs e)
 {
     Console.WriteLine("Auto connect error: " + e.Exception);
     ErrorLogging.WriteLine("Auto connect error: " + e.Exception);
 }
Exemplo n.º 10
0
 private void IrcClient_OnDisconnected(object sender, EventArgs e)
 {
     ActiveChannels.Clear();
     Console.WriteLine("! Disconnected");
     ErrorLogging.WriteLine("! Disconnected");
 }
Exemplo n.º 11
0
 private void IrcClient_OnRegistered(object sender, EventArgs e)
 {
     this.OnIrcFeedback?.Invoke(Events.IrcFeedback.Verified, "");
     Console.WriteLine("! LOGIN VERIFIED");
     ErrorLogging.WriteLine("! LOGIN VERIFIED");
 }
Exemplo n.º 12
0
 private void MeebyIrcClient_OnConnectionError(object sender, EventArgs e)
 {
     Console.WriteLine("!!! CONNECTION ERROR!!! " + e.ToString());
     ErrorLogging.WriteLine("!!! CONNECTION ERROR!!! " + e.ToString());
 }