Exemplo n.º 1
0
 public void StartStream()
 {
     FilteredStream = Stream.CreateFilteredStream();
     FilteredStream.AddTrack(Hashtag);
     FilteredStream.MatchingTweetReceived += (sender, args) => RaiseTweetAdded(args.Tweet);
     FilteredStream.StartStreamMatchingAllConditionsAsync();
 }
Exemplo n.º 2
0
        public async Task StartStreamAsync()
        {
            if (_isFake)
            {
                _stop = false;
                return;
            }

            await _filteredStream.StartStreamMatchingAllConditionsAsync();
        }
Exemplo n.º 3
0
        public static async Task Init(IServiceProvider service)
        {
            _serviceProvider = service;

            _stream = Stream.CreateFilteredStream();
            _stream.AddTrack(_searchTerm);

            _stream.MatchingTweetReceived += TweetRecieved;
            await _stream.StartStreamMatchingAllConditionsAsync();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Start a stream, filtering ony the keyword and only English language tweets.
        /// </summary>
        protected void StartStream(string keyword)
        {
            stream = Stream.CreateFilteredStream();
            stream.AddTrack(keyword);
            stream.MatchingTweetReceived += (sender, args) =>
            {
                if (args.Tweet.Language == Language.English)
                {
                    UpdateFdg(args.Tweet.Text);
                }
            };

            stream.StartStreamMatchingAllConditionsAsync();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Starts a Twitter Stream based on the specified geographic coordinates and the now playing hash tag
        /// </summary>
        /// <param name="latitude1">Latitude of user location (bottom_left)</param>
        /// <param name="longitude1">Longitude of user location (bottom_left)</param>
        /// <param name="latitude2">Latitude of user location (top_right)</param>
        /// <param name="longitude2">Longitude of user location (top_right)</param>
        public static async Task StartStream(double latitude1, double longitude1, double latitude2, double longitude2)
        {
            // Setup Twitter credentials
            TweetinviUtilities.SetTwitterCredentials();

            // If the stream does not exists...
            if (_stream == null)
            {
                //...then it is started

                // Create a filtered stream
                _stream = Stream.CreateFilteredStream();
                _stream.AddTrack(Constants.NOWPLAYING_HASHTAG); // Lookup for nowplaying hashtag

                // OPTIONAL: if you want to see how the feed is updated really quick, just comment the following line of code.
                //           You will see the effect of "infinite scroll" in the client
                _stream.AddLocation(
                    new Coordinates(latitude1, longitude1),
                    new Coordinates(latitude2, longitude2)); // Lookup in the specific geographic coordinates

                // OPTIONAL: if you want to filter the stream just for a specific user, uncomment the following line of code
                //_stream.AddFollow(2834545563);

                // Event that handles a matching tweet
                _stream.MatchingTweetReceived += async(sender, args) =>
                {
                    // A OEmbed tweet is sent to the client
                    IOEmbedTweet embedTweet = Tweet.GetOEmbedTweet(args.Tweet);
                    await _context.Clients.All.updateFeed(embedTweet);
                };

                // Start the stream matching all conditions
                await _stream.StartStreamMatchingAllConditionsAsync();
            }
            else
            {
                //... otherwise resume it
                _stream.ResumeStream();
            }
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var consumerKey    = Environment.GetEnvironmentVariable("TwitterConsumerKey");
            var consumerSecret = Environment.GetEnvironmentVariable("TwitterConsumerSecret");
            var accessKey      = Environment.GetEnvironmentVariable("TwitterAccessKey");
            var accessSecret   = Environment.GetEnvironmentVariable("TwitterAccessSecret");

            var credentials = new TwitterCredentials(consumerKey, consumerSecret, accessKey, accessSecret);

            Auth.SetCredentials(credentials);

            _filteredStream = Stream.CreateFilteredStream();

            if (!string.IsNullOrEmpty(_attribute.Filter))
            {
                _filteredStream.AddTrack(_attribute.Filter);
            }

            if (!string.IsNullOrWhiteSpace(_attribute.User))
            {
                _filteredStream.AddFollow(User.GetUserFromScreenName(_attribute.User));
            }

            _filteredStream.MatchingTweetReceived += async(obj, tweetEvent) =>
            {
                var triggerData = new TriggeredFunctionData
                {
                    TriggerValue = tweetEvent
                };
                await Executor.TryExecuteAsync(triggerData, CancellationToken.None);
            };

            _filteredStream.DisconnectMessageReceived += (obj, disconnectEvent) =>
            {
                _filteredStream.StopStream();
            };

            await _filteredStream.StartStreamMatchingAllConditionsAsync();
        }
Exemplo n.º 7
0
        private async void MinuteTimerEventHandler(object sender, System.Timers.ElapsedEventArgs e)
        {
            CheckTwitterFollows();

            if (_twitterStream == null)
            {
                return;
            }
            switch (_twitterStream.StreamState)
            {
            case StreamState.Running:
                break;

            case StreamState.Pause:
                _twitterStream.ResumeStream();
                break;

            case StreamState.Stop:
                await _twitterStream.StartStreamMatchingAllConditionsAsync();

                break;
            }
        }
Exemplo n.º 8
0
        public static async Task RegisterFilteredStreamEventsAsync(string[] users, string[] trackKeywords)
        {
            if (users == null)
            {
                log.Fatal("No Users Are Being Followed.  Server is useless.");
                return;
            }

            try
            {
                stream = Stream.CreateFilteredStream();
                foreach (string userName in users)
                {
                    IUserIdentifier myUser = Tweetinvi.User.GetUserFromScreenName(userName);
                    stream.AddFollow(myUser);
                }
                if (trackKeywords != null)
                {
                    foreach (string keyword in trackKeywords)
                    {
                        stream.AddTrack(keyword);
                    }
                }
                stream.MatchingTweetReceived     += StreamEventCallbackManager.FilteredStream_MatchingTweetReceived;
                stream.StreamStopped             += StreamEventCallbackManager.Stream_Stopped;
                stream.DisconnectMessageReceived += StreamEventCallbackManager.Stream_Disconnected;
                stream.StreamPaused  += StreamEventCallbackManager.Stream_Paused;
                stream.StreamResumed += StreamEventCallbackManager.Stream_Resumed;
                await stream.StartStreamMatchingAllConditionsAsync();

                log.Info("Now Listening To Stream Events.");
            }
            catch (Exception e)
            {
                log.Fatal("FAILED TO REGISTER TO STREAM EVENTS!", e);
            }
        }
        public static async Task StartStream()
        {
            var consumerKey       = Environment.GetEnvironmentVariable("TWITTER_CONSUMER_KEY", EnvironmentVariableTarget.User);
            var consumerSecret    = Environment.GetEnvironmentVariable("TWITTER_CONSUMER_SECRET", EnvironmentVariableTarget.User);
            var accessToken       = Environment.GetEnvironmentVariable("TWITTER_ACCESS_TOKEN", EnvironmentVariableTarget.User);
            var accessTokenSecret = Environment.GetEnvironmentVariable("TWITTER_ACCESS_TOKEN_SECRET", EnvironmentVariableTarget.User);

            var credentials = Auth.SetUserCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);

            if (_stream == null)
            {
                _stream = Stream.CreateFilteredStream(credentials);
                _stream.AddTrack("#WorldCup");
                _stream.MatchingTweetReceived += async(sender, args) =>
                {
                    await HubContext.Clients.All.SendTweet(args.Tweet.FullText);
                };
                await _stream.StartStreamMatchingAllConditionsAsync();
            }
            else
            {
                _stream.ResumeStream();
            }
        }
Exemplo n.º 10
0
        public void CreateCommands()
        {
            var CService = _client.GetService <CommandService>();

            IFilteredStream FilteredStream = Tweetinvi.Stream.CreateFilteredStream();
            ISampleStream   SampleStream   = Tweetinvi.Stream.CreateSampleStream();

            CService.CreateCommand("StreamState")
            .Description("Gets the states of the streams")
            .Do(async(e) =>
            {
                await e.Channel.SendMessage("```Sample Stream: " + SampleStream.StreamState + Environment.NewLine + "Filtered Stream: " + FilteredStream.StreamState + "```");
            });

            CService.CreateCommand("PurgeStreams")
            .Alias("Kill", "Stop", "PS")
            .Description("Hopefully stops the stream")
            .Do(async(e) =>
            {
                FilteredStream.StopStream();
                SampleStream.StopStream();
                FilteredStream.ClearTracks();
                await e.Channel.SendMessage("```Sample Stream: " + SampleStream.StreamState + Environment.NewLine + "Filtered Stream: " + FilteredStream.StreamState + "```");
            });

            CService.CreateCommand("StopSampleStream")
            .Description("Stops all sample streams")
            .Do(async(e) =>
            {
                SampleStream.StopStream();
                await e.Channel.SendMessage("```Sample Stream: " + SampleStream.StreamState + Environment.NewLine + "Filtered Stream: " + FilteredStream.StreamState + "```");
            });

            CService.CreateCommand("StopFilteredStream")
            .Description("Stops all Filtered streams")
            .Do(async(e) =>
            {
                FilteredStream.StopStream();
                await e.Channel.SendMessage("```Sample Stream: " + SampleStream.StreamState + Environment.NewLine + "Filtered Stream: " + FilteredStream.StreamState + "```");
            });

            CService.CreateCommand("Track")
            .Description("Tracks a twitter User Either from their ID or Handle")
            .Parameter("User", ParameterType.Unparsed)
            .Description("Tracks a Twitter User")
            .Do(async(e) =>
            {
                if (Regex.IsMatch(e.GetArg("User"), @"-?\d+(\.\d+)?"))
                {
                    long User    = Convert.ToInt64(e.GetArg("User"));
                    IUser Target = Tweetinvi.User.GetUserFromId(Convert.ToInt64(e.GetArg("User")));

                    await e.Channel.SendMessage("Tracking " + Tweetinvi.User.GetUserFromId(Convert.ToInt64(e.GetArg("User"))));

                    FilteredStream.AddFollow(User);
                    FilteredStream.MatchingTweetReceived += (sender, args) =>
                    {
                        e.Channel.SendMessage(Target + " " + args.Tweet);
                    };
                    FilteredStream.StreamStopped += (sender, args) =>
                    {
                        var Exception         = args.Exception;
                        var DisconnectMessage = args.DisconnectMessage;
                        e.Channel.SendMessage("Filtered stream ended exception: " + Exception + " Disconnect message: " + DisconnectMessage);
                    };
                    await FilteredStream.StartStreamMatchingAllConditionsAsync();
                }
                else
                {
                    var Target = Tweetinvi.User.GetUserFromScreenName(e.GetArg("User"));

                    await e.Channel.SendMessage("Tracking " + Tweetinvi.User.GetUserFromScreenName(e.GetArg("User")));

                    FilteredStream.AddFollow(Target);
                    FilteredStream.MatchingTweetReceived += (sender, args) =>
                    {
                        Console.WriteLine("Found Tweet");
                        e.Channel.SendMessage(e.GetArg("User") + " Tweeted " + args.Tweet);
                    };
                    await FilteredStream.StartStreamMatchingAllConditionsAsync();
                }
            });

            CService.CreateCommand("Spam")
            .Alias("Havoc", "Anton", "Cancer")
            .Description("Initializes a socalled sample stream which returns 1% of all public tweets Discord will not show them all because of RateLimits.")
            .Do(async(e) =>
            {
                if (e.User.ServerPermissions.ManageServer == true)
                {
                    SampleStream.TweetReceived += (sender, args) =>
                    {
                        e.Channel.SendMessage(args.Tweet.Text.ToString());
                    };
                    await SampleStream.StartStreamAsync();
                }
                else
                {
                    await e.Channel.SendMessage("ERROR most likely you do not have sufficient permissions");
                }
            });

            CService.CreateCommand("Sample")
            .Description("Initializes a socalled sample stream but instead of 1% its specified with an amount of random tweets, Neat!")
            .Parameter("Tweets", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                if (Regex.IsMatch(e.GetArg("Tweets"), @"-?\d+(\.\d+)?"))
                {
                    int Tweets = Convert.ToInt32(e.GetArg("Tweets"));
                    await e.Channel.SendMessage("Transmitting " + e.GetArg("Tweets") + " Tweets");

                    int i = 0;
                    SampleStream.TweetReceived += (sender, args) =>
                    {
                        i++;
                        if (i < Tweets)
                        {
                            e.Channel.SendMessage(args.Tweet.Text.ToString());
                        }
                        else
                        {
                            SampleStream.StopStream();
                        }
                    };
                    FilteredStream.StreamStopped += (sender, args) =>
                    {
                        var Exception         = args.Exception;
                        var DisconnectMessage = args.DisconnectMessage;
                        e.Channel.SendMessage("Filtered stream ended exception: " + Exception + " Disconnect message: " + DisconnectMessage);
                    };
                    await SampleStream.StartStreamAsync();
                }
                else
                {
                    await e.Channel.SendMessage("Error Invalid input");
                }
            });
        }
 public void StartStreamMatchingAllConditionsAsync()
 {
     stream.StartStreamMatchingAllConditionsAsync();
 }
Exemplo n.º 12
0
        public static void CreateCommands()
        {
            var CService = _client.GetService <CommandService>();

            ISampleStream   SampleStream   = Tweetinvi.Stream.CreateSampleStream();
            IFilteredStream FilteredStream = Tweetinvi.Stream.CreateFilteredStream();

            CService.CreateCommand("State")
            .Alias("StreamState", "SS")
            .Description("Displays whether the streams are running or not")
            .Do(async(e) =>
            {
                await e.Channel.SendMessage($"Filtered Stream: {FilteredStream.StreamState} {Environment.NewLine}Sample Stream: {SampleStream.StreamState}");
            });

            CService.CreateCommand("PurgeStreams")
            .Alias("PS", "Purge")
            .Description("Purges all running streams")
            .Do(async(e) =>
            {
                SampleStream.StopStream();
                FilteredStream.StopStream();
                FilteredStream.ClearTracks();
                await e.Channel.SendMessage($"```Sample Stream: {SampleStream.StreamState} {Environment.NewLine}Filtered Stream: {FilteredStream.StreamState}```");
            });

            CService.CreateCommand("Sample")
            .Description("Initializes a socalled sample stream but instead of 1% its specified with an amount of random tweets, Neat!")
            .Parameter("Tweets", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                if (Regex.IsMatch(e.GetArg("Tweets"), @"-?\d+(\.\d+)?"))
                {
                    int Tweets = Convert.ToInt32(e.GetArg("Tweets"));
                    await e.Channel.SendMessage("Transmitting " + e.GetArg("Tweets") + " Tweets");

                    Console.WriteLine(Tweetinvi.User.GetAuthenticatedUser());
                    int i = 0;
                    SampleStream.TweetReceived += (sender, args) =>
                    {
                        if (i < Tweets)
                        {
                            e.Channel.SendMessage(args.Tweet.Text.ToString());
                            i++;
                        }
                        else
                        {
                            SampleStream.StopStream();
                        }
                    };
                    SampleStream.StreamStopped += (sender, args) =>
                    {
                        var Exception         = args.Exception;
                        var DisconnectMessage = args.DisconnectMessage;
                        e.Channel.SendMessage($"```Stream ended { Environment.NewLine }Exception: { Exception } { Environment.NewLine }Disconnect message: { DisconnectMessage }```");
                    };
                    await SampleStream.StartStreamAsync();
                }
                else
                {
                    await e.Channel.SendMessage("Error Invalid input");
                }
            });

            CService.CreateCommand("Track")
            .Description("Tracks a twitter User Either from their ID or Handle")
            .Parameter("User", ParameterType.Unparsed)
            .Description("Tracks a Twitter User")
            .Do(async(e) =>
            {
                if (Regex.IsMatch(e.GetArg("User"), @"-?\d+(\.\d+)?"))
                {
                    long User    = Convert.ToInt64(e.GetArg("User"));
                    IUser Target = Tweetinvi.User.GetUserFromId(Convert.ToInt64(e.GetArg("User")));

                    await e.Channel.SendMessage($"Tracking { Tweetinvi.User.GetUserFromId(Convert.ToInt64(e.GetArg("User"))) }");

                    FilteredStream.AddFollow(User);
                    FilteredStream.MatchingTweetReceived += (sender, args) =>
                    {
                        e.Channel.SendMessage(Target + " " + args.Tweet);
                    };
                    FilteredStream.StreamStopped += (sender, args) =>
                    {
                        e.Channel.SendMessage("Filtered Stream Ended");
                    };
                    await FilteredStream.StartStreamMatchingAllConditionsAsync();
                }
                else
                {
                    var Target = Tweetinvi.User.GetUserFromScreenName(e.GetArg("User"));

                    await e.Channel.SendMessage($"Tracking { Tweetinvi.User.GetUserFromScreenName(e.GetArg("User")) }");

                    FilteredStream.AddFollow(Target);
                    FilteredStream.MatchingTweetReceived += (sender, args) =>
                    {
                        Console.WriteLine("Found Tweet");
                        e.Channel.SendMessage($"{ e.GetArg("User") } Tweeted { args.Tweet }");
                    };
                    await FilteredStream.StartStreamMatchingAllConditionsAsync();
                }
            });
        }