async void BanWorker(TwitchChannel chan, TwitchUser user) { while (!chan.Ban(user) && chan.IsJoined) await Task.Delay(250); }
public TwitchChannel Create(string channel) { if (string.IsNullOrEmpty(channel) || channel[0] == '#') throw new ArgumentException("channel"); channel = channel.ToLower(); TwitchChannel twitchChannel; lock (m_channels) { if (!m_channels.TryGetValue(channel, out twitchChannel)) { twitchChannel = new TwitchChannel(this, channel); m_channels[channel] = twitchChannel; } } return twitchChannel; }
private void HandleJtvMessage(TwitchChannel chan, string text, int offset) { switch (text[offset]) { case 'E': ParseEmoteSet(text, offset); break; case 'C': Debug.Assert(chan != null); chan.ParseChatClear(text, offset); break; case 'S': ParseSpecialUser(chan, text, offset); break; case 'T': Debug.Assert(chan != null); string modMsg = "The moderators of this room are: "; string slowMode = "This room is now in slow mode. You may send messages every "; string slowOff = "This room is no longer in slow mode."; string subMode = "This room is now in subscribers-only mode."; string subModeOff = "This room is no longer in subscribers-only mode."; if (text.StartsWith(modMsg, offset)) chan.ParseModerators(text, offset, offset + modMsg.Length); else if (text.StartsWith(slowMode, offset)) chan.ParseSlowMode(slowMode, offset + slowMode.Length); else if (text.StartsWith(slowOff, offset)) chan.SlowOff(); else if (text.StartsWith(subMode, offset)) chan.SubMode(); else if (text.StartsWith(subModeOff, offset)) chan.SubModeOff(); else chan.RawJtvMessage(text, offset); break; case 'H': Debug.Assert(text.StartsWith("HISTORYEND", offset)); break; case 'U': ParseUserColor(text, offset); break; default: Debug.Assert(chan != null); chan.RawJtvMessage(text, offset); return; } }
public ChatMessage(TwitchChannel channel, MainWindow controller, TwitchUser user, string message, bool question) : base(channel, controller, question ? ItemType.Question : ItemType.Message) { User = user; Message = message; }
public ChatAction(TwitchChannel channel, MainWindow controller, TwitchUser user, string message) : base(channel, controller, ItemType.Action, user, message) { }
private static async void TimeoutUserList(int duration, TwitchChannel channel, TwitchUser[] users) { foreach (var user in users) { if (duration == -1) { while (!channel.Ban(user)) await Task.Delay(250); } else { while (!channel.Timeout(user, duration)) await Task.Delay(250); } } }
public ChatItem(TwitchChannel channel, MainWindow controller, ItemType type) { Channel = channel; Controller = controller; Type = type; }
TwitchConnection LeaveChannel() { var channel = m_channel; if (channel == null) return null; lock (m_sync) { if (m_channel == null) return null; channel = m_channel; m_channel = null; } channel.Leave(); channel.ModeratorJoined -= ModJoined; channel.UserChatCleared -= UserClearChatHandler; channel.MessageReceived -= ChatMessageReceived; channel.MessageSent -= ChatMessageReceived; channel.StatusMessageReceived -= JtvMessageReceived; channel.ActionReceived -= ChatActionReceived; channel.UserSubscribed -= SubscribeHandler; channel.ChatCleared -= ChatCleared; channel.SlowModeBegin -= SlowModeHandler; channel.SlowModeEnd -= SlowModeEndHandler; channel.SubModeBegin -= SubModeBeginHandler; channel.SubModeEnd -= SubModeEndHandler; channel.ModListReceived -= ModListReceived; return channel.Connection; }
private void ChatCleared(TwitchChannel channel) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, "Chat was cleared by a moderator")); }
void ModListReceived(TwitchChannel channel, TwitchUser[] moderators) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchChannel>(ModListReceivedWorker), channel); }
private void ModListReceivedWorker(TwitchChannel channel) { // Setting initial state, it's ok we haven't joined the channel yet. var currUser = CurrentUser = channel.GetUser(m_options.User); if (currUser.IsModerator) ModJoined(channel, currUser); else ModLeft(channel, currUser); }
async void ChangeChannel(string newChannel) { var twitch = LeaveChannel(); if (twitch == null) m_channel = await Connect(newChannel); else m_channel = JoinChannel(twitch, newChannel); }
private async void Reconnect(string channelName) { Disconnect(); m_channel = await Connect(channelName); }
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); }
private void ModJoined(TwitchChannel conn, TwitchUser user) { if (user == CurrentUser) ModButtonVisibility = Visibility.Visible; }
private void SlowModeEndHandler(TwitchChannel channel) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, "This room is no longer in subscribers-only mode.")); }
private void ModLeft(TwitchChannel conn, TwitchUser user) { if (user == CurrentUser) ModButtonVisibility = Visibility.Collapsed; }
private void SlowModeHandler(TwitchChannel channel, int time) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, string.Format("This room is now in slow mode. You may send messages every {0} seconds.", time))); }
async void LoadAsyncData() { var connectTask = Connect(m_channelName); string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); m_cache = System.IO.Path.Combine(path, "TwitchChat"); var task = TwitchApi.GetEmoticonData(m_cache); GetChannelData(); Emoticons = await task; m_channel = await connectTask; }
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 Subscriber(TwitchChannel channel, MainWindow controller, TwitchUser user) : base(channel, controller, ItemType.Subscriber) { User = user; }
private void ChatActionReceived(TwitchChannel sender, TwitchUser user, string text) { if (m_options.Ignore.Contains(user.Name)) return; var emotes = Emoticons; if (emotes != null) emotes.EnsureDownloaded(user.ImageSet); Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new ChatAction(sender, this, user, text)); }
public ChatMessage(TwitchChannel channel, MainWindow controller, ItemType type, TwitchUser user, string message) : base(channel, controller, type) { User = user; Message = message; }
private void JtvMessageReceived(TwitchChannel sender, string text) { if (text.StartsWith("The moderators of this")) { if (m_modListRequested) m_modListRequested = false; else return; } WriteStatus(text); }
public StatusMessage(TwitchChannel channel, MainWindow controller, string message) : base(channel, controller, ItemType.Status) { Message = message; }
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)); }
public TwitchChannel GetChannel(string channel) { channel = channel.ToLower(); var twitchChannel = m_lastChannel; if (twitchChannel != null && twitchChannel.Name == channel) return twitchChannel; bool created = false; lock (m_channels) { if (!m_channels.TryGetValue(channel, out twitchChannel)) { twitchChannel = m_channels[channel] = new TwitchChannel(this, channel); created = true; } } if (created) { var evt = ChannelCreated; if (evt != null) evt(this, twitchChannel); } m_lastChannel = twitchChannel; return twitchChannel; }
private void UserClearChatHandler(TwitchChannel sender, TwitchUser user) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchUser>(DispatcherClearChat), user); }
internal void ParseSpecialUser(TwitchChannel chan, string text, int offset) { //* SPECIALUSER username subscriber string specialuser = "******"; if (!text.StartsWith(specialuser, offset)) { Debug.Fail("ParseSpecialUser received unexpected string start."); return; } offset += specialuser.Length; int i = text.IndexOf(' ', offset); string name = text.Slice(offset, i); if (text.EndsWith("subscriber")) { if (chan == null) { Debug.Fail("Subscriber message sent to non-channel."); return; } var user = chan.GetUser(name); user.IsSubscriber = true; } else if (text.EndsWith("turbo")) { var user = GetUserData(name); user.IsTurbo = true; } else if (text.EndsWith("admin")) { var user = GetUserData(name); user.IsAdmin = true; } else if (text.EndsWith("staff")) { var user = GetUserData(name); user.IsStaff = true; } else { Debug.Fail(string.Format("Parse SpecialMessage could not parse {0}", text)); } }
static async Task<TwitchChannel[]> ConnectAsync(params string[] channelNames) { TwitchConnection twitch = new TwitchConnection(); string[] loginData = File.ReadLines("login.txt").Take(2).ToArray(); var connectResult = await twitch.ConnectAsync(loginData[0], loginData[1]); if (connectResult != ConnectResult.Connected) { Console.WriteLine("Failed to login."); return null; } //TwitchChannel result = Create(channel); //await result.JoinAsync(); //return result; TwitchChannel[] channels = (from channelName in channelNames select twitch.Create(channelName)).ToArray(); Task[] channelTasks = (from channel in channels select channel.JoinAsync()).ToArray(); var result = new TwitchChannel[channelTasks.Length]; for (int i = 0; i < result.Length; ++i) await channelTasks[i]; return channels; }