public static async Task <Result> ConnectUser(SettingsV3Model settings) { Result userResult = null; ChannelSession.Settings = settings; // Twitch connection if (!ChannelSession.Settings.StreamingPlatformAuthentications.ContainsKey(StreamingPlatformTypeEnum.Twitch)) { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch] = new StreamingPlatformAuthenticationSettingsModel(StreamingPlatformTypeEnum.Twitch); } Result <TwitchPlatformService> twitchResult = twitchResult = await TwitchPlatformService.Connect(ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchUserConnection = twitchResult.Value; userResult = twitchResult; } else { userResult = await ChannelSession.ConnectTwitchUser(); } if (userResult.Success) { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].IsEnabled = true; ChannelSession.TwitchUserNewAPI = await ChannelSession.TwitchUserConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchUserNewAPI == null) { return(new Result("Failed to get Twitch user data")); } ChannelSession.TwitchUserV5 = await ChannelSession.TwitchUserConnection.GetV5APIUserByLogin(ChannelSession.TwitchUserNewAPI.login); if (ChannelSession.TwitchUserV5 == null) { return(new Result("Failed to get V5 API Twitch user data")); } if (ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken != null) { twitchResult = await TwitchPlatformService.Connect(ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchBotConnection = twitchResult.Value; ChannelSession.TwitchBotNewAPI = await ChannelSession.TwitchBotConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchBotNewAPI == null) { return(new Result("Failed to get Twitch bot data")); } } else { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken = null; return(new Result(success: true, message: "Failed to connect Twitch bot account, please manually reconnect")); } } } else { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch] = null; return(userResult); } return(userResult); }
public static async Task <Result> ConnectUser(SettingsV3Model settings) { Result userResult = new Result(success: false); try { ChannelSession.Settings = settings; // Twitch connection if (!ChannelSession.Settings.StreamingPlatformAuthentications.ContainsKey(StreamingPlatformTypeEnum.Twitch)) { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch] = new StreamingPlatformAuthenticationSettingsModel(StreamingPlatformTypeEnum.Twitch); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "Assigning of initial Settings failed"); throw ex; } Result <TwitchPlatformService> twitchResult = new Result <TwitchPlatformService>(success: false, (TwitchPlatformService)null); try { twitchResult = twitchResult = await TwitchPlatformService.Connect(ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchUserConnection = twitchResult.Value; userResult = twitchResult; } else { userResult = await ChannelSession.ConnectTwitchUser(); } } catch (Exception ex) { Logger.Log(ex); } try { if (userResult != null && userResult.Success) { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].IsEnabled = true; ChannelSession.TwitchUserNewAPI = await ChannelSession.TwitchUserConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchUserNewAPI == null) { return(new Result(Resources.TwitchFailedNewAPIUserData)); } ChannelSession.TwitchUserV5 = await ChannelSession.TwitchUserConnection.GetV5APIUserByLogin(ChannelSession.TwitchUserNewAPI.login); if (ChannelSession.TwitchUserV5 == null) { return(new Result(Resources.TwitchFailedV5APIUserData)); } try { if (ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken != null) { twitchResult = await TwitchPlatformService.Connect(ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchBotConnection = twitchResult.Value; ChannelSession.TwitchBotNewAPI = await ChannelSession.TwitchBotConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchBotNewAPI == null) { return(new Result(Resources.TwitchFailedBotData)); } } else { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken = null; return(new Result(success: true, message: "Failed to connect Twitch bot account, please manually reconnect")); } } } catch (Exception ex) { Logger.Log(LogLevel.Error, "Getting bot details failed"); throw ex; } } else { ChannelSession.Settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken = null; return(userResult); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "Getting user details failed"); throw ex; } return(userResult); }
public static async Task <Result> ConnectUser(SettingsV2Model settings) { Result userResult = null; ChannelSession.Settings = settings; // Twitch connection Result <TwitchPlatformService> twitchResult = await TwitchPlatformService.Connect(ChannelSession.Settings.TwitchUserOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchUserConnection = twitchResult.Value; userResult = twitchResult; } else { userResult = await ChannelSession.ConnectTwitchUser(ChannelSession.Settings.IsStreamer); } if (userResult.Success) { ChannelSession.TwitchUserNewAPI = await ChannelSession.TwitchUserConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchUserNewAPI == null) { return(new Result("Failed to get Twitch user data")); } ChannelSession.TwitchUserV5 = await ChannelSession.TwitchUserConnection.GetV5APIUserByLogin(ChannelSession.TwitchUserNewAPI.login); if (ChannelSession.TwitchUserV5 == null) { return(new Result("Failed to get V5 API Twitch user data")); } if (settings.TwitchBotOAuthToken != null) { twitchResult = await TwitchPlatformService.Connect(settings.TwitchBotOAuthToken); if (twitchResult.Success) { ChannelSession.TwitchBotConnection = twitchResult.Value; ChannelSession.TwitchBotNewAPI = await ChannelSession.TwitchBotConnection.GetNewAPICurrentUser(); if (ChannelSession.TwitchBotNewAPI == null) { return(new Result("Failed to get Twitch bot data")); } } else { settings.TwitchBotOAuthToken = null; return(new Result(success: true, message: "Failed to connect Twitch bot account, please manually reconnect")); } } } else { ChannelSession.Settings.TwitchUserOAuthToken = null; return(userResult); } return(userResult); }