Example #1
0
        public TomeChat(string login, string pass, string main, string mods )
            : base(new Irc(login, pass, new[] { main, mods, "#tomestone"}))
        {
            Client.WriteLine("TWITCHCLIENT 3");

            Channels.Add("main", main);
            Channels.Add("mods", mods);
            Channels.Add("tome", "#tomestone");

            _twitch = new TwitchConnection();

            var timer = new DispatcherTimer { Interval = TimeSpan.FromMinutes(1) };
            timer.Tick += _timer_Tick;
            timer.Start();

            _commands.Add(new AdminAddCommand(this));
            _commands.Add(new AdminDeleteCommand(this));
            _commands.Add(new AdminEditCommand(this));
            _commands.Add(new AdminEntryCommand(this));
            _commands.Add(new AdminInfoCommand(this));

            _commands.Add(new SuperQuoteCommand(this));

            _commands.Add(new UserHighlightCommand(this));
            _commands.Add(new UserBribeCommand(this));
            _commands.Add(new UserTeachCommand(this));
            _commands.Add(new UserQuoteCommand(this));
            _commands.Add(new UserVoteCommand(this));

            _commands.Add(new SuperTeachReply(this));

            _commands.Add(new UserTeachReply(this));
            _commands.Add(new UserQuoteReply(this));
        }
 internal void SendChat(TwitchConnection twitchConnection, string message)
 {
     SendIrcMessage(":" + bot.user.userName
          + "!" + bot.user.userName + "@"
          + bot.user.userName
          + ".tmi.twitch.tv PRIVMSG #" + twitchConnection.channel.user.userName + " :" + message);
 }
Example #3
0
        public Chat()
            : base(new Irc("Tomestone", "oauth:npafwpg44j0a5iullxo2dt385n5jeco", new[] { MainChannel }))
        {
            var twitch = new TwitchConnection();

            _userDatabase = new UserDatabase(_db, twitch);
            _gameDatabase = new GameDatabase(_db, twitch);
            _statistics = new Statistics(_userDatabase, _gameDatabase, twitch);
        }
Example #4
0
        internal void UpdateLiveFollowers(TwitchConnection connection, uint limit, uint offset)
        {
            string json = GetLiveFollowersJson(connection, limit, offset);
            TwitchChannel[] liveChannels = twitchJson.ParseStreams(json);

            if(liveChannels.Length >= limit) {
                Log.info("Live Followers, requesting another page...");
                UpdateLiveFollowers(connection, 100, offset + (uint)liveChannels.Length);
            }
        }
        public TwitchChatRoom(ITwitchFactory factory, TwitchIrcConnection chatConnection,
			 TwitchIrcConnection whisperConnection, TwitchConnection twitchConnection)
        {
            this.factory = factory;
            this.chatIrcConnection = chatConnection;
            this.whisperIrcConnection = whisperConnection;
            this.twitchConnection = twitchConnection;
            this.pointManager = new ChannelPointManager(factory, twitchConnection.channel);

            chatConnection.Join(this);

            TypeHelpers.InstantiateEachSubclass<IAutoJoinTwitchRooms, TwitchChatRoom>(this);
        }
Example #6
0
        internal void UpdateNewFollowers(TwitchConnection connection, uint limit, uint offset, bool forceNextPage = false)
        {
            string json = GetFollowerJson(connection, limit, offset);
            TwitchUserInChannel[] followers = twitchJson.ParseFollowers(json);

            if(followers != null && followers.Length > 0) {
                bool nextPage = forceNextPage;
                foreach(TwitchUserInChannel follower in followers) {
                    follower.Save(false);
                    nextPage = nextPage || follower.HasChangedDb;
                }

                if(nextPage) {
                    Log.info("Followers, requesting another page...");
                    UpdateNewFollowers(connection, 100, offset + (uint)followers.Length, forceNextPage);
                }
            }
        }
 public SqlTwitchCommand(
     uint id,
     TwitchConnection twitchConnection = null,
     string command = null,
     string description = null,
     bool isModOnly = true,
     TimeSpan coolDown = default(TimeSpan),
     string response = null)
     : base(new object[] {
             id,
             twitchConnection.channel.user.id,
             twitchConnection.bot.user.id,
             command,
             description, 
             isModOnly,
             coolDown.TotalSeconds,
             response
         })
 {
     this.connection = twitchConnection;
 }
 /// <summary>
 /// Creates an instance of the GamesService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public GamesService(TwitchConnection connection) : base(connection)
 {
 }
