private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { await this.RunAsyncOperation(async() => { this.DataContext = this.viewModel = new MainWindowViewModel(); if (!await this.viewModel.Initialize()) { this.Close(); return; } PrivatePopulatedUserModel currentUser = await this.viewModel.GetCurrentUser(); if (currentUser != null) { this.Title += " - " + currentUser.username; } Task.Run(async() => { while (true) { try { await this.viewModel.Run(); } catch (Exception ex) { Logger.Log(ex); } await Task.Delay(1000 * 60); } }).Wait(1); }); }
public static async Task <UserModel> GetCurrentUser(MixerClient client) { ChannelModel channel = await ChannelsServiceUnitTests.GetChannel(client); PrivatePopulatedUserModel user = await client.Users.GetCurrentUser(); Assert.IsNotNull(user); Assert.IsTrue(user.id > (uint)0); return(user); }
public async void AttemptLogin() { // hide login grid LoginGrid.Visibility = Visibility.Visible; // show main grid MainGrid.Visibility = Visibility.Collapsed; // attempt to login and authenticate with OAuth _connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], _scopes); // check that we logged in and got a connection if (_connection != null) { // get the current logged in user _user = await _connection.Users.GetCurrentUser(); // get the channel we want to connect to _channel = await _connection.Channels.GetChannel("SmiteGame"); // create a chat client so we can connect to the chat _chatClient = await ChatClient.CreateFromChannel(_connection, _channel); // attach an event handler incase we disconnect from chat _chatClient.OnDisconnectOccurred += ChatClient_OnDisconnectOccurred; // try and connect + authenticate with the chat client (will fail if banned from chat etc...) if (await _chatClient.Connect() && await _chatClient.Authenticate()) { // set logged in user on ui ChannelUserTextBlock.Text = _user.username; // set stream title on ui StreamTitleTextBox.Text = _channel.name; // set game title on ui GameTitleTextBlock.Text = _channel.type.name; // set connection status on ui ConnectionStatus.Text = "Connected"; // set stream online status on ui StreamStatus.Text = _channel.online.ToString(); // set taskbar hover text to show we're connected MainIcon.ToolTipText = "Smite Mixer Idler (Connected)"; // set the icon to the coloured version MainIcon.Icon = Properties.Resources.lumbridgeAvatar; // show a notification to the user saying we connected and authenticated successfully MainIcon.ShowBalloonTip("Smite Mixer Idler", "Successfully connected to chat.", Properties.Resources.lumbridgeAvatar, true); // hide the login grid LoginGrid.Visibility = Visibility.Collapsed; // show the main grid MainGrid.Visibility = Visibility.Visible; } } }
public static async Task RefreshUser() { if (ChannelSession.User != null) { PrivatePopulatedUserModel user = await ChannelSession.Connection.GetCurrentUser(); if (user != null) { ChannelSession.User = user; } } }
public void GetCurrentBroadcast() { TestWrapper(async(MixerConnection connection) => { PrivatePopulatedUserModel user = await connection.Users.GetCurrentUser(); Assert.IsNotNull(user); Assert.IsTrue(user.id > 0); bool success = await connection.Ads.RunAd(user.channel); Assert.IsTrue(success); }); }
public void GetTestStreamSettings() { TestWrapper(async(MixerConnection connection) => { PrivatePopulatedUserModel user = await connection.Users.GetCurrentUser(); Assert.IsNotNull(user); Assert.IsTrue(user.id > 0); TestStreamSettingsModel testStreamSettings = await connection.TestStreams.GetSettings(user.channel); Assert.IsNotNull(testStreamSettings); Assert.IsTrue(testStreamSettings.id > 0); }); }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginGrid.Visibility = Visibility.Visible; this.MainGrid.Visibility = Visibility.Collapsed; List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.chat__chat, OAuthClientScopeEnum.chat__connect, OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; this.connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], scopes); List <string> following = new List <string>(); if (this.connection != null) { this.user = await this.connection.Users.GetCurrentUser(); this.follows = await this.connection.Users.GetFollows(user); this.UserName.Text = this.user.username; foreach (var follow in follows) { following.Add(follow.token); } this.Avatar.Navigate("https://mixer.com/api/v1/users/" + user.channel.userId + "/avatar?w=60&h=60"); this.Follows.ItemsSource = following; } this.LoginGrid.Visibility = Visibility.Collapsed; this.MainGrid.Visibility = Visibility.Visible; }
private static async Task <bool> InitializeBotInternal() { PrivatePopulatedUserModel user = await ChannelSession.BotConnection.GetCurrentUser(); if (user != null) { ChannelSession.BotUser = user; ChannelSession.BotConnection.Initialize(); await ChannelSession.Chat.ConnectBot(); await ChannelSession.SaveSettings(); return(true); } return(false); }
public void GetClipsForChannel() { TestWrapper(async(MixerConnection connection) => { PrivatePopulatedUserModel user = await connection.Users.GetCurrentUser(); Assert.IsNotNull(user); IEnumerable <ClipModel> clips = await connection.Clips.GetChannelClips(user.channel); Assert.IsNotNull(clips); Assert.IsTrue(clips.Count() > 0); ClipModel clip = await connection.Clips.GetClip(clips.FirstOrDefault().shareableId); Assert.IsNotNull(clip); Assert.IsTrue(clip.shareableId.Equals(clips.FirstOrDefault().shareableId)); }); }
private async void Login_Click(object sender, RoutedEventArgs e) { Connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(Settings.Default.ClientId, GetScope()); if (Connection != null) { User = await Connection.Users.GetCurrentUser(); Channel = await Connection.Channels.GetChannel(Settings.Default.Channel); ChatClient = await ChatClient.CreateFromChannel(Connection, Channel); ChatClient.OnMessageOccurred += ChatClient_MessageOccurred; ChatClient.OnDisconnectOccurred += ChatClient_OnDisconnectOccurred; if (await ChatClient.Connect() && await ChatClient.Authenticate()) { Log("connected"); } } }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginGrid.Visibility = Visibility.Visible; this.MainGrid.Visibility = Visibility.Collapsed; List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.interactive__manage__self, OAuthClientScopeEnum.interactive__robot__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; this.connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], scopes); if (this.connection != null) { this.user = await this.connection.Users.GetCurrentUser(); this.channel = await this.connection.Channels.GetChannel(this.user.username); this.games = new List <InteractiveGameListingModel>(await this.connection.Interactive.GetOwnedInteractiveGames(this.channel)); this.GameSelectComboBox.ItemsSource = this.games.Select(g => g.name); this.LoginGrid.Visibility = Visibility.Collapsed; this.GameSelectGrid.Visibility = Visibility.Visible; } }
private static async Task <bool> InitializeInternal(string channelName = null) { PrivatePopulatedUserModel user = await ChannelSession.Connection.GetCurrentUser(); if (user != null) { ExpandedChannelModel channel = await ChannelSession.Connection.GetChannel((channelName == null)?user.username : channelName); if (channel != null) { ChannelSession.User = user; ChannelSession.Channel = channel; if (ChannelSession.Settings == null) { ChannelSession.Settings = ChannelSession.Services.Settings.Create(channel, (channelName == null)); } await ChannelSession.Services.Settings.Initialize(ChannelSession.Settings); ChannelSession.Settings.Channel = channel; ChannelSession.Connection.Initialize(); if (!await ChannelSession.Chat.Connect() || !await ChannelSession.Constellation.Connect()) { return(false); } if (!string.IsNullOrEmpty(ChannelSession.Settings.OBSStudioServerIP)) { await ChannelSession.Services.InitializeOBSWebsocket(); } if (ChannelSession.Settings.EnableStreamlabsOBSConnection) { await ChannelSession.Services.InitializeStreamlabsOBSService(); } if (ChannelSession.Settings.EnableXSplitConnection) { await ChannelSession.Services.InitializeXSplitServer(); } if (ChannelSession.Settings.EnableOverlay) { await ChannelSession.Services.InitializeOverlayServer(); } if (ChannelSession.Settings.EnableDeveloperAPI) { await ChannelSession.Services.InitializeDeveloperAPI(); } if (ChannelSession.Settings.StreamlabsOAuthToken != null) { await ChannelSession.Services.InitializeStreamlabs(); } if (ChannelSession.Settings.GameWispOAuthToken != null) { await ChannelSession.Services.InitializeGameWisp(); } if (ChannelSession.Settings.GawkBoxOAuthToken != null) { await ChannelSession.Services.InitializeGawkBox(); } if (ChannelSession.Settings.TwitterOAuthToken != null) { await ChannelSession.Services.InitializeTwitter(); } if (ChannelSession.Settings.SpotifyOAuthToken != null) { await ChannelSession.Services.InitializeSpotify(); } if (ChannelSession.Settings.DiscordOAuthToken != null) { await ChannelSession.Services.InitializeDiscord(); } if (ChannelSession.Settings.TiltifyOAuthToken != null) { await ChannelSession.Services.InitializeTiltify(); } foreach (CommandBase command in ChannelSession.AllCommands) { foreach (ActionBase action in command.Actions) { if (action is CounterAction) { await((CounterAction)action).SetCounterValue(); } } } if (ChannelSession.Settings.DefaultInteractiveGame > 0) { IEnumerable <InteractiveGameListingModel> games = await ChannelSession.Connection.GetOwnedInteractiveGames(ChannelSession.Channel); InteractiveGameListingModel game = games.FirstOrDefault(g => g.id.Equals(ChannelSession.Settings.DefaultInteractiveGame)); if (game != null) { if (!await ChannelSession.Interactive.Connect(game)) { await ChannelSession.Interactive.Disconnect(); } } else { ChannelSession.Settings.DefaultInteractiveGame = 0; } } await ChannelSession.SaveSettings(); await ChannelSession.Services.Settings.SaveBackup(ChannelSession.Settings); if (!Util.Logger.IsDebug) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await ChannelSession.Services.MixItUpService.SendLoginEvent(new LoginEvent(ChannelSession.Settings.IsStreamer.ToString())); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } GlobalEvents.OnRankChanged += GlobalEvents_OnRankChanged; return(true); } } return(false); }
public async Task Run() { IEnumerable <ChannelHostModel> channels = this.Channels.ToList(); HostingOrderEnum hostOrder = EnumHelper.GetEnumValueFromString <HostingOrderEnum>(this.HostingOrder); AgeRatingEnum ageRating = EnumHelper.GetEnumValueFromString <AgeRatingEnum>(this.AgeRating); PrivatePopulatedUserModel currentUser = await this.connection.Users.GetCurrentUser(); if (currentUser != null && !currentUser.channel.online) { bool keepCurrentHost = false; if (currentUser.channel.hosteeId != null) { ExpandedChannelModel channel = await this.connection.Channels.GetChannel(currentUser.channel.hosteeId.GetValueOrDefault()); if (channel != null) { AgeRatingEnum channelAgeRating = EnumHelper.GetEnumValueFromString <AgeRatingEnum>(channel.audience); if (channelAgeRating <= ageRating) { keepCurrentHost = true; this.CurrentlyHosting = new ChannelHostModel() { ID = channel.userId, Name = channel.user.username, }; } } } if (!keepCurrentHost) { this.CurrentlyHosting = null; } if (this.CurrentlyHosting != null) { await this.UpdateChannel(this.CurrentlyHosting); } if (this.IsAutoHostingEnabled && (this.CurrentlyHosting == null || !this.CurrentlyHosting.IsOnline)) { if (hostOrder == HostingOrderEnum.Random) { channels = channels.OrderBy(c => Guid.NewGuid()); } foreach (ChannelHostModel channel in channels) { if (channel.IsEnabled) { ChannelModel channelModel = await this.UpdateChannel(channel); AgeRatingEnum channelAgeRating = EnumHelper.GetEnumValueFromString <AgeRatingEnum>(channelModel.audience); if (channelModel != null && channel.IsOnline && channelAgeRating <= ageRating) { ChannelModel updatedChannel = await this.connection.Channels.SetHostChannel(currentUser.channel, channelModel); if (updatedChannel.hosteeId.GetValueOrDefault() == channelModel.id) { this.CurrentlyHosting = channel; break; } } } } } } await this.SaveData(); }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginButton.IsEnabled = false; string clientID = ConfigurationManager.AppSettings["ClientID"]; if (string.IsNullOrEmpty(clientID)) { throw new ArgumentException("ClientID value isn't set in application configuration"); } this.connection = await MixerConnection.ConnectViaShortCode(clientID, new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.chat__chat, OAuthClientScopeEnum.chat__connect, OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }, (OAuthShortCodeModel code) => { this.ShortCodeTextBox.Text = code.code; Process.Start("https://mixer.com/oauth/shortcode"); }); if (this.connection != null) { this.user = await this.connection.Users.GetCurrentUser(); this.channel = await this.connection.Channels.GetChannel(this.user.username); this.chatClient = await ChatClient.CreateFromChannel(this.connection, channel); this.chatClient.OnDisconnectOccurred += ChatClient_OnDisconnectOccurred; this.chatClient.OnMessageOccurred += ChatClient_MessageOccurred; this.chatClient.OnUserJoinOccurred += ChatClient_UserJoinOccurred; this.chatClient.OnUserLeaveOccurred += ChatClient_UserLeaveOccurred; this.chatClient.OnUserTimeoutOccurred += ChatClient_UserTimeoutOccurred; this.chatClient.OnUserUpdateOccurred += ChatClient_UserUpdateOccurred; this.chatClient.OnPollStartOccurred += ChatClient_PollStartOccurred; this.chatClient.OnPollEndOccurred += ChatClient_PollEndOccurred; this.chatClient.OnPurgeMessageOccurred += ChatClient_PurgeMessageOccurred; this.chatClient.OnDeleteMessageOccurred += ChatClient_DeleteMessageOccurred; this.chatClient.OnClearMessagesOccurred += ChatClient_ClearMessagesOccurred; IEnumerable <ChatUserModel> users = await this.connection.Chats.GetUsers(this.channel); this.viewerCount = users.Count(); this.CurrentViewersTextBlock.Text = this.viewerCount.ToString(); if (await this.chatClient.Connect() && await this.chatClient.Authenticate()) { this.LoginGrid.Visibility = Visibility.Collapsed; this.ChatGrid.Visibility = Visibility.Visible; } } this.LoginButton.IsEnabled = true; }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginGrid.Visibility = Visibility.Visible; this.MainGrid.Visibility = Visibility.Collapsed; this.ChatListView.ItemsSource = this.chatMessages; this.UsersListView.ItemsSource = this.chatUsers; List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.chat__bypass_links, OAuthClientScopeEnum.chat__bypass_slowchat, OAuthClientScopeEnum.chat__change_ban, OAuthClientScopeEnum.chat__change_role, OAuthClientScopeEnum.chat__chat, OAuthClientScopeEnum.chat__connect, OAuthClientScopeEnum.chat__clear_messages, OAuthClientScopeEnum.chat__edit_options, OAuthClientScopeEnum.chat__giveaway_start, OAuthClientScopeEnum.chat__poll_start, OAuthClientScopeEnum.chat__poll_vote, OAuthClientScopeEnum.chat__purge, OAuthClientScopeEnum.chat__remove_message, OAuthClientScopeEnum.chat__timeout, OAuthClientScopeEnum.chat__view_deleted, OAuthClientScopeEnum.chat__whisper, OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; this.connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], scopes); if (this.connection != null) { this.user = await this.connection.Users.GetCurrentUser(); this.channel = await this.connection.Channels.GetChannel(this.user.username); this.chatClient = await ChatClient.CreateFromChannel(this.connection, this.channel); this.chatClient.OnMessageOccurred += ChatClient_MessageOccurred; this.chatClient.OnUserJoinOccurred += ChatClient_UserJoinOccurred; this.chatClient.OnUserLeaveOccurred += ChatClient_UserLeaveOccurred; this.chatClient.OnUserTimeoutOccurred += ChatClient_UserTimeoutOccurred; this.chatClient.OnUserUpdateOccurred += ChatClient_UserUpdateOccurred; this.chatClient.OnPollStartOccurred += ChatClient_PollStartOccurred; this.chatClient.OnPollEndOccurred += ChatClient_PollEndOccurred; this.chatClient.OnPurgeMessageOccurred += ChatClient_PurgeMessageOccurred; this.chatClient.OnDeleteMessageOccurred += ChatClient_DeleteMessageOccurred; this.chatClient.OnClearMessagesOccurred += ChatClient_ClearMessagesOccurred; if (await this.chatClient.Connect() && await this.chatClient.Authenticate()) { this.ChannelUserTextBlock.Text = this.user.username; this.StreamTitleTextBox.Text = this.channel.name; this.GameTitleTextBlock.Text = this.channel.type.name; foreach (ChatUserModel user in await this.connection.Chats.GetUsers(this.chatClient.Channel)) { this.chatUsers.Add(new ChatUser(user)); } this.LoginGrid.Visibility = Visibility.Collapsed; this.MainGrid.Visibility = Visibility.Visible; } } }
public async Task Run() { IEnumerable <ChannelHostModel> channels = this.Channels.ToList(); HostingOrderEnum hostOrder = this.settings.HostingOrder; AgeRatingEnum ageRating = this.settings.AgeRating; PrivatePopulatedUserModel currentUser = await this.connection.Users.GetCurrentUser(); if (currentUser != null && !currentUser.channel.online) { bool keepCurrentHost = false; if (currentUser.channel.hosteeId != null) { ExpandedChannelModel channel = await this.connection.Channels.GetChannel(currentUser.channel.hosteeId.GetValueOrDefault()); if (channel != null) { AgeRatingEnum channelAgeRating = EnumHelper.GetEnumValueFromString <AgeRatingEnum>(channel.audience); if (channelAgeRating <= ageRating) { keepCurrentHost = true; this.CurrentlyHosting = new ChannelHostModel() { ID = channel.userId, Name = channel.token, }; } } } if (!keepCurrentHost) { this.CurrentlyHosting = null; } if (this.CurrentlyHosting != null) { await this.UpdateChannel(this.CurrentlyHosting); this.totalMinutesHosted++; } if (this.IsAutoHostingEnabled && (this.CurrentlyHosting == null || !this.CurrentlyHosting.IsOnline || (this.settings.MaxHostLength > 0 && this.totalMinutesHosted >= this.settings.MaxHostLength))) { Base.Util.Logger.Log("Attempting to find new host..."); if (hostOrder == HostingOrderEnum.Random) { if (this.CurrentlyHosting != null) { channels = channels.Where(c => !c.ID.Equals(this.CurrentlyHosting.ID)); } channels = channels.OrderBy(c => Guid.NewGuid()); } foreach (ChannelHostModel channel in channels) { if (channel.IsEnabled) { ChannelModel channelModel = await this.UpdateChannel(channel); AgeRatingEnum channelAgeRating = EnumHelper.GetEnumValueFromString <AgeRatingEnum>(channelModel.audience); if (channelModel != null && channel.IsOnline && channelAgeRating <= ageRating) { if (this.CurrentlyHosting != null && channelModel.id.Equals(this.CurrentlyHosting.ID)) { this.totalMinutesHosted = 0; break; } else { ChannelModel updatedChannel = await this.connection.Channels.SetHostChannel(currentUser.channel, channelModel); if (updatedChannel.hosteeId.GetValueOrDefault() == channelModel.id) { Base.Util.Logger.Log("Now hosting " + channelModel.token); await this.SaveData(); this.CurrentlyHosting = channel; this.totalMinutesHosted = 0; if (!string.IsNullOrEmpty(this.WhisperMessage)) { ChatClient chatClient = ChatClient.CreateFromChannel(connection, channelModel).Result; if (chatClient.Connect().Result&& chatClient.Authenticate().Result) { await Task.Delay(3000); await chatClient.Whisper(channelModel.token, this.WhisperMessage); await Task.Delay(3000); } await chatClient.Disconnect(); } break; } } } } } } } else { this.totalMinutesHosted = 0; } }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginButton.IsEnabled = false; string clientID = ConfigurationManager.AppSettings["ClientID"]; if (string.IsNullOrEmpty(clientID)) { throw new ArgumentException("ClientID value isn't set in application configuration"); } this.client = await MixerClient.ConnectViaShortCode(clientID, new List <ClientScopeEnum>() { ClientScopeEnum.chat__chat, ClientScopeEnum.chat__connect, ClientScopeEnum.channel__details__self, ClientScopeEnum.channel__update__self, ClientScopeEnum.user__details__self, ClientScopeEnum.user__log__self, ClientScopeEnum.user__notification__self, ClientScopeEnum.user__update__self, }, (string code) => { this.ShortCodeTextBox.Text = code; Process.Start("https://mixer.com/oauth/shortcode"); }); if (this.client != null) { this.user = await this.client.Users.GetCurrentUser(); this.channel = await this.client.Channels.GetChannel(this.user.username); this.chatClient = await ChatClient.CreateFromChannel(this.client, this.user.channel); this.chatClient.MessageOccurred += ChatClient_MessageOccurred; this.chatClient.UserJoinOccurred += ChatClient_UserJoinOccurred; this.chatClient.UserLeaveOccurred += ChatClient_UserLeaveOccurred; this.chatClient.UserTimeoutOccurred += ChatClient_UserTimeoutOccurred; this.chatClient.UserUpdateOccurred += ChatClient_UserUpdateOccurred; this.chatClient.PollStartOccurred += ChatClient_PollStartOccurred; this.chatClient.PollEndOccurred += ChatClient_PollEndOccurred; this.chatClient.PurgeMessageOccurred += ChatClient_PurgeMessageOccurred; this.chatClient.DeleteMessageOccurred += ChatClient_DeleteMessageOccurred; this.chatClient.ClearMessagesOccurred += ChatClient_ClearMessagesOccurred; if (await this.chatClient.Connect() && await this.chatClient.Authenticate()) { this.ChannelUserTextBlock.Text = this.user.username; this.StreamTitleTextBox.Text = this.channel.name; this.GameTitleTextBlock.Text = this.channel.type.name; foreach (ChatUserModel user in await this.client.Chats.GetUsers(this.chatClient.Channel)) { this.chatUsers.Add(new ChatUser(user)); } this.LoginGrid.Visibility = Visibility.Collapsed; this.MainGrid.Visibility = Visibility.Visible; } } this.LoginButton.IsEnabled = true; }
private async void LoginButton_Click(object sender, RoutedEventArgs e) { this.LoginGrid.Visibility = Visibility.Visible; this.MainGrid.Visibility = Visibility.Collapsed; List <OAuthClientScopeEnum> scopes = new List <OAuthClientScopeEnum>() { OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.chat__bypass_links, OAuthClientScopeEnum.chat__bypass_slowchat, OAuthClientScopeEnum.chat__change_ban, OAuthClientScopeEnum.chat__change_role, OAuthClientScopeEnum.chat__chat, OAuthClientScopeEnum.chat__connect, OAuthClientScopeEnum.chat__clear_messages, OAuthClientScopeEnum.chat__edit_options, OAuthClientScopeEnum.chat__giveaway_start, OAuthClientScopeEnum.chat__poll_start, OAuthClientScopeEnum.chat__poll_vote, OAuthClientScopeEnum.chat__purge, OAuthClientScopeEnum.chat__remove_message, OAuthClientScopeEnum.chat__timeout, OAuthClientScopeEnum.chat__view_deleted, OAuthClientScopeEnum.chat__whisper, OAuthClientScopeEnum.channel__details__self, OAuthClientScopeEnum.channel__update__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, OAuthClientScopeEnum.interactive__manage__self, OAuthClientScopeEnum.interactive__robot__self, OAuthClientScopeEnum.user__details__self, OAuthClientScopeEnum.user__log__self, OAuthClientScopeEnum.user__notification__self, OAuthClientScopeEnum.user__update__self, }; this.connection = await MixerConnection.ConnectViaLocalhostOAuthBrowser(ConfigurationManager.AppSettings["ClientID"], scopes); if (this.connection != null) { this.user = await this.connection.Users.GetCurrentUser(); this.channel = await this.connection.Channels.GetChannel(this.user.username); this.games = new List <InteractiveGameListingModel>(await this.connection.Interactive.GetOwnedInteractiveGames(this.channel)); this.GameSelectComboBox.ItemsSource = this.games.Select(g => g.name); this.LoginGrid.Visibility = Visibility.Collapsed; this.GameSelectGrid.Visibility = Visibility.Visible; this.chatClient = await ChatClient.CreateFromChannel(this.connection, this.channel); if (await this.chatClient.Connect() && await this.chatClient.Authenticate()) { this.InteractiveDataTextBlock.Text += "Connected to the chat." + Environment.NewLine; } } }
private static async Task <bool> InitializeInternal(bool isStreamer, string channelName = null) { await ChannelSession.Services.InitializeTelemetryService(); PrivatePopulatedUserModel user = await ChannelSession.Connection.GetCurrentUser(); if (user != null) { ExpandedChannelModel channel = await ChannelSession.Connection.GetChannel((channelName == null)?user.username : channelName); if (channel != null) { ChannelSession.User = user; ChannelSession.Channel = channel; if (ChannelSession.Settings == null) { ChannelSession.Settings = await ChannelSession.Services.Settings.Create(channel, isStreamer); } await ChannelSession.Services.Settings.Initialize(ChannelSession.Settings); if (isStreamer && ChannelSession.Settings.Channel != null && ChannelSession.User.id != ChannelSession.Settings.Channel.userId) { GlobalEvents.ShowMessageBox("The account you are logged in as on Mixer does not match the account for this settings. Please log in as the correct account on Mixer."); ChannelSession.Settings.OAuthToken.accessToken = string.Empty; ChannelSession.Settings.OAuthToken.refreshToken = string.Empty; ChannelSession.Settings.OAuthToken.expiresIn = 0; return(false); } ChannelSession.Settings.Channel = channel; ChannelSession.Services.Telemetry.SetUserId(ChannelSession.Settings.TelemetryUserId); ChannelSession.Connection.Initialize(); if (!await ChannelSession.Chat.Connect() || !await ChannelSession.Constellation.Connect()) { return(false); } if (!string.IsNullOrEmpty(ChannelSession.Settings.OBSStudioServerIP)) { await ChannelSession.Services.InitializeOBSWebsocket(); } if (ChannelSession.Settings.EnableStreamlabsOBSConnection) { await ChannelSession.Services.InitializeStreamlabsOBSService(); } if (ChannelSession.Settings.EnableXSplitConnection) { await ChannelSession.Services.InitializeXSplitServer(); } if (ChannelSession.Settings.EnableOverlay) { await ChannelSession.Services.InitializeOverlayServer(); } if (ChannelSession.Settings.EnableDeveloperAPI) { await ChannelSession.Services.InitializeDeveloperAPI(); } if (ChannelSession.Settings.StreamlabsOAuthToken != null) { await ChannelSession.Services.InitializeStreamlabs(); } if (ChannelSession.Settings.GameWispOAuthToken != null) { await ChannelSession.Services.InitializeGameWisp(); } if (ChannelSession.Settings.GawkBoxOAuthToken != null) { await ChannelSession.Services.InitializeGawkBox(); } if (ChannelSession.Settings.TwitterOAuthToken != null) { await ChannelSession.Services.InitializeTwitter(); } if (ChannelSession.Settings.SpotifyOAuthToken != null) { await ChannelSession.Services.InitializeSpotify(); } if (ChannelSession.Settings.DiscordOAuthToken != null) { await ChannelSession.Services.InitializeDiscord(); } if (ChannelSession.Settings.TiltifyOAuthToken != null) { await ChannelSession.Services.InitializeTiltify(); } if (ChannelSession.Settings.TipeeeStreamOAuthToken != null) { await ChannelSession.Services.InitializeTipeeeStream(); } if (ChannelSession.Settings.TreatStreamOAuthToken != null) { await ChannelSession.Services.InitializeTreatStream(); } if (ChannelSession.Settings.StreamJarOAuthToken != null) { await ChannelSession.Services.InitializeStreamJar(); } if (ChannelSession.Settings.PatreonOAuthToken != null) { await ChannelSession.Services.InitializePatreon(); } foreach (CommandBase command in ChannelSession.AllEnabledCommands) { foreach (ActionBase action in command.Actions) { if (action is CounterAction) { await((CounterAction)action).SetCounterValue(); } } } if (ChannelSession.Settings.DefaultInteractiveGame > 0) { IEnumerable <InteractiveGameListingModel> games = await ChannelSession.Connection.GetOwnedInteractiveGames(ChannelSession.Channel); InteractiveGameListingModel game = games.FirstOrDefault(g => g.id.Equals(ChannelSession.Settings.DefaultInteractiveGame)); if (game != null) { if (!await ChannelSession.Interactive.Connect(game)) { await ChannelSession.Interactive.Disconnect(); } } else { ChannelSession.Settings.DefaultInteractiveGame = 0; } } foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values) { if (currency.ShouldBeReset()) { await currency.Reset(); } } if (ChannelSession.Settings.ModerationResetStrikesOnLaunch) { foreach (UserDataViewModel userData in ChannelSession.Settings.UserData.Values) { userData.ModerationStrikes = 0; ChannelSession.Settings.UserData.ManualValueChanged(userData.ID); } } await ChannelSession.LoadUserEmoticons(); await ChannelSession.SaveSettings(); await ChannelSession.Services.Settings.SaveBackup(ChannelSession.Settings); await ChannelSession.Services.Settings.PerformBackupIfApplicable(ChannelSession.Settings); ChannelSession.Services.Telemetry.TrackLogin(); if (ChannelSession.Settings.IsStreamer) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { await ChannelSession.Services.MixItUpService.SendUserFeatureEvent(new UserFeatureEvent(ChannelSession.User.id)); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } GlobalEvents.OnRankChanged += GlobalEvents_OnRankChanged; return(true); } } return(false); }
private static async Task <bool> InitializeInternal(string channelName = null) { PrivatePopulatedUserModel user = await ChannelSession.Connection.GetCurrentUser(); if (user != null) { ExpandedChannelModel channel = await ChannelSession.Connection.GetChannel((channelName == null)?user.username : channelName); if (channel != null) { ChannelSession.User = user; ChannelSession.Channel = channel; ChannelSession.PreMadeChatCommands = new List <PreMadeChatCommand>(); ChannelSession.GameQueue = new LockedList <UserViewModel>(); ChannelSession.Counters = new LockedDictionary <string, int>(); if (ChannelSession.Settings == null) { ChannelSession.Settings = ChannelSession.Services.Settings.Create(channel, (channelName == null)); } await ChannelSession.Services.Settings.Initialize(ChannelSession.Settings); ChannelSession.Connection.Initialize(); if (!await ChannelSession.Chat.Connect(connectionAttempts: 5) || !await ChannelSession.Constellation.Connect()) { return(false); } if (!string.IsNullOrEmpty(ChannelSession.Settings.OBSStudioServerIP)) { await ChannelSession.Services.InitializeOBSWebsocket(); } if (ChannelSession.Settings.EnableXSplitConnection) { await ChannelSession.Services.InitializeXSplitServer(); } if (ChannelSession.Settings.EnableOverlay) { await ChannelSession.Services.InitializeOverlayServer(); } if (ChannelSession.Settings.EnableDeveloperAPI) { await ChannelSession.Services.InitializeDeveloperAPI(); } GlobalEvents.OnRankChanged += GlobalEvents_OnRankChanged; await ChannelSession.SaveSettings(); await ChannelSession.Services.Settings.SaveBackup(ChannelSession.Settings); await Logger.LogAnalyticsUsage("LogIn", "Desktop"); return(true); } } return(false); }