Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Reddit DNC vote bot, this is just a function, that is used by the bigger part of the program called 'Ultimate'
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net;
- using System.IO;
- using reddit.Properties;
- using System.Collections.Specialized;
- using System.Net.Http;
- using Newtonsoft.Json;
- using System.Web.Script.Serialization;
- using System.Web;
- using System.Text.RegularExpressions;
- public class Rootobject
- {
- public Json json { get; set; }
- }
- public class Json
- {
- public object[] errors { get; set; }
- public Data data { get; set; }
- }
- public class Data
- {
- public bool need_https { get; set; }
- public string modhash { get; set; }
- public string cookie { get; set; }
- }
- private string _mainid;
- private string _postid;
- private string _commentid;
- private int _votetype;
- private string _subreddit;
- private string _uh;
- private string _vh;
- private string _username;
- private string _password;
- private string[] _identify;
- private CookieContainer cookieContainer = new CookieContainer();
- private HttpClientHandler clienthandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true, CookieContainer = new CookieContainer() };
- private readonly HttpClient client;
- private string connection { get; set; }
- private string DatabaseHost { get; } = Settings.Default["databasehost"].ToString();
- private string DatabaseUser { get; } = Settings.Default["databaseusername"].ToString();
- private string DatabasePassword { get; } = Settings.Default["databasepassword"].ToString();
- private string DatabaseName { get; } = Settings.Default["databasename"].ToString();
- public string MainID
- {
- get { return _mainid; }
- set { this._mainid = value; }
- }
- public string PostID
- {
- get { return _postid; }
- set { this._postid = value; }
- }
- public string CommentID
- {
- get { return _commentid; }
- set { this._commentid = value; }
- }
- public string VoteType
- {
- get
- {
- this.Invoke(new Action(() =>
- {
- _votetype = votetype.SelectedIndex;
- }));
- return ( _votetype == 0) ? "1" : "-1";
- }
- }
- public string Subreddit
- {
- get { return _subreddit; }
- set { this._subreddit = value; }
- }
- public string uh
- {
- get { return _uh; }
- set { this._uh = value; }
- }
- public string vh
- {
- get { return _vh; }
- set { this._vh = value; }
- }
- public string username
- {
- get { return _username; }
- set { this._username = value; }
- }
- public string password
- {
- get { return _password; }
- set { this._password = value; }
- }
- public string accounts
- {
- get { return Settings.Default["accounts"].ToString(); }
- }
- public string[] identify
- {
- get
- {
- if (_identify == null)
- {
- _identify = url.Text.Split('/');
- }
- return _identify;
- }
- }
- public voting()
- {
- InitializeComponent();
- votetype.SelectedIndex = 0;
- client = new HttpClient(clienthandler);
- client.DefaultRequestHeaders.Add("Origin", "https://www.reddit.com");
- client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
- client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
- client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
- client.DefaultRequestHeaders.Add("Accept-Charset", "ISO-8859-1");
- }
- private async Task core()
- {
- try
- {
- // started voting
- this.Invoke(new Action(() =>
- {
- status.Text = "Voting Started";
- status.ForeColor = System.Drawing.Color.Green;
- }));
- // get the subreddit, postid and commentid
- Subreddit = identify[4].ToString();
- PostID = "t3_" + identify[6].ToString();
- if (identify[8].ToString() != "")
- {
- CommentID = "t1_" + identify[8].ToString();
- }
- // loop through text file to get the account information
- string[] lines = File.ReadAllLines(accounts);
- List<string> newlines = new List<string>();
- foreach (string line in lines)
- {
- string[] temp = line.Split('|');
- username = temp[0];
- password = temp[1];
- // log the user in, run through accounts, complete actions then use next account
- await login();
- // we've logged in time to vote
- await vote();
- // logout and use the next account
- await logout();
- }
- // completed voting
- this.Invoke(new Action(() =>
- {
- // Status update
- status.Text = "Voting Completed";
- status.ForeColor = System.Drawing.Color.Green;
- }));
- }
- catch (Exception ex)
- {
- this.Invoke(new Action(() =>
- {
- status.Text = "Error: " + ex.Message;
- status.ForeColor = System.Drawing.Color.Red;
- }));
- }
- }
- private async Task login()
- {
- // A simple login to store user information
- var postdata = new Dictionary<string, string>
- {
- { "op", "login" },
- { "user", username},
- { "passwd", password},
- { "api_type", "json"},
- };
- var content = new FormUrlEncodedContent(postdata);
- var response = await client.PostAsync("https://www.reddit.com/api/login/" + username, content);
- var responseString = await response.Content.ReadAsStringAsync();
- var serializer = new JavaScriptSerializer();
- var jsonObject = serializer.Deserialize<Rootobject>(responseString);
- uh = jsonObject.json.data.modhash;
- // get the voting hash too
- await getHash();
- }
- private async Task logout()
- {
- // A simple logout so we can use multiple accounts
- var postdata = new Dictionary<string, string>
- {
- { "uh", uh},
- { "top", "off"},
- };
- var content = new FormUrlEncodedContent(postdata);
- var response = await client.PostAsync("https://www.reddit.com/logout", content);
- }
- private async Task getHash()
- {
- var response = await client.GetStringAsync("https://www.reddit.com/");
- string vhash = new Regex(Regex.Unescape(@"""vote_hash"": ""(.*?)""")).Match(response).Groups[1].ToString();
- vh = vhash;
- }
- private async Task vote()
- {
- try
- {
- //MainID = (CommentID != "") ? CommentID : PostID;
- MainID = PostID;
- // Vote on the post, add the session id etc
- // A simple login to store user information
- var postdata = new Dictionary<string, string>
- {
- { "id", MainID },
- { "dir", VoteType },
- { "vh", vh },
- { "isTrusted", "true" },
- { "r", Subreddit },
- { "uh", uh },
- { "renderstyle", "html" },
- };
- var content = new FormUrlEncodedContent(postdata);
- var response = await client.PostAsync("https://www.reddit.com/api/vote?dir=" + VoteType + "&id=" + MainID + "&sr=" + Subreddit, content);
- var responseString = await response.Content.ReadAsStringAsync();
- this.Invoke(new Action(() =>
- {
- // Status update
- status.Text = "Upvoted with account: " + username;
- status.ForeColor = System.Drawing.Color.Green;
- }));
- }
- catch( Exception ex )
- {
- this.Invoke(new Action(() =>
- {
- // Status update
- status.Text = "Error: " + ex.Message;
- status.ForeColor = System.Drawing.Color.Red;
- }));
- }
- }
Add Comment
Please, Sign In to add comment