Esempio n. 1
0
        public ListElement(TwitterList listElementData, Twitter tw)
        {
            this.Description = listElementData.Description;
            this.Id = listElementData.Id;
            this.IsPublic = (listElementData.Mode == "public");
            this.MemberCount = listElementData.MemberCount;
            this.Name = listElementData.Name;
            this.SubscriberCount = listElementData.SubscriberCount;
            this.Slug = listElementData.Slug;
            this.Nickname = listElementData.User.Name.Trim();
            this.Username = listElementData.User.ScreenName;
            this.UserId = listElementData.User.Id;

            this._tw = tw;
        }
Esempio n. 2
0
 private void TryAddView(ViewType viewType, ViewModelType viewModelType, TweetListType columnType, string searchTerm, string searchName, Decimal? existingSearchID = null, MetroTwitStatusBase Tweet = null, TwitterList ListItem = null)
 {
     if (viewType == ViewType.Column)
     {
         this.TryAddColumn(false, (TweetListViewModel)null, columnType, searchTerm, searchName, existingSearchID);
     }
     else
     {
         if (viewType != ViewType.Popup)
             return;
         if (InlinePopup.CurrentInline != null)
             InlinePopup.CurrentInline.Close();
         Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)this.MultiAccountifyToken((System.Enum)ViewModelMessages.SetNewTweetEntryOptionsContainer));
         UserControl view = (UserControl)null;
         switch (viewModelType)
         {
             case ViewModelType.TweetList:
                 if (columnType == TweetListType.Conversation)
                 {
                     string replyToScreenName = Tweet.InReplyToScreenName;
                     TweetListViewModel tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, replyToScreenName, string.Empty, new Decimal?(), false, Tweet, Tweet.ID)
                     {
                         EnableNotifications = false,
                         TitleBarVisible = false,
                         SettingsVisible = false
                     };
                     TweetListView tweetListView = new TweetListView();
                     tweetListView.DataContext = (object)tweetListViewModel;
                     view = (UserControl)tweetListView;
                     break;
                 }
                 else
                 {
                     TweetListViewModel tweetListViewModel;
                     if (Tweet != null && Tweet.AdUrls != null && !string.IsNullOrEmpty(Tweet.AdUrls.friendship_url))
                         tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, searchTerm, searchName, new Decimal?(), false, (MetroTwitStatusBase)null, new Decimal(0))
                         {
                             EnableNotifications = false,
                             AdFollowUrl = Tweet.AdUrls.friendship_url,
                             TitleBarVisible = false,
                             SettingsVisible = false
                         };
                     else
                         tweetListViewModel = new TweetListViewModel(Guid.Empty, columnType, this.TwitterAccountID, new MetroTwitColumn(), string.Empty, searchTerm, searchName, new Decimal?(), false, (MetroTwitStatusBase)null, new Decimal(0))
                         {
                             EnableNotifications = false,
                             TitleBarVisible = false,
                             SettingsVisible = false
                         };
                     tweetListViewModel.AllowPin = columnType != TweetListType.RetweetUsers;
                     ProfileView profileView = new ProfileView();
                     profileView.DataContext = (object)tweetListViewModel;
                     view = (UserControl)profileView;
                     break;
                 }
             case ViewModelType.Lists:
                 ListsView listsView = new ListsView();
                 listsView.DataContext = (object)new ListsViewModel(this.TwitterAccountID)
                 {
                     PopupTitle = "lists",
                     AllowPin = false
                 };
                 view = (UserControl)listsView;
                 break;
             case ViewModelType.Trends:
                 TrendsView trendsView1 = new TrendsView();
                 TrendsView trendsView2 = trendsView1;
                 TrendsViewModel trendsViewModel1 = new TrendsViewModel();
                 trendsViewModel1.TwitterAccountID = this.TwitterAccountID;
                 trendsViewModel1.AllowPin = false;
                 trendsViewModel1.PopupTitle = "twitter trends";
                 TrendsViewModel trendsViewModel2 = trendsViewModel1;
                 trendsView2.DataContext = (object)trendsViewModel2;
                 view = (UserControl)trendsView1;
                 break;
             case ViewModelType.ManageList:
                 ManageTwitterListView manageTwitterListView = new ManageTwitterListView();
                 manageTwitterListView.DataContext = (object)new ManageTwitterListViewModel(ListItem != null ? ListItem : (TwitterList)null, this.TwitterAccountID)
                 {
                     AllowPin = false,
                     PopupTitle = (ListItem != null ? string.Format("Edit {0}", (object)ListItem.Name) : "create new list")
                 };
                 view = (UserControl)manageTwitterListView;
                 break;
         }
         PopupService.ShowView(view);
     }
 }
