public void ChannelJoined(TwitchChannel channel) { chan = channel; //for (int i = 0; i < 10000; i++) //{ // string name = CreateString(5); // string response = CreateString(35); // if (!triggerResponses.ContainsKey(name)) // triggerResponses.Add(name, new SharedInformationalChatCommand() // { // ChannelName = channel.Channel, // CommandId = 0, // CommandPermissionRequired = string.Empty, // CommandResponse = response, // CommandTrigger = name, // CoolDownSeconds = 0, // IsActive = 1, // DateCreated = DateTime.Now, // UserCreated = "c" // }); //} //foreach (var item in triggerResponses.Keys) //{ // ActivateConcreteCommand(triggerResponses[item]); //} }
private async Task RefreshChannelStatus(bool notify = false) { TwitchChecker checker = new TwitchChecker(_cm.GetApiKey()); foreach (string item in _cm.GetChannels()) { int? itemindex = GetCorrespondingListItemIndex(item); TwitchChannel chan = await checker.CheckChannel(item); if (itemindex != null) { ChannelListBox.Items.RemoveAt((int)itemindex); ChannelListBox.Items.Insert((int)itemindex, chan); } else { ChannelListBox.Items.Add(chan); } if (chan.Status != "offline") { //todo: Notify } } RefreshUpdateTimestamp(); }
public EmoteClrServer(TwitchChannel channel) { server = new WebSocketServer(IPAddress.Any, 5201); server.AddWebSocketService <EmoteClrServerBehaviour>("/"); server.Start(); }
internal TwitchChannel[] ParseStreams(string json) { LinkedList <TwitchChannel> liveChannels = new LinkedList <TwitchChannel>(); if (json != null) { // {"streams":[{"_id":15979305936,"game":"Hearthstone: Heroes of Warcraft","viewers":32125,"created_at":"2015-08-24T18:43:05Z","video_height":1080,"average_fps":59.9971194327,"is_playlist":false,"_links":{"self":"http://api.twitch.tv/kraken/streams/trumpsc"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-{width}x{height}.jpg"},"channel":{"_links":{"self":"http://api.twitch.tv/kraken/channels/trumpsc","follows":"http://api.twitch.tv/kraken/channels/trumpsc/follows","commercial":"http://api.twitch.tv/kraken/channels/trumpsc/commercial","stream_key":"http://api.twitch.tv/kraken/channels/trumpsc/stream_key","chat":"http://api.twitch.tv/kraken/chat/trumpsc","features":"http://api.twitch.tv/kraken/channels/trumpsc/features","subscriptions":"http://api.twitch.tv/kraken/channels/trumpsc/subscriptions","editors":"http://api.twitch.tv/kraken/channels/trumpsc/editors","videos":"http://api.twitch.tv/kraken/channels/trumpsc/videos","teams":"http://api.twitch.tv/kraken/channels/trumpsc/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"TrumpSC","game":"Hearthstone: Heroes of Warcraft","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-profile_image-0eca634ef027d36b-300x300.png","mature":false,"status":"TSM Trump New Shaman Ladders","partner":true,"url":"http://www.twitch.tv/trumpsc","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-channel_offline_image-7a8982acc68970b3-640x360.jpeg","_id":14836307,"name":"trumpsc","created_at":"2010-08-21T02:09:05Z","updated_at":"2015-08-24T20:17:30Z","delay":0,"followers":586748,"profile_banner":null,"profile_banner_background_color":null,"views":74490399,"language":"en"}},{"_id":15980940288,"game":"Trials Fusion","viewers":8,"created_at":"2015-08-24T20:16:57Z","video_height":0,"average_fps":28.9494117647,"is_playlist":false,"_links":{"self":"https://api.twitch.tv/kraken/streams/coolkid661"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-{width}x{height}.jpg"},"channel":{"_links":{"self":"https://api.twitch.tv/kraken/channels/coolkid661","follows":"https://api.twitch.tv/kraken/channels/coolkid661/follows","commercial":"https://api.twitch.tv/kraken/channels/coolkid661/commercial","stream_key":"https://api.twitch.tv/kraken/channels/coolkid661/stream_key","chat":"https://api.twitch.tv/kraken/chat/coolkid661","features":"https://api.twitch.tv/kraken/channels/coolkid661/features","subscriptions":"https://api.twitch.tv/kraken/channels/coolkid661/subscriptions","editors":"https://api.twitch.tv/kraken/channels/coolkid661/editors","videos":"https://api.twitch.tv/kraken/channels/coolkid661/videos","teams":"https://api.twitch.tv/kraken/channels/coolkid661/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"Coolkid661","game":"Trials Fusion","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-profile_image-c87d780344e2e2bf-300x300.jpeg","mature":true,"status":"Trials pot roast","partner":false,"url":"http://www.twitch.tv/coolkid661","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-channel_offline_image-ebc8ecb7816b3e01-640x360.png","_id":62621803,"name":"coolkid661","created_at":"2014-05-14T21:14:07Z","updated_at":"2015-08-24T20:18:04Z","delay":0,"followers":904,"profile_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-profile_banner-cdcf6f682eb11f44-480.png","profile_banner_background_color":"null","views":6932,"language":"en"}}],"_total":2,"_links":{"self":"https://api.twitch.tv/kraken/streams?channel=hardlysober%2Csoberbot%2Carbedii%2Cbacon_donut%2Csevadus%2Ctrumpsc%2Ccoolkid661&limit=25&offset=0","next":"https://api.twitch.tv/kraken/streams?channel=hardlysober%2Csoberbot%2Carbedii%2Cbacon_donut%2Csevadus%2Ctrumpsc%2Ccoolkid661&limit=25&offset=25","featured":"https://api.twitch.tv/kraken/streams/featured","summary":"https://api.twitch.tv/kraken/streams/summary","followed":"https://api.twitch.tv/kraken/streams/followed"}} json = json.GetBetween("[", "]", true, false); // {"_id":15979305936,"game":"Hearthstone: Heroes of Warcraft","viewers":32125,"created_at":"2015-08-24T18:43:05Z","video_height":1080,"average_fps":59.9971194327,"is_playlist":false,"_links":{"self":"http://api.twitch.tv/kraken/streams/trumpsc"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-{width}x{height}.jpg"},"channel":{"_links":{"self":"http://api.twitch.tv/kraken/channels/trumpsc","follows":"http://api.twitch.tv/kraken/channels/trumpsc/follows","commercial":"http://api.twitch.tv/kraken/channels/trumpsc/commercial","stream_key":"http://api.twitch.tv/kraken/channels/trumpsc/stream_key","chat":"http://api.twitch.tv/kraken/chat/trumpsc","features":"http://api.twitch.tv/kraken/channels/trumpsc/features","subscriptions":"http://api.twitch.tv/kraken/channels/trumpsc/subscriptions","editors":"http://api.twitch.tv/kraken/channels/trumpsc/editors","videos":"http://api.twitch.tv/kraken/channels/trumpsc/videos","teams":"http://api.twitch.tv/kraken/channels/trumpsc/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"TrumpSC","game":"Hearthstone: Heroes of Warcraft","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-profile_image-0eca634ef027d36b-300x300.png","mature":false,"status":"TSM Trump New Shaman Ladders","partner":true,"url":"http://www.twitch.tv/trumpsc","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-channel_offline_image-7a8982acc68970b3-640x360.jpeg","_id":14836307,"name":"trumpsc","created_at":"2010-08-21T02:09:05Z","updated_at":"2015-08-24T20:17:30Z","delay":0,"followers":586748,"profile_banner":null,"profile_banner_background_color":null,"views":74490399,"language":"en"}},{"_id":15980940288,"game":"Trials Fusion","viewers":8,"created_at":"2015-08-24T20:16:57Z","video_height":0,"average_fps":28.9494117647,"is_playlist":false,"_links":{"self":"https://api.twitch.tv/kraken/streams/coolkid661"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_coolkid661-{width}x{height}.jpg"},"channel":{"_links":{"self":"https://api.twitch.tv/kraken/channels/coolkid661","follows":"https://api.twitch.tv/kraken/channels/coolkid661/follows","commercial":"https://api.twitch.tv/kraken/channels/coolkid661/commercial","stream_key":"https://api.twitch.tv/kraken/channels/coolkid661/stream_key","chat":"https://api.twitch.tv/kraken/chat/coolkid661","features":"https://api.twitch.tv/kraken/channels/coolkid661/features","subscriptions":"https://api.twitch.tv/kraken/channels/coolkid661/subscriptions","editors":"https://api.twitch.tv/kraken/channels/coolkid661/editors","videos":"https://api.twitch.tv/kraken/channels/coolkid661/videos","teams":"https://api.twitch.tv/kraken/channels/coolkid661/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"Coolkid661","game":"Trials Fusion","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-profile_image-c87d780344e2e2bf-300x300.jpeg","mature":true,"status":"Trials pot roast","partner":false,"url":"http://www.twitch.tv/coolkid661","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-channel_offline_image-ebc8ecb7816b3e01-640x360.png","_id":62621803,"name":"coolkid661","created_at":"2014-05-14T21:14:07Z","updated_at":"2015-08-24T20:18:04Z","delay":0,"followers":904,"profile_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/coolkid661-profile_banner-cdcf6f682eb11f44-480.png","profile_banner_background_color":"null","views":6932,"language":"en"}} if (json != null) { string[] channelsJsonList = json.Tokenize("{\"_id\":", true); // channelsList[i] = {"_id":15979305936,"game":"Hearthstone: Heroes of Warcraft","viewers":32125,"created_at":"2015-08-24T18:43:05Z","video_height":1080,"average_fps":59.9971194327,"is_playlist":false,"_links":{"self":"http://api.twitch.tv/kraken/streams/trumpsc"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-{width}x{height}.jpg"},"channel":{"_links":{"self":"http://api.twitch.tv/kraken/channels/trumpsc","follows":"http://api.twitch.tv/kraken/channels/trumpsc/follows","commercial":"http://api.twitch.tv/kraken/channels/trumpsc/commercial","stream_key":"http://api.twitch.tv/kraken/channels/trumpsc/stream_key","chat":"http://api.twitch.tv/kraken/chat/trumpsc","features":"http://api.twitch.tv/kraken/channels/trumpsc/features","subscriptions":"http://api.twitch.tv/kraken/channels/trumpsc/subscriptions","editors":"http://api.twitch.tv/kraken/channels/trumpsc/editors","videos":"http://api.twitch.tv/kraken/channels/trumpsc/videos","teams":"http://api.twitch.tv/kraken/channels/trumpsc/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"TrumpSC","game":"Hearthstone: Heroes of Warcraft","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-profile_image-0eca634ef027d36b-300x300.png","mature":false,"status":"TSM Trump New Shaman Ladders","partner":true,"url":"http://www.twitch.tv/trumpsc","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-channel_offline_image-7a8982acc68970b3-640x360.jpeg","_id":14836307,"name":"trumpsc","created_at":"2010-08-21T02:09:05Z","updated_at":"2015-08-24T20:17:30Z","delay":0,"followers":586748,"profile_banner":null,"profile_banner_background_color":null,"views":74490399,"language":"en"}}, // w/ or w/o a comma at the end foreach (string channelJson in channelsJsonList) { TwitchChannel channel = ParseChannel(channelJson); if (channel != null) { liveChannels.AddLast(channel); } } } } return(liveChannels.ToArray <TwitchChannel>()); }
public async Task <IHttpActionResult> PutTwitchChannel(int id, TwitchChannel twitchChannel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != twitchChannel.Id) { return(BadRequest()); } db.Entry(twitchChannel).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TwitchChannelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <TwitchChannel> AddChannelByName(string channelName) { _log.Debug("Adding Twitch channel by name {channelName}", channelName); var userEntity = await _twitchClient.GetUserByName(channelName); if (userEntity == null) { throw new AddChannelFailedException(AddChannelFailedReason.ChannelNotFound); } var channelEntity = await _twitchClient.GetChannelById(userEntity.Id); if (channelEntity == null) { throw new AddChannelFailedException(AddChannelFailedReason.ChannelNotFound); } var channel = new TwitchChannel { DisplayName = userEntity.DisplayName, Id = userEntity.Id, Followers = channelEntity.Followers }; if (!await _twitchChannelRepository.TryAddChannel(channel)) { _log.Debug("Adding channel {channelName} failed", channelName); throw new AddChannelFailedException(AddChannelFailedReason.Internal); } _log.Debug("Channel {channelName} added", channelName); return(channel); }
public SqlTwitchUserPoints(TwitchUser user, TwitchChannel 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; }
private void ModJoined(TwitchChannel conn, TwitchUser user) { if (user == CurrentUser) { ModButtonVisibility = Visibility.Visible; } }
public async Task <bool> TryAddChannel(TwitchChannel channel) { var record = new TwitchChannelRecord { Id = channel.Id, DisplayName = channel.DisplayName, Followers = channel.Followers }; using (var op = _log.BeginOperation("Adding channel to repository. Channel name {channelName} id {channelId}", channel.DisplayName, channel.Id)) using (ITransaction tx = _stateManager.CreateTransaction()) { var channelDictionary = await GetChannelDictionary(tx); if (!await channelDictionary.TryAddAsync(tx, record.Id, record)) { return(false); } await tx.CommitAsync() .ContinueWith(task => RepositoryIndexes.Instance.AddRecord(record.Id, record.DisplayName), TaskContinuationOptions.OnlyOnRanToCompletion); op.Complete(); } return(true); }
private void ChatMessageReceived(TwitchChannel sender, TwitchUser user, string text) { if (m_options.Ignore.Contains(user.Name)) { return; } var emotes = Emoticons; if (emotes != null) { emotes.EnsureDownloaded(user.ImageSet); } bool question = false; if (HighlightQuestions) { foreach (var highlight in m_options.Highlights) { if (text.ToLower().Contains(highlight)) { question = true; break; } } } Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action <ChatItem>(AddItem), new ChatMessage(sender, this, user, text, question)); }
private void ModLeft(TwitchChannel conn, TwitchUser user) { if (user == CurrentUser) { ModButtonVisibility = Visibility.Collapsed; } }
TwitchChannel ParseChannel(string json) { // json = {"_id":15979305936,"game":"Hearthstone: Heroes of Warcraft","viewers":32125,"created_at":"2015-08-24T18:43:05Z","video_height":1080,"average_fps":59.9971194327,"is_playlist":false,"_links":{"self":"http://api.twitch.tv/kraken/streams/trumpsc"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-{width}x{height}.jpg"},"channel":{"_links":{"self":"http://api.twitch.tv/kraken/channels/trumpsc","follows":"http://api.twitch.tv/kraken/channels/trumpsc/follows","commercial":"http://api.twitch.tv/kraken/channels/trumpsc/commercial","stream_key":"http://api.twitch.tv/kraken/channels/trumpsc/stream_key","chat":"http://api.twitch.tv/kraken/chat/trumpsc","features":"http://api.twitch.tv/kraken/channels/trumpsc/features","subscriptions":"http://api.twitch.tv/kraken/channels/trumpsc/subscriptions","editors":"http://api.twitch.tv/kraken/channels/trumpsc/editors","videos":"http://api.twitch.tv/kraken/channels/trumpsc/videos","teams":"http://api.twitch.tv/kraken/channels/trumpsc/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"TrumpSC","game":"Hearthstone: Heroes of Warcraft","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-profile_image-0eca634ef027d36b-300x300.png","mature":false,"status":"TSM Trump New Shaman Ladders","partner":true,"url":"http://www.twitch.tv/trumpsc","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-channel_offline_image-7a8982acc68970b3-640x360.jpeg","_id":14836307,"name":"trumpsc","created_at":"2010-08-21T02:09:05Z","updated_at":"2015-08-24T20:17:30Z","delay":0,"followers":586748,"profile_banner":null,"profile_banner_background_color":null,"views":74490399,"language":"en"}}, // w/ or w/o a comma at the end json = json.GetBetween("{", "}", true, false); // "_id":15979305936,"game":"Hearthstone: Heroes of Warcraft","viewers":32125,"created_at":"2015-08-24T18:43:05Z","video_height":1080,"average_fps":59.9971194327,"is_playlist":false,"_links":{"self":"http://api.twitch.tv/kraken/streams/trumpsc"},"preview":{"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-80x45.jpg","medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-320x180.jpg","large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-640x360.jpg","template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_trumpsc-{width}x{height}.jpg"},"channel":{"_links":{"self":"http://api.twitch.tv/kraken/channels/trumpsc","follows":"http://api.twitch.tv/kraken/channels/trumpsc/follows","commercial":"http://api.twitch.tv/kraken/channels/trumpsc/commercial","stream_key":"http://api.twitch.tv/kraken/channels/trumpsc/stream_key","chat":"http://api.twitch.tv/kraken/chat/trumpsc","features":"http://api.twitch.tv/kraken/channels/trumpsc/features","subscriptions":"http://api.twitch.tv/kraken/channels/trumpsc/subscriptions","editors":"http://api.twitch.tv/kraken/channels/trumpsc/editors","videos":"http://api.twitch.tv/kraken/channels/trumpsc/videos","teams":"http://api.twitch.tv/kraken/channels/trumpsc/teams"},"background":null,"banner":null,"broadcaster_language":"en","display_name":"TrumpSC","game":"Hearthstone: Heroes of Warcraft","logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-profile_image-0eca634ef027d36b-300x300.png","mature":false,"status":"TSM Trump New Shaman Ladders","partner":true,"url":"http://www.twitch.tv/trumpsc","video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/trumpsc-channel_offline_image-7a8982acc68970b3-640x360.jpeg","_id":14836307,"name":"trumpsc","created_at":"2010-08-21T02:09:05Z","updated_at":"2015-08-24T20:17:30Z","delay":0,"followers":586748,"profile_banner":null,"profile_banner_background_color":null,"views":74490399,"language":"en"} uint userId = uint.Parse(json.GetBetween(",\"_id\":", ",")); string previewImageUrl = json.GetBetween("\"large\":\"", "\""); string game = json.GetBetween("\"game\":\"", "\""); uint liveViewers = 0; uint.TryParse(json.GetBetween("\"viewers\":", ","), out liveViewers); uint totalViews = 0; uint.TryParse(json.GetBetween("\"views\":", ","), out totalViews); uint followers = 0; uint.TryParse(json.GetBetween("\"followers\":", ","), out followers); TwitchChannel channel = factory.CreateTwitchChannel(factory.GetUserForID(userId), true, previewImageUrl, game, liveViewers, totalViews, followers); channel.Save(false); return(channel); }
public static SqlTwitchUserInChannel[] GetAllWithUsernames(TwitchChannel 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) { SqlTwitchUserInChannel[] followers = new SqlTwitchUserInChannel[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 SqlTwitchChannelPointScale(TwitchChannel channel, ulong unitValue, string unitNameSingular = null, string unitNamePlural = null) : base(new object[] { channel.user.id, unitValue, unitNameSingular, unitNamePlural }) { this.channel = channel; }
public void Post(VideoSend request) { if (String.IsNullOrWhiteSpace(request.Name)) { throw new ArgumentException("Name cannot be empty."); } if (String.IsNullOrWhiteSpace(request.Path)) { throw new ArgumentException("Path cannot be empty."); } if (String.IsNullOrWhiteSpace(request.UserId)) { throw new ArgumentException("UserId cannot be empty."); } List <TwitchChannel> list = Plugin.Instance.Configuration.TwitchChannels.ToList <TwitchChannel>(); TwitchChannel channel = new TwitchChannel() { UserId = request.UserId, Name = request.Name, UserName = request.UserName, Image = "", Protocol = Model.MediaInfo.MediaProtocol.Http }; list.Add(channel); Plugin.Instance.Configuration.TwitchChannels = list.ToArray(); Plugin.Instance.SaveConfiguration(); }
public async Task <IHttpActionResult> DeleteTwitchChannelAdmin(int channelId, int userId) { TwitchChannel channel = await db.TwitchChannels.FindAsync(channelId); db.TwitchChannels.Attach(channel); int index = channel.Users.FindIndex(u => u.Id == userId); if (index < 0) { return(NotFound()); } channel.Users.RemoveAt(index); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TwitchChannelExists(userId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private TwitchChannel getChannelJson(string room) { try { string json = getHttp(room); if (json == null || json == "") { return(null); } if (!json.Contains("{")) { return(null); } if (json.Contains("\"error\"")) { return(null); } TwitchChannel result = JsonConvert.DeserializeObject <TwitchChannel>(json); if (result == null) { return(null); } return(result); } catch (Exception) { return(null); } }
async void BanWorker(TwitchChannel chan, TwitchUser user) { while (!chan.Ban(user) && chan.IsJoined) { await Task.Delay(250); } }
public Task <CommandHandlerResult> ProcessCommand(BotCommand command, TwitchChannel channel) { string channelName = $"#{channel.Name}"; //check other misc commands. switch (command.Command) { case "!roll": //dice roll command is in form of !roll nDm+x, where n is number of dice, m is dice size, and x is the modifier. Regex rollRegex = new Regex(@"(\d*)?[Dd](\d*)(\+\d*|-\d*)?"); Match match = rollRegex.Match(command.Arguments); if (match.Success) { return(Task.FromResult(DiceRollCommand(match, channelName))); } else { return(Task.FromResult(new CommandHandlerResult(ResultType.NotHandled))); } case "!8": return(Task.FromResult(MagicEightBallCommand(command, channelName))); default: return(Task.FromResult(new CommandHandlerResult(ResultType.NotHandled))); } }
/// <summary> /// Initializes a new instance of the <see cref="TwitchClearchatEventArgs"/> class. /// </summary> internal TwitchCheerEventArgs(TwitchUser user, TwitchChannel channel, string message, int bits) { Channel = channel; User = user; Message = message; Bits = bits; }
public async Task JoinTwitch() { SharedBotInfo shared = SharedBotInfo.GetSharedInfo(Context.Guild.Id); if (!string.IsNullOrWhiteSpace(shared.TwitchChannelName)) { TwitchChannel chan = Program.TwitchBot.GetChannel(shared.TwitchChannelName); if (chan != null) { await chan.SendChatMessage("Boo!"); await Context.Channel.SendMessageAsync("No need for me to rejoin, I'm already there! Can you see me over in Twitch-land?"); } else { await Program.TwitchBot.JoinChannel(shared.TwitchChannelName); await Task.Delay(1000); if (Program.TwitchBot.GetChannel(shared.TwitchChannelName) != null) { await Context.Channel.SendMessageAsync("Figure that, I was able to join your Twitch channel this time! Can you see me over in Twitch-land?"); } else { await Context.Channel.SendMessageAsync("I wasn't able to connect to the Twitch channel you linked to this server!"); } } } else { await Context.Channel.SendMessageAsync($"You haven't told me what Twitch channel this server is associated with yet, dummy! *(pssst! use `{Program.Config.CommandPrefix}settwitch`!)*"); } }
internal TwitchSubscriptionEventArgs(TwitchUser user, TwitchChannel channel, TwitchSubscriptionPlan subscriptionPlan, string message, int totalMonthsSubscribed) { User = user; Channel = channel; SubscriptionPlan = subscriptionPlan; Message = message; TotalMonthsSubscribed = totalMonthsSubscribed; }
public async Task <CommandHandlerResult> ProcessCommand(BotCommand command, TwitchChannel channel) { Quote result; string[] args; switch (command.Command.ToLower()) { case "!quote": args = command.SplitArgumentsOnSpaces(2); //check to see if the command was passed arguments. if (args.Length > 0) { bool hasQuoteNumber; int quoteNumber; // attempt to turn the first argument recieved into an int index to get a specific quote. hasQuoteNumber = Int32.TryParse(args[0], out quoteNumber); if (hasQuoteNumber) { //attempt to get a specificquote; otherwise return a message indicating failure. result = await _apiClient.Quotes.GetSpecificQuoteForPersonalityAsync(channel.Personality, quoteNumber); string responseMessage; if (result == null) { responseMessage = $"Quote number {quoteNumber} doesn't exist. Beg the bot admins to add more quotes."; } else { responseMessage = result.Content; } return(new CommandHandlerResult(ResultType.HandledWithMessage, responseMessage, $"#{channel.Name}")); } } //no args or bad args passed; return a random quote for the personality result = await _apiClient.Quotes.GetRandomQuoteForPersonalityAsync(channel.Personality); return(new CommandHandlerResult(ResultType.HandledWithMessage, result.Content, $"#{channel.Name}")); case "!addquote": //only channel admins can run this command if (channel.Users.Find(u => u.TwitchUsername.ToLower() == command.Sender) == null) { return(new CommandHandlerResult(ResultType.Handled)); } else { result = await _apiClient.Quotes.AddQuoteForPersonalityAsync(channel.Personality, command.Arguments); return(new CommandHandlerResult(ResultType.HandledWithMessage, result.Content, $"#{channel.Name}")); } default: return(new CommandHandlerResult(ResultType.NotHandled)); } }
//need to make a TwitchChannel.cs //use it to store the channel names???? //idk will have to think about how to tackle this at a later date public TwitchChatRoom(TwitchChatConnection chatConnection, TwitchChatConnection whisperConnection, TwitchChannel channel) { this._chatConnection = chatConnection; this._whisperConnection = whisperConnection; this._channel = channel; chatConnection.Join(this); ///joins the chat connection }
public override string getOwnerName(string room) { TwitchChannel data = getChannelJson(room); if (data == null) { return(""); } return(data.display_name); }
//logic for actually monitoring channel. private void ControlLoop() { while (!exit) { string currentTextLine = _inputStream.ReadLine(); /* IRC commands come in one of these formats: * :NICK!USER@HOST COMMAND ARGS ... :DATA\r\n * :SERVER COMAND ARGS ... :DATA\r\n */ //Display received irc message Console.WriteLine(currentTextLine); //if (currentTextLine[0] != ':') continue; //Send pong reply to any ping messages if (currentTextLine.StartsWith("PING ")) { _outputStream.Write(currentTextLine.Replace("PING", "PONG") + "\r\n"); _outputStream.Flush(); } else if (currentTextLine[0] != ':') { continue; } else if (BotCommand.isPotentialCommand(currentTextLine)) { BotCommand command = new BotCommand(currentTextLine); TwitchChannel channel = _channels.Find(c => '#' + c.Name == command.Channel); foreach (ICommandHandler handler in _commandHandlers) { CommandHandlerResult result = handler.ProcessCommand(command, channel).Result; bool breakLoop = false; switch (result.ResultType) { case ResultType.Handled: breakLoop = true; break; case ResultType.HandledWithMessage: SendPrivmsg(result.Channel, result.Message); breakLoop = true; break; default: break; } if (breakLoop) { break; } } } } }
private void SubscribeHandler(TwitchChannel sender, TwitchUser user) { if (PlaySounds) { m_subSound.Play(); } var sub = new Subscriber(sender, this, user); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action <Subscriber>(DispatcherUserSubscribed), sub); }
public async Task <IHttpActionResult> GetTwitchChannel(int id) { TwitchChannel twitchChannel = await db.TwitchChannels.FindAsync(id); if (twitchChannel == null) { return(NotFound()); } return(Ok(twitchChannel)); }
private bool AuthorizeCommand(string username, TwitchChannel twitchChannel) { if (twitchChannel.Users.Find(u => u.TwitchUsername.ToLower() == username) == null) { return(false); } else { return(true); } }
public async Task UpdateChannel(TwitchChannel channel) { /*using (var tx = _stateManager.CreateTransaction()) * { * var channelDictionary = await GetChannelDictionary(tx); * * channelDictionary. * * await tx.CommitAsync(); * }*/ }
private void ChannelListBox_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (ChannelListBox.SelectedItem != null) { TwitchChannel channel = (TwitchChannel)ChannelListBox.SelectedItem; if (channel.Status == "live") { System.Diagnostics.Process.Start($"https://twitch.tv/{channel.Name}"); } } }
async void TimeoutWorker(TwitchChannel chan, TwitchUser user, int duration) { if (duration < 1) { duration = 1; } while (!chan.Timeout(user, duration) && chan.IsJoined) { await Task.Delay(250); } }
public static TwitchChannelPointScale[] ForChannel(TwitchChannel channel) { List<object[]> results = _table.Select(null, null, "ChannelUserId=?a", new object[] { channel.user.id }, "UnitValue", 0); if(results != null && results.Count > 0) { TwitchChannelPointScale[] points = new TwitchChannelPointScale[results.Count]; for(int i = 0; i < results.Count; i++) { points[i] = new SqlTwitchChannelPointScale(channel, results[i][1].FromSql<ulong>(), results[i][2].FromSql<string>(), results[i][3].FromSql<string>()); } return points; } return null; }
public TwitchStream(JToken twitchStreamData) { bool isPlaylist; long id; int viewers, videoHeight, delay; double averageFps; if (bool.TryParse(twitchStreamData.SelectToken("is_playlist").ToString(), out isPlaylist) && isPlaylist) _isPlaylist = true; if (long.TryParse(twitchStreamData.SelectToken("_id").ToString(), out id)) _id = id; if (int.TryParse(twitchStreamData.SelectToken("viewers").ToString(), out viewers)) _viewers = viewers; if (int.TryParse(twitchStreamData.SelectToken("video_height").ToString(), out videoHeight)) _videoHeight = videoHeight; if (int.TryParse(twitchStreamData.SelectToken("delay").ToString(), out delay)) _delay = delay; if (double.TryParse(twitchStreamData.SelectToken("average_fps").ToString(), out averageFps)) _averageFps = averageFps; _game = twitchStreamData.SelectToken("game").ToString(); _createdAt = twitchStreamData.SelectToken("created_at").ToString(); _channel = new TwitchChannel((JObject) twitchStreamData.SelectToken("channel")); _preview = new PreviewObj(twitchStreamData.SelectToken("preview")); }
public static TwitchChannel[] GetAllLiveFollowers(TwitchChannel 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 }; List<object[]> results = _table.Select(join, null, where, vars, null, 0); if(results != null) { TwitchChannel[] channels = new TwitchChannel[results.Count]; for(int i = 0; i < results.Count; i++) { channels[i] = FromSql(results[i]); } return channels; } else { return null; } }
public static TwitchChannel[] GetAll() { List<object[]> results = _table.Select(null, null, null, null, null, 0); if(results != null) { TwitchChannel[] channels = new TwitchChannel[results.Count]; for(int i = 0; i < results.Count; i++) { channels[i] = FromSql(results[i]); } return channels; } else { return null; } }
public static void ClearLiveFollowers(TwitchChannel channel) { _table.Update("join twitch_followers on twitch_followers.UserId=twitch_channels.UserId", "IsLive=?a", "ChannelUserId=?b", new object[] { false, channel.user.id }); }
public static SqlTwitchUserInChannel[] GetAllWithUsernames(TwitchChannel 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) { SqlTwitchUserInChannel[] followers = new SqlTwitchUserInChannel[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 TwitchUserPoints[] GetTopUsersForChannel(TwitchChannel 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) { TwitchUserPoints[] points = new TwitchUserPoints[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 void ClearFollowingBitForAllUsers(TwitchChannel channel) { SqlTwitchChannel.ClearLiveFollowers(channel); }
public SqlTwitchUserInChannel(TwitchUser user, TwitchChannel channel, DateTime created = default(DateTime), bool isCurrentlyFollowing = false, string greetingMessage = null) : base(new object[] { user.id, channel.user.id, created, isCurrentlyFollowing, greetingMessage }) { this.user = user; this.channel = channel; }
public TwitchUserPointManager GetUserPointManager(TwitchChannel channel, TwitchUser user) { return new TwitchUserPointManager(this, channel, user); }
public TwitchUserPoints GetUserPoints(TwitchUser user, TwitchChannel channel) { return new SqlTwitchUserPoints(user, channel); }
public TwitchUserInChannel GetUserInChannel(TwitchUser user, TwitchChannel channel) { return new SqlTwitchUserInChannel(user, channel); }
public TwitchUserPoints[] GetTopUsers(TwitchChannel channel, uint count) { return SqlTwitchUserPoints.GetTopUsersForChannel(channel, count); }
static SqlTwitchUserInChannel FromSql(TwitchChannel channel, object[] results) { if(results != null && results.Length > 0) { if(results.Length > 4) { return new SqlTwitchUserInChannel(new SqlTwitchUser(results[0].FromSql<uint>(), results[4].FromSql<string>()), channel, results[2].FromSql<DateTime>(), results[3].FromSql<bool>()); } else { return new SqlTwitchUserInChannel(new SqlTwitchUser(results[0].FromSql<uint>()), channel, results[2].FromSql<DateTime>(), results[3].FromSql<bool>()); } } else { return null; } }
PointUnit[] LoadUnits(TwitchChannel channel) { TwitchChannelPointScale[] points = factory.GetChannelPointScale(channel); if(points != null && points.Length > 0) { PointUnit[] units = new PointUnit[points.Length]; for(int i = 0; i < points.Length; i++) { units[i] = new PointUnit(points[i].unitNameSingular, points[i].unitNamePlural, points[i].unitValue); } return units; } return null; }
public TwitchUserInChannel[] GetAllUserInChannels(TwitchChannel channel) { return SqlTwitchUserInChannel.GetAllWithUsernames(channel); }
public static SqlTwitchUserInChannel GetMostRecent(TwitchChannel 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 TwitchChannelPointScale[] GetChannelPointScale(TwitchChannel channel) { return SqlTwitchChannelPointScale.ForChannel(channel); }
public TwitchChatChannelEvent(TwitchChannel channel) { this.channel = channel; }
public TwitchChatMessage(TwitchChannel channel, TwitchUser speaker, string message) : base(channel) { this.speaker = speaker; this.message = message?.Trim(); }
public TwitchUserPointManager(ITwitchFactory factory, TwitchChannel channel, TwitchUser user) { sqlPoints = factory.GetUserPoints(user, channel); }
public ChannelPointManager(ITwitchFactory factory, TwitchChannel channel) { this.factory = factory; this.channel = channel; units = LoadUnits(channel); }
public TwitchChannel[] GetAllLiveFollowers(TwitchChannel channel) { return SqlTwitchChannel.GetAllLiveFollowers(channel); }
public static void ClearAll(TwitchChannel channel) { _table.Update(null, "IsCurrentlyFollowing=?a", "ChannelUserId=?b", new object[] { false, channel.user.id }); }