View difference between Paste ID: pYMCtFk3 and h6Dthvuh
SHOW: | | - or go back to the newest paste.
1
Reddit DNC vote bot, this is just a function, that is used by the bigger part of the program called 'Ultimate'
2
3
using System;
4
using System.Collections.Generic;
5
using System.ComponentModel;
6
using System.Data;
7
using System.Drawing;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
using System.Windows.Forms;
12
using System.Net;
13
using System.IO;
14
using reddit.Properties;
15
using System.Collections.Specialized;
16
using System.Net.Http;
17
using Newtonsoft.Json;
18
using System.Web.Script.Serialization;
19
using System.Web;
20
using System.Text.RegularExpressions;
21
22
        public class Rootobject
23
        {
24
            public Json json { get; set; }
25
        }
26
27
        public class Json
28
        {
29
            public object[] errors { get; set; }
30
            public Data data { get; set; }
31
        }
32
33
        public class Data
34
        {
35
            public bool need_https { get; set; }
36
            public string modhash { get; set; }
37
            public string cookie { get; set; }
38
        }
39
40
        private string _mainid;
41
        private string _postid;
42
        private string _commentid;
43
        private int _votetype;
44
        private string _subreddit;
45
        private string _uh;
46
        private string _vh;
47
        private string _username;
48
        private string _password;
49
        private string[] _identify;
50
51
        private CookieContainer cookieContainer = new CookieContainer();
52
        private HttpClientHandler clienthandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true, CookieContainer = new CookieContainer() };
53
        private readonly HttpClient client;
54
55
        private string connection { get; set; }
56
        private string DatabaseHost { get; } = Settings.Default["databasehost"].ToString();
57
        private string DatabaseUser { get; } = Settings.Default["databaseusername"].ToString();
58
        private string DatabasePassword { get; } = Settings.Default["databasepassword"].ToString();
59
        private string DatabaseName { get; } = Settings.Default["databasename"].ToString();
60
61
        public string MainID
62
        {
63
            get { return _mainid; }
64
            set { this._mainid = value; }
65
        }
66
67
        public string PostID
68
        {
69
            get { return _postid; }
70
            set { this._postid = value; }
71
        }
72
73
        public string CommentID
74
        {
75
            get { return _commentid; }
76
            set { this._commentid = value; }
77
        }
78
79
        public string VoteType
80
        {
81
            get
82
            {
83
                this.Invoke(new Action(() =>
84
                {
85
                    _votetype = votetype.SelectedIndex;
86
                }));
87
                return ( _votetype == 0) ? "1" : "-1";
88
            }
89
        }
90
91
        public string Subreddit
92
        {
93
            get { return _subreddit; }
94
            set { this._subreddit = value; }
95
        }
96
97
        public string uh
98
        {
99
            get { return _uh; }
100
            set { this._uh = value; }
101
        }
102
103
        public string vh
104
        {
105
            get { return _vh; }
106
            set { this._vh = value; }
107
        }
108
109
        public string username
110
        {
111
            get { return _username; }
112
            set { this._username = value; }
113
        }
114
115
        public string password
116
        {
117
            get { return _password; }
118
            set { this._password = value; }
119
        }
120
121
        public string accounts
122
        {
123
            get { return Settings.Default["accounts"].ToString(); }
124
        }
125
126
        public string[] identify
127
        {
128
            get
129
            {
130
                if (_identify == null)
131
                {
132
                    _identify = url.Text.Split('/');
133
                }
134
                return _identify;
135
            }
136
        }
137
138
        public voting()
139
        {
140
            InitializeComponent();
141
142
            votetype.SelectedIndex = 0;
143
            client = new HttpClient(clienthandler);
144
            client.DefaultRequestHeaders.Add("Origin", "https://www.reddit.com");
145
            client.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
146
            client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
147
            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
148
            client.DefaultRequestHeaders.Add("Accept-Charset", "ISO-8859-1");
149
        }
150
        
151
152
        private async Task core()
153
        {
154
            try
155
            {
156
                // started voting 
157
                this.Invoke(new Action(() =>
158
                {
159
                    status.Text = "Voting Started";
160
                    status.ForeColor = System.Drawing.Color.Green;
161
                }));
162
163
                // get the subreddit, postid and commentid
164
                Subreddit = identify[4].ToString();
165
                PostID = "t3_" + identify[6].ToString();
166
                if (identify[8].ToString() != "")
167
                {
168
                    CommentID = "t1_" + identify[8].ToString();
169
                }
170
171
                // loop through text file to get the account information
172
                string[] lines = File.ReadAllLines(accounts);
173
                List<string> newlines = new List<string>();
174
                foreach (string line in lines)
175
                {
176
                    string[] temp = line.Split('|');
177
                    username = temp[0];
178
                    password = temp[1];
179
180
                    // log the user in, run through accounts, complete actions then use next account
181
                    await login();
182
183
                    // we've logged in time to vote
184
                    await vote();
185
186
                    // logout and use the next account
187
                    await logout();
188
                }
189
190
                // completed voting
191
                this.Invoke(new Action(() =>
192
                {
193
                    // Status update
194
                    status.Text = "Voting Completed";
195
                    status.ForeColor = System.Drawing.Color.Green;
196
                }));
197
            }
198
            catch (Exception ex)
199
            {
200
                this.Invoke(new Action(() =>
201
                {
202
                    status.Text = "Error: " + ex.Message;
203
                    status.ForeColor = System.Drawing.Color.Red;
204
                }));
205
            }
206
        }
207
208
        private async Task login()
209
        {
210
            // A simple login to store user information
211
            var postdata = new Dictionary<string, string>
212
            {
213
                { "op", "login" },
214
                { "user", username},
215
                { "passwd", password},
216
                { "api_type", "json"},
217
            };
218
219
            var content = new FormUrlEncodedContent(postdata);
220
            var response = await client.PostAsync("https://www.reddit.com/api/login/" + username, content);
221
222
            var responseString = await response.Content.ReadAsStringAsync();
223
224
            var serializer = new JavaScriptSerializer();
225
            var jsonObject = serializer.Deserialize<Rootobject>(responseString);
226
            uh = jsonObject.json.data.modhash;
227
228
            // get the voting hash too
229
            await getHash();
230
        }
231
232
        private async Task logout()
233
        {
234
            // A simple logout so we can use multiple accounts
235
            var postdata = new Dictionary<string, string>
236
            {
237
                { "uh", uh},
238
                { "top", "off"},
239
            };
240
            var content = new FormUrlEncodedContent(postdata);
241
            var response = await client.PostAsync("https://www.reddit.com/logout", content);
242
        }
243
244
245
        private async Task getHash()
246
        {
247
            var response = await client.GetStringAsync("https://www.reddit.com/");
248
            string vhash = new Regex(Regex.Unescape(@"""vote_hash"": ""(.*?)""")).Match(response).Groups[1].ToString();
249
            vh = vhash;
250
        }
251
252
        private async Task vote()
253
        {
254
            try
255
            {
256
                //MainID = (CommentID != "") ? CommentID : PostID;
257
                MainID = PostID;
258
                // Vote on the post, add the session id etc
259
                // A simple login to store user information
260
                var postdata = new Dictionary<string, string>
261
                {
262
                    { "id", MainID },
263
                    { "dir", VoteType },
264
                    { "vh", vh },
265
                    { "isTrusted", "true" },
266
                    { "r", Subreddit },
267
                    { "uh", uh },
268
                    { "renderstyle", "html" },
269
                };
270
271
                var content = new FormUrlEncodedContent(postdata);
272
                var response = await client.PostAsync("https://www.reddit.com/api/vote?dir=" + VoteType + "&id=" + MainID + "&sr=" + Subreddit, content);
273
                var responseString = await response.Content.ReadAsStringAsync();
274
275
                this.Invoke(new Action(() =>
276
                {
277
                    // Status update
278
                    status.Text = "Upvoted with account: " + username;
279
                    status.ForeColor = System.Drawing.Color.Green;
280
                }));
281
            }
282
            catch( Exception ex )
283
            {
284
                this.Invoke(new Action(() =>
285
                {
286
                    // Status update
287
                    status.Text = "Error: " + ex.Message;
288
                    status.ForeColor = System.Drawing.Color.Red;
289
                }));
290
            }
291
292
        }