/// <summary> /// Attemt connection to PubSub server, after fetching channelIDs from Twitch API. /// </summary> /// <param name="credentials">Caster credentials, to requests private PubSub events.</param> public async Task <bool> Connect(TwitchCredentials credentials) { if (credentials.IsCaster) { // Set caster credentials _casterCredentials = credentials; try { v5User authUser = await TwitchAPIv5.GetUser(credentials.OAuth); if (authUser != null) { _userId = authUser.Id; _wsclient.ConnectAsync(); return(true); } else { return(false); } } catch { return(false); } } else { return(false); } }
/// <summary> /// Start connection to the Twitch IRC Chat. /// </summary> /// <param name="secure">Secure SSL connection or not.</param> public async void Connect(bool secure, TwitchCredentials credentials) { _credentials = credentials; // Set used port and connect to Twitch IRC connection int port = secure ? 443 : 6667; await _tcpClient.ConnectAsync("irc.chat.twitch.tv", port, secure, RATELIMIT_NOMOD); }
public void SetCredentials(TwitchCredentials credentials) { if (credentials.IsCaster) { _casteraccount = credentials; } else { _botaccount = credentials; } }
/* https://dev.twitch.tv/docs/api/reference#get-users */ /// <summary> /// Gets information about the user associated with the supplied oauth. /// Returns <see cref="User"/> model of the user associated with supplied oauth. /// </summary> /// <param name="caster">Caster <see cref="TwitchCredentials"/> containing a set oauth.</param> /// <exception cref="ArgumentNullException"/> /// <exception cref="TwitchAPIException"/> internal static async Task <User> GetUser(TwitchCredentials caster) { if (caster == null) { throw new ArgumentNullException("caster", "Argument cannot be null."); } try { var blob = await TwitchAPIRequests.GetRequest($"https://api.twitch.tv/helix/users", caster.OAuth); return((JsonConvert.DeserializeObject <TwitchApiResponse <User> >(blob, jSettings)).Data[0]); } catch (WebException ex) { throw new TwitchAPIException(ex.Message, ((HttpWebResponse)ex.Response).StatusCode); } }
public TwitchChatOpperatorChangedEventArgs(TwitchCredentials credentials, string username, bool isOpperator) : base(credentials) { Username = username; IsOpperator = isOpperator; }
public TwitchChatMessageReceivedEventArgs(TwitchCredentials credentials, TwitchChatMessage chatmessage) : base(credentials) { ChatMessage = chatmessage; }
public TwitchChatAuthenticationEventArgs(TwitchCredentials credentials, bool successful) : base(credentials) { Successfull = successful; }
public TwitchChatDisconnectedEventArgs(TwitchCredentials credentials, string reason) : base(credentials) { Reason = reason; }
public TwitchChatConnectedEventArgs(TwitchCredentials credentials) : base(credentials) { }
public TwitchChatEventArgs(TwitchCredentials credentials) { ClientCredentials = credentials; }
public TwitchChatChatterChangedEventArgs(TwitchCredentials credentials, string username, bool hasParted) : base(credentials) { Username = username; HasParted = hasParted; }
public TwitchChatChatterListReceivedEventArgs(TwitchCredentials credentials, IList <string> usernames) : base(credentials) { Usernames = usernames; }