-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpeningMenu.cs
More file actions
249 lines (208 loc) · 8.9 KB
/
OpeningMenu.cs
File metadata and controls
249 lines (208 loc) · 8.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
using System.Runtime.CompilerServices;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization.Json;
using System.Net;
using MimeKit;
using MailKit.Net.Smtp;
using MailKit.Security;
using System.Security.Policy;
namespace TwitterSharp
{
public partial class OpeningMenu : Form
{
bool MessageBoxOpen = false;
static bool StartLoop = false;
static string OldTweetTime = "";
public OpeningMenu()
{
InitializeComponent();
double IntervalMinutes = 10;
var TimeSinceCheck = new System.Timers.Timer(1000 * 60 * IntervalMinutes);
TimeSinceCheck.Elapsed += OnTimedEvent;
TimeSinceCheck.AutoReset = true;
TimeSinceCheck.Enabled = true;
}
static Uri TwitterURI;
private async static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
if (StartLoop)
{
//Check Twitter
string TwitStr = "";
using(var TwitterClient = new HttpClient())
{
TwitterClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "Put Bearer token string that you received from twitter here");
TwitStr = await TwitterClient.GetStringAsync(TwitterURI);
}
bool InQuotes = false;
string TitleString = "";
string NewTweetTime = "";
string TweetText = "";
for (int i = 0; i < TwitStr.Length; ++i)
{
if(TweetText.Length > 0 && NewTweetTime.Length > 0)
{
break;
}
else if (InQuotes)
{
if (TitleString.Length > 0 && TwitStr[i] == '"' && TwitStr[i - 1] != '\\')
{
switch (TitleString)
{
case "created_at":
{
//Write Next quote body to TimeString
for (int ITime = i + 3; ITime < TwitStr.Length; ++ITime)
{
if (TwitStr[ITime] == '"' && TwitStr[ITime - 1] != '\\')
{
i = ITime;
break;
}
else
NewTweetTime += TwitStr[ITime];
}
}
break;
case "text":
{
//Write next quote body to TweetContent
for (int ITime = i + 3; ITime < TwitStr.Length; ++ITime)
{
if (TwitStr[ITime] == '"' && TwitStr[ITime - 1] != '\\')
{
i = ITime;
break;
}
else
TweetText += TwitStr[ITime];
}
}
break;
default:
{
}
break;
}
TitleString = "";
InQuotes = false;
}
else
{
TitleString += TwitStr[i];
}
}
else if (TwitStr[i] == '"' && !InQuotes)
{
InQuotes = true;
}
}
//Send Text by email User if new tweet is posted.
if(NewTweetTime != OldTweetTime)
{
OldTweetTime = NewTweetTime;
string[] TweetChunk = NewTweetTime.Split(' ');
//send text message via email.
MimeMessage TextAlert = new MimeMessage();
TextAlert.From.Add(new MailboxAddress (GlobalVars.TwitterHandle, "Put your email address here"));
TextAlert.To.Add(new MailboxAddress(GlobalVars.PhoneNumber + GetProviderAddress()));
TextAlert.Subject = GlobalVars.TwitterHandle;
string TrimmedTweetText = "";
if(TweetText.Length < 116)
{
TrimmedTweetText = TweetText;
}
else
{
TrimmedTweetText = TweetText.Substring(0, 115) + "...";
}
TextAlert.Body = new TextPart("plain")
{
Text = "<" + TweetChunk[3] + ">" + "\n" + TrimmedTweetText
};
SendMessage(TextAlert);
}
}
}
enum providers
{
VERIZON,
ATT,
TMOBILE,
SPRINT
}
string[] Providers = { "Verizon", "AT&T", "T-Mobile", "Sprint" };
static string GetProviderAddress()
{
string Address = "";
switch((providers)GlobalVars.Provider)
{
case providers.VERIZON: Address = "@vtext.com";break;
case providers.ATT: Address = "@txt.att.net"; break;
case providers.TMOBILE: Address = "@tmomail.net"; break;
case providers.SPRINT: Address = "@messaging.sprintpcs.com"; break;
}
return (Address);
}
public static void SendMessage(MimeMessage TextAlert)
{
using (var client = new SmtpClient())
{
//client.Connect(URI,Port,SecurityOptions)
client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
client.Authenticate("Put your email address here", GlobalVars.RandoDingen);
client.Send(TextAlert);
client.Disconnect(true);
}
}
private void buttonStart_Click(object sender, EventArgs e)
{
if (this.textNumber.Text.Length == 10 && this.textTwitter.Text.Length > 0)
{
GlobalVars.PhoneNumber = this.textNumber.Text;
GlobalVars.TwitterHandle = this.textTwitter.Text;
GlobalVars.Provider = this.comboBox1.SelectedIndex;
this.Visible = false;
StartLoop = true;
TwitterURI = new Uri("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + GlobalVars.TwitterHandle + "&count=1&trim_user=1");
}
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (!MessageBoxOpen)
{
MessageBoxOpen = true;
var Response = MessageBox.Show("Do you want to close TwitterSharp?", "TwitterSharp", MessageBoxButtons.YesNo);
MessageBoxOpen = false;
if (Response == System.Windows.Forms.DialogResult.Yes)
{
this.Close();
}
}
}
private void OpeningMenu_Load(object sender, EventArgs e)
{
this.textNumber.Text = GlobalVars.PhoneNumber;
this.textTwitter.Text = GlobalVars.TwitterHandle;
this.comboBox1.Items.AddRange(Providers);
if(GlobalVars.Provider < Providers.Length)
this.comboBox1.Text = (string)this.comboBox1.Items[GlobalVars.Provider];
else
this.comboBox1.Text = (string)this.comboBox1.Items[0];
}
}
}