Advertisement
Guest User

noir

a guest
Sep 23rd, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using ultimatebot.core.classes;
  10.  
  11. namespace ultimatebot.reddit.classes
  12. {
  13.     class votingcore
  14.     {
  15.         public static event EventHandler<string> StatusTextChanged;
  16.  
  17.         public static int _votetype;
  18.  
  19.         public static string MainID { get; set; }
  20.  
  21.         public static string PostID { get; set; }
  22.  
  23.         public static string CommentID { get; set; }
  24.  
  25.         public static string Subreddit { get; set; }
  26.  
  27.         public string[] identify { get; set; }
  28.  
  29.         public static string VoteType
  30.         {
  31.             get
  32.             {
  33.                 ///_votetype = votetype.SelectedIndex;
  34.                 return (_votetype == 0) ? "1" : "-1";
  35.             }
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Loop through accounts, and vote on specified post
  40.         /// </summary>
  41.         /// <param name="Posturl"></param>
  42.         /// <returns></returns>
  43.         public async Task main(string Posturl)
  44.         {
  45.             try
  46.             {
  47.                 // set the url of the reddit post
  48.                 identify = Posturl.Split('/');
  49.  
  50.                 // get voting designer and userclass
  51.                 voting voting = new voting();
  52.                 user user = new user();
  53.  
  54.                 // started voting
  55.                 StatusTextChanged?.Invoke(this, $"Voting started");
  56.  
  57.                 // get the subreddit, postid and commentid
  58.                 Subreddit = identify[4].ToString();
  59.                 PostID = "t3_" + identify[6].ToString();
  60.  
  61.                 // check if it's a comment
  62.                 if (identify[8].ToString() != "")
  63.                 {
  64.                     CommentID = "t1_" + identify[8].ToString();
  65.                 }
  66.  
  67.                 // loop through text file to get the account information
  68.                 string[] lines = File.ReadAllLines(redditcore.AccountsFile);
  69.                 List<string> newlines = new List<string>();
  70.                 foreach (string line in lines)
  71.                 {
  72.                     string[] temp = line.Split('|');
  73.                     redditcore.username = temp[0];
  74.                     redditcore.password = temp[1];
  75.  
  76.                     // log the user in, run through accounts, complete actions then use next account
  77.                     await user.login();
  78.  
  79.                     // we've logged in time to vote
  80.                     await vote();
  81.  
  82.                     // logout and use the next account
  83.                     await user.logout();
  84.                 }
  85.  
  86.                 // voting complete
  87.                 StatusTextChanged?.Invoke(this, $"Voting Completed");
  88.             }
  89.             catch (Exception ex)
  90.             {
  91.                 // get the exception
  92.                 StatusTextChanged?.Invoke(this, ex.Message);
  93.             }
  94.         }
  95.  
  96.         /// <summary>
  97.         /// Core functionality to vote, the post request
  98.         /// </summary>
  99.         /// <returns></returns>
  100.         public async Task vote()
  101.         {
  102.             try
  103.             {
  104.                 //MainID = (CommentID != "") ? CommentID : PostID;
  105.                 MainID = PostID;
  106.                 // Vote on the post, add the session id etc
  107.                 var postdata = new Dictionary<string, string>
  108.                 {
  109.                     { "id", MainID },
  110.                     { "dir", VoteType },
  111.                     { "vh", user.vh },
  112.                     { "isTrusted", "true" },
  113.                     { "r", Subreddit },
  114.                     { "uh", user.uh },
  115.                     { "renderstyle", "html" },
  116.                 };
  117.  
  118.                 var content = new FormUrlEncodedContent(postdata);
  119.                 var response = await systemcore.client.PostAsync("https://www.reddit.com/api/vote?dir=" + VoteType + "&id=" + MainID + "&sr=" + Subreddit, content);
  120.                 var responseString = await response.Content.ReadAsStringAsync();
  121.  
  122.                 // Status with account that upvoted
  123.                 StatusTextChanged?.Invoke(this, "Upvoted with account: " + redditcore.username);
  124.             }
  125.             catch (Exception ex)
  126.             {
  127.                 // get the exception
  128.                 StatusTextChanged?.Invoke(this, "234" + ex.Message);
  129.             }
  130.  
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement