public SqlTwitchUserPoints(SqlTwitchUser user, SqlTwitchChannel channel, ulong points = 0, DateTime timeOfLastBonus = default(DateTime))
     : base(new object[] { user.id, channel.user.id, points, timeOfLastBonus })
 {
     user.Save();
     this.user = user;
     this.channel = channel;
 }
        public static SqlTwitchUserPoints[] GetTopUsersForChannel(SqlTwitchChannel channel, uint count)
        {
            List<object[]> results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "Points Desc", count);

            if(results != null && results.Count > 0) {
                SqlTwitchUserPoints[] points = new SqlTwitchUserPoints[results.Count];
                for(int i = 0; i < results.Count; i++) {
                    points[i] = new SqlTwitchUserPoints(new SqlTwitchUser((uint)results[i][0]), channel, (ulong)results[i][2], (DateTime)results[i][3]);
                }

                return points;
            }

            return null;
        }
        public static SqlTwitchFollower[] GetAllWithUsernames(SqlTwitchChannel channel)
        {
            try {
                List<object[]> results = _table.Select("join twitch_users on id=" + _table.tableName + ".UserId", _table.tableName + ".*, name", "ChannelUserId=?a", new object[] { channel.user.id }, null, 0);

                if(results != null) {
                    SqlTwitchFollower[] followers = new SqlTwitchFollower[results.Count];
                    for(int i = 0; i < followers.Length; i++) {
                        followers[i] = FromSql(channel, results[i]);
                    }

                    return followers;
                } else {
                    return null;
                }
            } catch(Exception e) {
                Log.exception(e);

                return null;
            }
        }
        public static SqlTwitchChannel[] GetAllLiveFollowers(SqlTwitchChannel channel)
        {
            string where = "twitch_followers.ChannelUserId=?a and IsLive=?b";
            string join = "join twitch_followers on twitch_followers.UserId=twitch_channels.UserId";
            object[] vars = new object[] { channel.user.id, true };

            object[][] results = _table.Select(join, null, where, vars, null, 0);
            if(results != null) {
                SqlTwitchChannel[] channels = new SqlTwitchChannel[results.Length];
                for(int i = 0; i < results.Length; i++) {
                    channels[i] = FromSql(results[i]);
                }

                return channels;
            } else {
                return null;
            }
        }
        public static SqlTwitchChannel[] GetAll()
        {
            object[][] results = _table.Select(null, null, null, null, null, 0);
            if(results != null) {
                SqlTwitchChannel[] channels = new SqlTwitchChannel[results.Length];
                for(int i = 0; i < results.Length; i++) {
                    channels[i] = FromSql(results[i]);
                }

                return channels;
            } else {
                return null;
            }
        }
 public static void ClearLiveFollowers(SqlTwitchChannel channel)
 {
     _table.Update("join twitch_followers on twitch_followers.UserId=twitch_channels.UserId", "IsLive=?a", "ChannelUserId=?b", new object[] { false, channel.user.id });
 }
 public SqlTwitchConnection(SqlTwitchBot bot, SqlTwitchChannel channel, bool autoConnectToChat = false)
     : base(new object[] { bot.user.id, channel.user.id, autoConnectToChat })
 {
     this.bot = bot;
     this.channel = channel;
 }
        public static SqlTwitchFollower GetMostRecent(SqlTwitchChannel channel)
        {
            try {
                object[] results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "CreatedAt Desc");
                if(results != null && results.Length > 0) {
                    return FromSql(channel, results);
                } else {
                    return null;
                }
            } catch(Exception e) {
                Log.exception(e);

                return null;
            }
        }
 public static void ClearAll(SqlTwitchChannel channel)
 {
     _table.Update(null, "IsCurrentlyFollowing=?a", "ChannelUserId=?b", new object[] { false, channel.user.id });
 }
 public SqlTwitchFollower(SqlTwitchUser user, SqlTwitchChannel channel, DateTime created = default(DateTime), bool isCurrentlyFollowing = false)
     : base(new object[] { user.id, channel.user.id, created, isCurrentlyFollowing })
 {
     this.user = user;
     this.channel = channel;
 }
 static SqlTwitchFollower FromSql(SqlTwitchChannel channel, object[] results)
 {
     if(results != null && results.Length > 0) {
         if(results.Length > 4) {
             return new SqlTwitchFollower(new SqlTwitchUser(results[0].FromSql<uint>(), results[4].FromSql<string>()), channel, results[2].FromSql<DateTime>(), results[3].FromSql<bool>());
         } else {
             return new SqlTwitchFollower(new SqlTwitchUser(results[0].FromSql<uint>()), channel, results[2].FromSql<DateTime>(), results[3].FromSql<bool>());
         }
     } else {
         return null;
     }
 }