-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twitter.cs
63 lines (52 loc) · 2.13 KB
/
Twitter.cs
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
using System;
using System.Threading;
using System.Collections;
using System.Globalization;
using Tweetinvi;
namespace LittleBabyDylan
{
public class Twitter
{
static DateTime pullTime;
public static void CheckForTweets()
{
Auth.SetUserCredentials("YOUR TWITTER API TOKENS HERE");
var user = User.GetAuthenticatedUser();
long dylanID = //User's specific Twitter account ID number;
var dylan = User.GetUserFromId(dylanID);
var timelineParameter = Timeline.CreateUserTimelineParameter();
timelineParameter.ExcludeReplies = true;
timelineParameter.IncludeRTS = false;
var lastTweets = dylan.GetUserTimeline(timelineParameter);
foreach (var tweet in lastTweets)
{
TimeSpan mins = TimeSpan.FromMinutes(4);
if (tweet.CreatedAt >= pullTime.Subtract(mins))
{
if (tweet.Text.Contains("r") || tweet.Text.Contains("R") || tweet.Text.Contains("l") || tweet.Text.Contains("L"))
{
var culture = new CultureInfo("en-US");
string editedTweet = tweet.Text.Replace("r", "w", true, culture).Replace("l", "w", true, culture);
if (!(string.IsNullOrEmpty(editedTweet)))
{
Tweet.FavoriteTweet(tweet.Id);
Tweet.PublishTweetInReplyTo("@" + tweet.CreatedBy.ScreenName + " " + editedTweet, tweet.Id);
Console.WriteLine("Tweeted: " + editedTweet);
}
}
}
else if (tweet.CreatedAt < pullTime)
{
break;
}
}
Console.WriteLine(DateTime.Now + " - Checking again...");
}
public static void RegisterPullTime()
{
pullTime = DateTime.Now;
//This sleeps for 20 minutes to give him time to tweet
Thread.Sleep(1200000);
}
}
}