public void ImgurSetup() { string imgID = Karuta.REGISTY.GetString("imgur_id"); string imgSec = Karuta.REGISTY.GetString("imgur_secret"); if (string.IsNullOrWhiteSpace(imgID) || string.IsNullOrWhiteSpace(imgSec)) { Karuta.Write("Please enter Imgur API information:"); imgID = Karuta.GetInput("Imgur API ID"); imgSec = Karuta.GetInput("Imgur API Sec"); } Karuta.LOGGER.Log("Connecting to imgur...", _appName); try { _imgurClient = new ImgurClient(imgID, imgSec); albumEndpoint = new AlbumEndpoint(_imgurClient); } catch (Exception e) { Karuta.Write("Failed to connect"); Karuta.Write(e.Message); _imgurClient = null; } Karuta.REGISTY.SetValue("imgur_id", imgID); Karuta.REGISTY.SetValue("imgur_secret", imgSec); }
async void Init() { Karuta.LOGGER.Log("Starting Discord Bot..", _appName); try { ImgurSetup(); } catch (Exception e) { Karuta.LOGGER.LogError($"Unable to initiate Imgur Connection: {e.Message}", _appName); } client = new DiscordClient(); if (string.IsNullOrWhiteSpace(_token)) { _token = Karuta.GetInput("Enter discord token"); Karuta.REGISTY.SetValue("discordToken", _token); } client.MessageReceived += MessageRecieved; client.UserJoined += UserJoined; try { await client.Connect(_token, TokenType.Bot); client.SetGame("World Domination"); //SendToAllConsoles("Bot Online"); }catch (Exception e) { Karuta.LOGGER.LogWarning($"Unable to initiate connection to discord: {e.Message}", _appName); Karuta.LOGGER.LogError(e.StackTrace, _appName, true); Karuta.Write("Unable to connect to discord..."); } }
private string GetAuthToken() { if (_cookies == null) { GetCookies(); } string pass = Karuta.GetInput("Please enter your Plex password", true); string postData = String.Format("user[login]={0}&user[password]={1}", Karuta.user, pass); HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create("https://my.plexapp.com/users/sign_in.xml"); getRequest.CookieContainer = new CookieContainer(); getRequest.CookieContainer.Add(_cookies); //recover cookies First request getRequest.Method = WebRequestMethods.Http.Post; getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"; getRequest.AllowWriteStreamBuffering = true; getRequest.ProtocolVersion = HttpVersion.Version11; getRequest.AllowAutoRedirect = true; getRequest.ContentType = "application/x-www-form-urlencoded"; byte[] byteArray = Encoding.ASCII.GetBytes(postData); getRequest.ContentLength = byteArray.Length; Stream newStream = getRequest.GetRequestStream(); //open connection newStream.Write(byteArray, 0, byteArray.Length); // Send the data. newStream.Close(); HttpWebResponse response = (HttpWebResponse)getRequest.GetResponse(); //Retrieve your cookie that id's your session //response.Cookies StreamReader reader = new StreamReader(response.GetResponseStream()); string output = reader.ReadToEnd(); reader.Close(); reader.Dispose(); response.Close(); return(output); }