Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using ultimatebot.core.classes;
- namespace ultimatebot.reddit.classes
- {
- class votingcore
- {
- public static event EventHandler<string> StatusTextChanged;
- public static int _votetype;
- public static string MainID { get; set; }
- public static string PostID { get; set; }
- public static string CommentID { get; set; }
- public static string Subreddit { get; set; }
- public string[] identify { get; set; }
- public static string VoteType
- {
- get
- {
- ///_votetype = votetype.SelectedIndex;
- return (_votetype == 0) ? "1" : "-1";
- }
- }
- /// <summary>
- /// Loop through accounts, and vote on specified post
- /// </summary>
- /// <param name="Posturl"></param>
- /// <returns></returns>
- public async Task main(string Posturl)
- {
- try
- {
- // set the url of the reddit post
- identify = Posturl.Split('/');
- // get voting designer and userclass
- voting voting = new voting();
- user user = new user();
- // started voting
- StatusTextChanged?.Invoke(this, $"Voting started");
- // get the subreddit, postid and commentid
- Subreddit = identify[4].ToString();
- PostID = "t3_" + identify[6].ToString();
- // check if it's a comment
- if (identify[8].ToString() != "")
- {
- CommentID = "t1_" + identify[8].ToString();
- }
- // loop through text file to get the account information
- string[] lines = File.ReadAllLines(redditcore.AccountsFile);
- List<string> newlines = new List<string>();
- foreach (string line in lines)
- {
- string[] temp = line.Split('|');
- redditcore.username = temp[0];
- redditcore.password = temp[1];
- // log the user in, run through accounts, complete actions then use next account
- await user.login();
- // we've logged in time to vote
- await vote();
- // logout and use the next account
- await user.logout();
- }
- // voting complete
- StatusTextChanged?.Invoke(this, $"Voting Completed");
- }
- catch (Exception ex)
- {
- // get the exception
- StatusTextChanged?.Invoke(this, ex.Message);
- }
- }
- /// <summary>
- /// Core functionality to vote, the post request
- /// </summary>
- /// <returns></returns>
- public async Task vote()
- {
- try
- {
- //MainID = (CommentID != "") ? CommentID : PostID;
- MainID = PostID;
- // Vote on the post, add the session id etc
- var postdata = new Dictionary<string, string>
- {
- { "id", MainID },
- { "dir", VoteType },
- { "vh", user.vh },
- { "isTrusted", "true" },
- { "r", Subreddit },
- { "uh", user.uh },
- { "renderstyle", "html" },
- };
- var content = new FormUrlEncodedContent(postdata);
- var response = await systemcore.client.PostAsync("https://www.reddit.com/api/vote?dir=" + VoteType + "&id=" + MainID + "&sr=" + Subreddit, content);
- var responseString = await response.Content.ReadAsStringAsync();
- // Status with account that upvoted
- StatusTextChanged?.Invoke(this, "Upvoted with account: " + redditcore.username);
- }
- catch (Exception ex)
- {
- // get the exception
- StatusTextChanged?.Invoke(this, "234" + ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement