1515 public class KeystrokeCommandViewModel : ViewModelBase {
1616 private bool banUserCurrentMessage ;
1717 private bool clearMessageQueue ;
18-
18+
1919
2020 /// <summary>
2121 /// The command to write in chat.
@@ -59,7 +59,7 @@ public KeystrokeCommandViewModel(KeystokeCommand config, Action<KeystrokeCommand
5959 this . Config = config ;
6060 this . KeyCode = config . KeyCode ;
6161 this . Command = config . Command ;
62- this . SelectedTwitchChat = config . TwitchChat ;
62+ this . SelectedTwitchChat = GetStreamingAccount ( ) ;
6363 this . ClearMessageQueue = config . ClearMessageQueue ;
6464 this . TimeoutUserCurrentMessage = config . TimeoutUserCurrentMessage ;
6565 this . BanUserCurrentMessage = config . BanUserCurrentMessage ;
@@ -162,6 +162,11 @@ public void Delete() {
162162 this . deleteCallback ? . Invoke ( this ) ;
163163 }
164164
165+ private string ? GetStreamingAccount ( ) {
166+ return this . SelectedTwitchChat ??
167+ Configuration . Instance . TwitchAccounts ? . FirstOrDefault ( a => a . IsUsersStreamingAccount ) ? . Username ;
168+ }
169+
165170 /// <summary>
166171 /// Raised when keystrokes are received from the keyboard.
167172 /// </summary>
@@ -178,9 +183,7 @@ private void OnKeystrokeReceived(string keycode) {
178183 }
179184
180185 int receivedKeycode ;
181- if ( string . IsNullOrWhiteSpace ( this . SelectedTwitchChat ) ||
182- null == this . KeyCode ||
183- string . IsNullOrWhiteSpace ( this . Command ) ||
186+ if ( null == this . KeyCode ||
184187 ! int . TryParse ( keycode , out receivedKeycode ) || this . KeyCode != receivedKeycode ) {
185188 return ;
186189 }
@@ -291,11 +294,12 @@ private void HandleBanUserCurrentMessage() {
291294 }
292295
293296 private void HandleSendChatMessage ( ) {
294- if ( null == this . SelectedTwitchChat ) {
297+ string ? account = GetStreamingAccount ( ) ;
298+ if ( null == account ) {
295299 return ;
296300 }
297301
298- var client = TwitchChatManager . Instance . GetTwitchChannelClient ( this . SelectedTwitchChat ) ;
302+ var client = TwitchChatManager . Instance . GetTwitchChannelClient ( account ) ;
299303 if ( null == client ) {
300304 return ;
301305 }
@@ -304,7 +308,7 @@ private void HandleSendChatMessage() {
304308 client . Reconnect ( ) ;
305309 }
306310
307- client . SendMessage ( this . SelectedTwitchChat , this . Command ) ;
311+ client . SendMessage ( account , this . Command ) ;
308312 }
309313
310314 /// <summary>
@@ -316,10 +320,9 @@ private void SaveToConfiguration(object? sender, PropertyChangedEventArgs e) {
316320 if ( null == Configuration . Instance . KeystrokeCommand ) {
317321 return ;
318322 }
319-
323+
320324 config . KeyCode = this . KeyCode ;
321325 config . Command = this . Command ;
322- config . TwitchChat = this . SelectedTwitchChat ;
323326 this . config . SkipMessage = this . SkipMessage ;
324327 config . ClearMessageQueue = this . ClearMessageQueue ;
325328 config . TimeoutUserCurrentMessage = this . TimeoutUserCurrentMessage ;
0 commit comments