Advertisement
Guest User

The Button Flair in C#

a guest
Jul 13th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 KB | None | 0 0
  1. using Newtonsoft.Json.Linq;
  2. using System; //Copyright 2015 (c) NorbiPeti
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9.  
  10. /*
  11.  * This project uses data from karmadecay.com which I found in Karmancer which I was pointed to by Nathan_Heburn (Minecraft name)
  12.  * And it also uses Newtonsoft.Json
  13.  * And someone should translate it to Java
  14.  */
  15.  
  16. namespace TheButtonMCAutoFlairProto
  17. {
  18.     class Program
  19.     { //2015.07.13.
  20.         //public static int LastUpdate;
  21.         //public static int CommentCount = 0;
  22.         //public static string LastComment = "";
  23.         static void Main(string[] args)
  24.         {
  25.             while(true)
  26.             {
  27.                 DownloadFlairs();
  28.                 Thread.Sleep(5000);
  29.                 Console.Clear();
  30.             }
  31.             //Console.ReadLine();
  32.         }
  33.  
  34.         public static void DownloadFlairs()
  35.         {
  36.             Console.WriteLine("Downloading information...");
  37.             try
  38.             {
  39.                 //string data = new WebClient().DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?count=" + CommentCount + "&after=" + LastComment);
  40.                 string data = new WebClient().DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json");
  41.                 var obj = JArray.Parse(data)[1];
  42.                 var array = obj["data"]["children"];
  43.                 foreach (JObject item in array)
  44.                 {
  45.                     string author = item["data"]["author"].ToString();
  46.                     string ign = item["data"]["body"].ToString();
  47.                     int start = ign.IndexOf("IGN:") + "IGN:".Length;
  48.                     int end = ign.IndexOf(' ', start);
  49.                     if (end == -1 || end == start)
  50.                         ign = ign.Substring(start);
  51.                     else
  52.                         ign = ign.Substring(start, end);
  53.                     ign = ign.Trim();
  54.                     //Console.WriteLine("IGN: " + ign);
  55.                     //LastComment = item["data"]["name"].ToString();
  56.                     //CommentCount++;
  57.                     if (HasIGFlair(ign))
  58.                         continue;
  59.                     string[] flairdata = new WebClient().DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).Replace("\"", "").Split(':');
  60.                     string flair = flairdata[1];
  61.                     if (flair != "-1")
  62.                         flair = flair + "s";
  63.                     else
  64.                         flair = "non-presser";
  65.                     string flairclass = flairdata[2];
  66.                     SetFlair(ign, flair, flairclass);
  67.                 }
  68.                 Console.WriteLine("Done!");
  69.             }
  70.             catch(Exception e)
  71.             {
  72.                 Console.WriteLine("Error!\n" + e);
  73.             }
  74.         }
  75.  
  76.         /// <summary>
  77.         /// Placeholder
  78.         /// </summary>
  79.         /// <param name="message"></param>
  80.         public static void TellPlayer(string playername, string message)
  81.         {
  82.             Console.WriteLine("TellPlayer: (to: " + playername + ") " + message);
  83.         }
  84.  
  85.         /// <summary>
  86.         /// Placeholder
  87.         /// </summary>
  88.         /// <param name="flair"></param>
  89.         public static void SetFlair(string playername, string flair, string flaircolor)
  90.         {
  91.             Console.WriteLine("SetFlair called (to: " + playername + "): " + flair + " - Class: " + flaircolor);
  92.         }
  93.  
  94.         public static bool HasIGFlair(string playername)
  95.         {
  96.             return false;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement