Exemple #1
0
 public IEnumerable <DB.Tweet> Run()
 {
     tweets = new BlockingCollection <DB.Tweet>();
     stream = Stream.CreateSampleStream(credentials);
     stream.TweetReceived += (s, e) => AddTweet(e);
     stream.StartStreamAsync();
     return(tweets.GetConsumingEnumerable());
 }
Exemple #2
0
        private void Produce()
        {
            _Stream = Stream.CreateSampleStream();

            _Stream.TweetReceived += (object sender, Tweetinvi.Events.TweetReceivedEventArgs e) =>
            {
                _TargetBuffer.Post(e.Tweet);
            };

            _Stream.AddTweetLanguageFilter(LanguageFilter.English);

            _Stream.StartStreamAsync();
        }
Exemple #3
0
    static Startup()
    {
        Auth.ApplicationCredentials = new TwitterCredentials(ConfigurationManager.AppSettings["consumerKey"],
            ConfigurationManager.AppSettings["consumerSecret"],
            ConfigurationManager.AppSettings["accessToken"], ConfigurationManager.AppSettings["accessTokenSecret"]);
        tStream = Stream.CreateSampleStream();
        tStream.AddTweetLanguageFilter(Language.English);
        tStream.TweetReceived += tStream_TweetReceived;
        tStream.StreamStopped += tStream_StreamStopped;
 
        tStream.StallWarnings = true;
        tStream.StartStreamAsync();
    }
Exemple #4
0
        public void Start()
        {
            _stream = Stream.CreateSampleStream();

            _stream.Credentials = _credentials;

            _hubContext.Clients.All.log("Message from Server: Sample stream created");

            _stream.TweetReceived += (sender, args) =>
            {
                var tweet = new TweetViewModel(args.Tweet);
                _hubContext.Clients.All.broadcastTweet(tweet);
            };

            _stream.StartStreamAsync();
        }
        public void Start()
        {            
            _stream = Stream.CreateSampleStream();

            _stream.Credentials = _credentials;

            _hubContext.Clients.All.log("Message from Server: Sample stream created");

            _stream.TweetReceived += (sender, args) =>
            {
                var tweet = new TweetViewModel(args.Tweet);
                _hubContext.Clients.All.broadcastTweet(tweet);
            };

            _stream.StartStreamAsync();
        }
Exemple #6
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");
                }
            });
        }
Exemple #7
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();
                }
            });
        }