Esempio n. 1
0
 public SpamConfig()
 {
     LastActions = new FixedSizedQueue <ChatAction>();
     Users       = new Dictionary <string, UserAction>();
 }
Esempio n. 2
0
        public LinkExpander(IrcClient client)
        {
            TwitterToChannels = new Dictionary <long, List <string> >();

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config", "services.json");

            if (!File.Exists(path))
            {
                Log.WriteWarn("Twitter", "File config/services.json doesn't exist");

                return;
            }

            var data = File.ReadAllText(path);

            try
            {
                Config = JsonConvert.DeserializeObject <LinkExpanderConfig>(data, new JsonSerializerSettings {
                    MissingMemberHandling = MissingMemberHandling.Error
                });

                if (Config.Twitter.AccessSecret == null ||
                    Config.Twitter.AccessToken == null ||
                    Config.Twitter.ConsumerKey == null ||
                    Config.Twitter.ConsumerSecret == null)
                {
                    throw new JsonException("Twitter keys cannot be null");
                }

                if (Config.Channels == null)
                {
                    Config.Channels = new List <string>();
                }
                else
                {
                    foreach (var channel in Config.Channels)
                    {
                        if (!IrcValidation.IsChannelName(channel))
                        {
                            throw new JsonException($"Invalid channel '{channel}'");
                        }
                    }
                }
            }
            catch (JsonException e)
            {
                Log.WriteError("Twitter", "Failed to parse services.json file: {0}", e.Message);

                Environment.Exit(1);
            }

            LastMatches = new FixedSizedQueue <string>
            {
                Limit = Config.DontRepeatLastCount
            };

            TwitterCompiledMatch = new Regex(@"(^|/|\.)twitter\.com/(.+?)/status/(?<status>[0-9]+)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);

            client.GotMessage += OnMessage;

            TweetinviConfig.ApplicationSettings.TweetMode = TweetMode.Extended;

            // lul per thread or application credentials
            Auth.ApplicationCredentials = new TwitterCredentials(
                Config.Twitter.ConsumerKey,
                Config.Twitter.ConsumerSecret,
                Config.Twitter.AccessToken,
                Config.Twitter.AccessSecret
                );

            if (Config.Twitter.AccountsToFollow.Count > 0)
            {
                var thread = new Thread(StartTwitterStream)
                {
                    Name = "TwitterStream"
                };
                thread.Start();
            }
        }