Esempio n. 3
0
 public ListTimeline(TwitterAccount account, string listTitle, string tabName,TwitterList list,SettingData setting,Action<TimelineAction> timelineActionCallback, Action<RowAction> rowActionCallback)
     : base(account, listTitle, tabName, TimelineType.List,setting,timelineActionCallback,rowActionCallback)
 {
     this.TwitterList = list;
     Initialize(account,setting, timelineActionCallback, rowActionCallback);
 }
Esempio n. 4
0
 public async Task <List <Tweet> > GetListAsync(TwitterList list, string sinceId, int count = 10, int page = 0)
 {
     return(await GetHttpRequestAsync <List <Tweet> >(TwitterUrl.GetListUrl + "?list_id=" + list.id_str + "&since_id=" + sinceId + "&count=" + count + "&page=" + page));
 }
 public ManageTwitterListViewModel(TwitterList existingList, Decimal TwitterAccountID)
 {
   this.TwitterAccountID = TwitterAccountID;
   this.SaveCommand = new RelayCommand(new Action(this.Save));
   this.OKCommand = new RelayCommand(new Action(this.OK));
   this.skipInitialValidation = true;
   this.showForm = false;
   this.Description = string.Empty;
   this.UsersInThisList = new ObservableCollection<MetroTwitUser>();
   this.existingList = existingList;
   this.ShowAnimation = true;
   this.ProgressText = "Loading list...";
   this.countLock = new object();
   this.IsPublic = true;
   this.ShowMembersList = false;
   if (existingList != null)
   {
     this.Name = existingList.Name;
     this.Description = existingList.Description;
     this.IsPublic = existingList.IsPublic;
     Lists.MembersAsync(App.AppState.Accounts[this.TwitterAccountID].Tokens, (Decimal) existingList.Id, MetroTwitTwitterizer.GetListMembersOptions).ContinueWith((Action<Task<TwitterResponse<TwitterUserCollection>>>) (response =>
     {
       if (response.Result.Result != RequestResult.Success)
         return;
       System.Windows.Application.Current.Dispatcher.Invoke((Action) (() =>
       {
         foreach (User item_0 in (Collection<User>) response.Result.ResponseObject)
           this.UsersInThisList.Add(new MetroTwitUser(item_0)
           {
             AlreadyExistsInList = true,
             IsSelected = true
           });
         this.ShowAnimation = false;
         this.ShowForm = true;
         this.ShowMembersList = this.UsersInThisList.Count > 0;
       }));
     }));
   }
   else
   {
     this.ShowAnimation = false;
     this.ShowForm = true;
   }
 }