Example #9
0
 /// <summary>
 /// Creates an instance of the StreamsService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public StreamsService(TwitchConnection connection) : base(connection)
 {
 }
Example #10
0
 /// <summary>
 /// Creates an instance of the TagsService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public TagsService(TwitchConnection connection) : base(connection)
 {
 }
Example #11
0
 public GameDatabase(Database db, TwitchConnection twitch)
 {
     _db = db;
 }
 /// <summary>
 /// Creates an instance of the PredictionsService
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public PredictionsService(TwitchConnection connection) : base(connection)
 {
 }
 public TwitchCommand[] GetAllCommands(TwitchConnection twitchConnection)
 {
     return SqlTwitchCommand.GetAll(twitchConnection);
 }
Example #14
0
 public UserDatabase(Database db, TwitchConnection twitch)
 {
     _db = db;
     _twitch = twitch;
 }
 /// <summary>
 /// Creates a new instance of the ChatClient class.
 /// </summary>
 /// <param name="connection">The current connection</param>
 public ChatClient(TwitchConnection connection)
 {
     this.connection = connection;
 }
 /// <summary>
 /// Creates an instance of the UsersService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public UsersService(TwitchConnection connection) : base(connection)
 {
 }
Example #17
0
 public Statistics(UserDatabase userDatabase, GameDatabase gameDatabase, TwitchConnection twitch)
 {
     _userDatabase = userDatabase;
     _gameDatabase = gameDatabase;
     _twitch       = twitch;
 }
 /// <summary>
 /// Creates an instance of the ClipsService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public ClipsService(TwitchConnection connection) : base(connection)
 {
 }
 /// <summary>
 /// Creates an instance of the WebhooksService
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public WebhooksService(TwitchConnection connection) : base(connection)
 {
 }
 /// <summary>
 /// Creates an instance of the OAuthService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public OAuthService(TwitchConnection connection) : base(connection, OAuthBaseAddress)
 {
 }
 /// <summary>
 /// Creates an instance of the ChannelsService.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public ChannelsService(TwitchConnection connection) : base(connection)
 {
 }
Example #22
0
 public TwitchCommand[] GetAllCommands(TwitchConnection twitchConnection)
 {
     return(SqlTwitchCommand.GetAll(twitchConnection));
 }
        public static TwitchCommand[] GetAll(TwitchConnection connection)
        {
            List<object[]> results = _table.Select(null, null, "ChannelUserId=?a AND BotUserId=?b",
                new object[] { connection.channel.user.id, connection.bot.user.id }, null, 0);
            if(results != null) {
                TwitchCommand[] commands = new TwitchCommand[results.Count];
                for(int i = 0; i < results.Count; i++) {
                    commands[i] = new SqlTwitchCommand(
                        results[i][0].FromSql<uint>(),
                        connection,
                        results[i][3].FromSql<string>(),
                        results[i][4].FromSql<string>(),
                        results[i][5].FromSql<bool>(),
                        TimeSpan.FromSeconds(results[i][6].FromSql<int>()),
                        results[i][7].FromSql<string>());
                }

                return commands;
            } else {
                return null;
            }
        }
Example #24
0
 /// <summary>
 /// Creates an instance of the V5APIServiceBase.
 /// </summary>
 /// <param name="connection">The Twitch connection to use</param>
 public V5APIServiceBase(TwitchConnection connection) : base(connection, BASE_ADDRESS)
 {
 }
 public TwitchAlert GetAlert(TwitchConnection connection, string alertGuid, DateTime lastFollowerNotification = default(DateTime))
 {
     return new SqlTwitchAlert(connection, alertGuid, lastFollowerNotification);
 }
Example #26
0
 static string GetFollowerJson(TwitchConnection connection, uint limit, uint offset)
 {
     return GetJson(connection.bot, limit, offset, "channels/" + connection.channel.user.userName + "/follows?");
 }
Example #27
0
 public Statistics(UserDatabase userDatabase, GameDatabase gameDatabase, TwitchConnection twitch)
 {
     _userDatabase = userDatabase;
     _gameDatabase = gameDatabase;
     _twitch = twitch;
 }
Example #28
0
 public GameDatabase(Database db, TwitchConnection twitch)
 {
     _db = db;
 }
Example #29
0
        public static void Main(string[] args)
        {
            Task.Run(async() =>
            {
                try
                {
                    Logger.SetLogLevel(LogLevel.Debug);
                    Logger.LogOccurred += Logger_LogOccurred;

                    using (StreamWriter writer = new StreamWriter(File.Open("Packets.txt", FileMode.Create)))
                    {
                        await writer.FlushAsync();
                    }

                    System.Console.WriteLine("Connecting to Twitch...");

                    connection = TwitchConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes).Result;
                    if (connection != null)
                    {
                        System.Console.WriteLine("Twitch connection successful!");

                        user = await connection.NewAPI.Users.GetCurrentUser();
                        if (user != null)
                        {
                            System.Console.WriteLine("Logged in as: " + user.display_name);

                            System.Console.WriteLine("Connecting to Chat...");

                            chat = new ChatClient(connection);

                            chat.OnDisconnectOccurred += Chat_OnDisconnectOccurred;
                            chat.OnSentOccurred       += Chat_OnSentOccurred;
                            chat.OnPacketReceived     += Chat_OnPacketReceived;

                            chat.OnPingReceived      += Chat_OnPingReceived;
                            chat.OnUserListReceived  += Chat_OnUserListReceived;
                            chat.OnUserJoinReceived  += Chat_OnUserJoinReceived;
                            chat.OnUserLeaveReceived += Chat_OnUserLeaveReceived;
                            chat.OnMessageReceived   += Chat_OnMessageReceived;

                            await chat.Connect();

                            await Task.Delay(1000);

                            await chat.AddCommandsCapability();
                            await chat.AddTagsCapability();
                            await chat.AddMembershipCapability();

                            await Task.Delay(1000);

                            UserModel broadcaster = await connection.NewAPI.Users.GetCurrentUser();

                            await chat.Join(broadcaster);

                            await Task.Delay(2000);

                            System.Console.WriteLine(string.Format("There are {0} users currently in chat", initialUserList.Count()));

                            await chat.SendMessage(broadcaster, "Hello World!");

                            while (true)
                            {
                                System.Console.ReadLine();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            }).Wait();

            System.Console.ReadLine();
        }
 public TwitchPlatformService(TwitchConnection connection)
 {
     this.Connection = connection;
 }
Example #31
0
 public TwitchAlert GetAlert(TwitchConnection connection, string alertGuid, DateTime lastFollowerNotification = default(DateTime))
 {
     return(new SqlTwitchAlert(connection, alertGuid, lastFollowerNotification));
 }
Example #32
0
 public SqlTwitchAlert(TwitchConnection connection, string alertGuid, DateTime lastFollowerNotification = default(DateTime))
     : base(new object[] { connection.bot.user.id, connection.channel.user.id, alertGuid, lastFollowerNotification })
 {
     this.connection = connection;
 }
Example #33
0
        public static void Main(string[] args)
        {
            Task.Run(async() =>
            {
                try
                {
                    Logger.SetLogLevel(LogLevel.Debug);
                    Logger.LogOccurred += Logger_LogOccurred;

                    System.Console.WriteLine("Connecting to Twitch...");

                    connection = TwitchConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes).Result;
                    if (connection != null)
                    {
                        System.Console.WriteLine("Twitch connection successful!");

                        user = await connection.NewAPI.Users.GetCurrentUser();
                        if (user != null)
                        {
                            System.Console.WriteLine("Logged in as: " + user.display_name);

                            System.Console.WriteLine("Connecting to PubSub...");

                            pubSub = new PubSubClient(connection);

                            pubSub.OnDisconnectOccurred += PubSub_OnDisconnectOccurred;
                            pubSub.OnSentOccurred       += PubSub_OnSentOccurred;
                            pubSub.OnReconnectReceived  += PubSub_OnReconnectReceived;
                            pubSub.OnResponseReceived   += PubSub_OnResponseReceived;
                            pubSub.OnMessageReceived    += PubSub_OnMessageReceived;
                            pubSub.OnWhisperReceived    += PubSub_OnWhisperReceived;
                            pubSub.OnPongReceived       += PubSub_OnPongReceived;

                            await pubSub.Connect();

                            await Task.Delay(1000);

                            List <PubSubListenTopicModel> topics = new List <PubSubListenTopicModel>();
                            foreach (PubSubTopicsEnum topic in EnumHelper.GetEnumList <PubSubTopicsEnum>())
                            {
                                topics.Add(new PubSubListenTopicModel(topic, user.id));
                            }

                            await pubSub.Listen(topics);

                            await Task.Delay(1000);

                            await pubSub.Ping();

                            while (true)
                            {
                                System.Console.ReadLine();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            }).Wait();

            System.Console.ReadLine();
        }
 private void TwitchConnection_OnMessageReceived(TwitchConnection arg1, TwitchMessage message)
 {
     Plugin.Log("Message Recieved, AsyncTwitch currently working", Plugin.LogLevel.Debug);
     twitchCommands.handleCommandMessage(arg1, message);
 }
Example #35
0
 string GetLiveFollowersJson(TwitchConnection connection, uint limit, uint offset)
 {
     TwitchUserInChannel[] followers = factory.GetAllUserInChannels(connection.channel);
     return GetJson(connection.bot, limit, offset, "streams/?channel="
             + TwitchHelpers.GetAllAsCsv(followers));
 }
 private void TwitchConnection_OnChatJoined(TwitchConnection arg1)
 {
     Plugin.Log("Message Recieved, AsyncTwitch currently working", Plugin.LogLevel.Debug);
     arg1.SendChatMessage("Custom UI plugin connected! Type !help for info!");
 }
 public SqlTwitchAlert(TwitchConnection connection, string alertGuid, DateTime lastFollowerNotification = default(DateTime))
     : base(new object[] { connection.bot.user.id, connection.channel.user.id, alertGuid, lastFollowerNotification })
 {
     this.connection = connection;
 }
Example #38
0
        private void ButtonConnectTwitch_Click(object sender, EventArgs e)
        {
            if (twitch != null && twitch.Client.IsConnected)
            {
                twitch?.Kill();
                twitch = null;

                comboBoxVotingTime.Enabled     = true;
                comboBoxVotingCooldown.Enabled = true;

                textBoxTwitchChannel.Enabled  = true;
                textBoxTwitchUsername.Enabled = true;
                textBoxTwitchOAuth.Enabled    = true;

                buttonConnectTwitch.Text = "Connect to Twitch";

                if (!tabSettings.TabPages.Contains(tabEffects))
                {
                    tabSettings.TabPages.Insert(tabSettings.TabPages.IndexOf(tabTwitch), tabEffects);
                }

                return;
            }

            if (Config.Instance.TwitchChannel != "" && Config.Instance.TwitchUsername != "" && Config.Instance.TwitchOAuthToken != "")
            {
                buttonConnectTwitch.Enabled = false;

                twitch = new TwitchConnection();

                twitch.OnRapidFireEffect += (_sender, rapidFireArgs) =>
                {
                    Invoke(new Action(() =>
                    {
                        if (Config.Instance.TwitchVotingMode == 2)
                        {
                            rapidFireArgs.Effect.RunEffect();
                            AddEffectToListBox(rapidFireArgs.Effect);
                        }
                    }));
                };

                twitch.Client.OnIncorrectLogin += (_sender, _e) =>
                {
                    MessageBox.Show("There was an error trying to log in to the account. Wrong username / OAuth token?", "Twitch Login Error");
                    Invoke(new Action(() =>
                    {
                        buttonConnectTwitch.Enabled = true;
                    }));
                    twitch.Kill();
                };

                twitch.Client.OnConnected += (_sender, _e) =>
                {
                    Invoke(new Action(() =>
                    {
                        buttonConnectTwitch.Enabled = true;
                        buttonTwitchToggle.Enabled  = true;

                        buttonAutoStart.Enabled = true;

                        buttonConnectTwitch.Text = "Disconnect";

                        textBoxTwitchChannel.Enabled  = false;
                        textBoxTwitchUsername.Enabled = false;
                        textBoxTwitchOAuth.Enabled    = false;
                    }));
                };
            }
        }