Esempio n. 6
0
 public static async Task SetListMembers(TwitterList list, IEnumerable <long> users)
 {
     await SetListDescription(list).ConfigureAwait(false);
     await SetListMembers(list.Id, users).ConfigureAwait(false);
 }
        public async Task <bool> DoListsTest(IUserSession session, List <int> testSeq)
        {
            var successStatus = true;
            var twList        = new TwitterList();

            try
            {
                // 1
                if (testSeq.Contains(1))
                {
                    ConsoleOutput.PrintMessage("10.1 Lists\\GetLists", ConsoleColor.Gray);

                    var lists1 = await session.GetLists(screenName : "NickHodgeMSFT");

                    if (lists1.OK)
                    {
                        foreach (var lst in lists1)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                            twList = lst;
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists1.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 2
                if (testSeq.Contains(2))
                {
                    ConsoleOutput.PrintMessage("10.2 Lists\\GetListTimeline", ConsoleColor.Gray);

                    var lists2 = await session.GetListTimeline(listId : twList.Id, slug : twList.Slug);

                    if (lists2.OK)
                    {
                        foreach (var tweet in lists2)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("From: {0} // Message: {1}", tweet.User.ScreenName, tweet.Text));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists2.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 3
                if (testSeq.Contains(3))
                {
                    ConsoleOutput.PrintMessage("10.3 Lists\\GetMyListsUserIsMemberOf - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;
                    var  listCount  = 0;

                    do
                    {
                        var lists3 =
                            await session.GetMyListsUserIsMemberOf(screenName : "shiftkey", cursor : nextcursor);

                        if (lists3.twitterFaulted)
                        {
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists3.twitterControlMessage);
                            successStatus = false;
                            break;
                        }
                        nextcursor = lists3.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists3.previous_cursor, lists3.next_cursor), ConsoleColor.Magenta);
                        foreach (var lst in lists3.lists)
                        {
                            listCount++;
                            ConsoleOutput.PrintMessage(
                                String.Format("ID: {5} // Slug: {0} // Name: {1} // {2} // {3} // {4}", lst.Slug, lst.Name, lst.CreatedTime, lst.MemberCount, lst.Mode, lst.Id));
                        }
                    } while (nextcursor != 0);

                    ConsoleOutput.PrintMessage(String.Format("List Membership Count: {0}",
                                                             listCount));
                }


                // 4
                if (testSeq.Contains(4))
                {
                    ConsoleOutput.PrintMessage("10.4 Lists\\GetMembersOnList - Cursored", ConsoleColor.Gray);

                    long nextcursor = -1;

                    do
                    {
                        var lists4 =
                            await session.GetMembersOnList(listId : 52908745, slug : "autechheads", ownerId : 800364, ownerScreenName : "NickHodgeMSFT", cursor : nextcursor);

                        if (lists4.twitterFaulted)
                        {
                            successStatus = false;
                            TwitterLiveFireUserAuth.PrintTwitterErrors(lists4.twitterControlMessage);
                            break;
                        }
                        nextcursor = lists4.next_cursor;
                        ConsoleOutput.PrintMessage(String.Format("Previous cursor: {0} Next cursor: {1}",
                                                                 lists4.previous_cursor, lists4.next_cursor), ConsoleColor.Magenta);
                        foreach (var lusr in lists4.users)
                        {
                            ConsoleOutput.PrintMessage(
                                String.Format("UserID: {0} // ScreenName: {1}", lusr.UserId, lusr.ScreenName));
                        }
                    } while (nextcursor != 0);
                }


                // 5
                if (testSeq.Contains(5))
                {
                    ConsoleOutput.PrintMessage("10.5 Lists\\IsUserOnList", ConsoleColor.Gray);
                    var testScreenName = "coatsy";
                    var lists5         =
                        await session.IsUserOnList(screenName : testScreenName, listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT");

                    if (lists5.OK)
                    {
                        if (lists5.ScreenName == null)
                        {
                            ConsoleOutput.PrintMessage(String.Format("UserID: {0} is NOT ON the list", testScreenName));
                        }
                        else
                        {
                            ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is on the list", lists5.ScreenName));
                        }
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists5.twitterControlMessage);
                        successStatus = false;
                    }
                }

                // 6
                if (testSeq.Contains(6))
                {
                    ConsoleOutput.PrintMessage("10.6 Lists\\AddUserToMyList", ConsoleColor.Gray);
                    var testScreenName = "shiftkey";
                    var lists6         =
                        await session.AddUserToMyList(listId : 52908745, userIdToAdd : 14671135, screenNameToAdd : "shiftkey");

                    if (lists6.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                }


                // 7
                if (testSeq.Contains(7))
                {
                    ConsoleOutput.PrintMessage("10.7 Lists\\DeleteUsersFromList", ConsoleColor.Gray);
                    var testScreenName  = "coatsy";
                    var testScreenNames = new List <string> {
                        testScreenName
                    };

                    var lists7 =
                        await session.DeleteUsersFromList(listId : 52908745, ownerId : 800364, ownerScreenName : "NickHodgeMSFT", screenNames : testScreenNames);

                    if (lists7.Status)
                    {
                        ConsoleOutput.PrintMessage(String.Format("ScreenName: {0} is added the list", testScreenName));
                    }
                    else
                    {
                        TwitterLiveFireUserAuth.PrintTwitterErrors(lists7.twitterControlMessage);
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleOutput.PrintError(e.ToString());
                return(false);
            }
            return(successStatus);
        }
        public static void GetMemberships()
        {
            TwitterListCollection lists = TwitterList.GetMemberships(Configuration.GetTokens(), userName).ResponseObject;

            Assert.IsNotNull(lists);
        }
        public void Show()
        {
            TwitterList list = TwitterList.Show(Configuration.GetTokens(), listName, null).ResponseObject;

            Assert.IsNotNull(list);
        }
Esempio n. 10
0
        public void Show()
        {
            var list = TwitterList.Show(Configuration.GetTokens(), listName, null);

            Assert.IsNotNull(list.ResponseObject, list.ErrorMessage);
        }
Esempio n. 11
0
 public static IEnumerable <UserViewModel> GetListMembers(TwitterList list)
 {
     return(GetListMembers(list.User.ScreenName, list.Name));
 }
Esempio n. 12
0
        private static void Main()
        {
            // Let's try literally try/catching the whole thing
            try
            {
                // Project requirements:
                // 1. TweetInvi library installed from NuGet - Install-Package TweetInvi
                // 2. Setup Twitter application to get a workable CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET (https://apps.twitter.com)
                // 3. Setup incoming Slack webhook to a channel in the group you want, to display the information you pass
                // 4. Collect credentials and pass them as environment variables; either using -e and docker run, or into the docker-compose file included.
                // That's it!

                Credentials creds = new Credentials();
                creds.ConsumerKey       = Environment.GetEnvironmentVariable("ConsumerKey");
                creds.ConsumerSecret    = Environment.GetEnvironmentVariable("ConsumerSecret");
                creds.AccessToken       = Environment.GetEnvironmentVariable("AccessToken");
                creds.AccessTokenSecret = Environment.GetEnvironmentVariable("AccessTokenSecret");
                creds.Channel           = Environment.GetEnvironmentVariable("Channel");
                creds.Username          = Environment.GetEnvironmentVariable("Username");
                creds.EmojiIcon         = Environment.GetEnvironmentVariable("EmojiIcon");
                creds.WebhookURL        = Environment.GetEnvironmentVariable("WebhookURL");

                // Load credentials into Tweetinvi auth.
                Auth.SetUserCredentials(creds.ConsumerKey, creds.ConsumerSecret, creds.AccessToken, creds.AccessTokenSecret);
                var authenticatedUser = Tweetinvi.User.GetAuthenticatedUser();

                // Enable Automatic RateLimit handling; not too sure what this does to be honest, but is recommended by the Tweetinvi dev.
                RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackAndAwait;

                // Get list membership info
                var listOwner        = Environment.GetEnvironmentVariable("ListOwner");
                var listToTrack      = Environment.GetEnvironmentVariable("ListToTrack");
                var chosenList       = TwitterList.GetExistingList(listToTrack, listOwner);
                var allUsersFromList = chosenList.GetMembers();

                // Attempting to make a stream of the users. Works, but gives tweets @ too.
                var tweetStream = Tweetinvi.Stream.CreateFilteredStream();
                foreach (var user in allUsersFromList)
                {
                    tweetStream.AddFollow(user);
                }

                // Initialize and say hello.
                SayHello(creds);

                // Write how many users you got to start with.
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(initString + "\n");
                Console.WriteLine("Using list: {0}", chosenList.FullName);
                Console.WriteLine("Have loaded {0} users into the stream...", tweetStream.FollowingUserIds.Count);

                // Start the stream; set a couple params.
                tweetStream.MatchOn       = Tweetinvi.Streaming.MatchOn.Follower;
                tweetStream.StallWarnings = true;

                tweetStream.MatchingTweetReceived += async(succsender, succargs) =>
                {
                    // Something broke in the actual setting to match followers, so doublecheck here.
                    if (succargs.MatchOn == tweetStream.MatchOn)
                    {
                        string tweetText = (succargs.Tweet.Url + " - " + DateTime.UtcNow).ToString();

                        // Created and then serialize JSON payload, which Slack expects. Pass as StringContent to HttpReader.
                        dynamic jsonPayload = new JObject();
                        jsonPayload.text       = tweetText;
                        jsonPayload.channel    = creds.Channel;
                        jsonPayload.username   = creds.Username;
                        jsonPayload.icon_emoji = creds.EmojiIcon;

                        var stringContent = new StringContent(JsonConvert.SerializeObject(jsonPayload), Encoding.UTF8, "application/json");

                        HttpResponseMessage response = await httpClient.PostAsync(creds.WebhookURL, stringContent);

                        HttpContent responseContent = response.Content;
                        using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
                        {
                            // Write the response output to console. Debug mode.
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine(await reader.ReadToEndAsync() + " - " + DateTime.UtcNow + " - tweet from " + succargs.Tweet.CreatedBy.ScreenName + " matched and sent");
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("no - " + DateTime.UtcNow + " - tweet from " + succargs.Tweet.CreatedBy.ScreenName + " rejected for not matching");
                    }
                };

                // Start stream if it's not running; attempt to get it to auto-restart
                do
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(DateTime.UtcNow + " - Starting stream...\n");
                    tweetStream.StartStreamMatchingAllConditions();
                    Console.WriteLine(DateTime.UtcNow + " - Stream stopped...\n");
                } while (tweetStream.StreamState != Tweetinvi.Models.StreamState.Running);
            }

            catch (Exception e)
            {
                Console.WriteLine("{0}", e);
                File.WriteAllText(@"log.txt", DateTime.UtcNow + e.ToString());
            }

            Console.WriteLine(DateTime.UtcNow + "Main function ending, even though this shouldn't happen!");
        }