15
15
public class KeystrokeCommandViewModel : ViewModelBase {
16
16
private bool banUserCurrentMessage ;
17
17
private bool clearMessageQueue ;
18
-
18
+
19
19
20
20
/// <summary>
21
21
/// The command to write in chat.
@@ -59,7 +59,7 @@ public KeystrokeCommandViewModel(KeystokeCommand config, Action<KeystrokeCommand
59
59
this . Config = config ;
60
60
this . KeyCode = config . KeyCode ;
61
61
this . Command = config . Command ;
62
- this . SelectedTwitchChat = config . TwitchChat ;
62
+ this . SelectedTwitchChat = GetStreamingAccount ( ) ;
63
63
this . ClearMessageQueue = config . ClearMessageQueue ;
64
64
this . TimeoutUserCurrentMessage = config . TimeoutUserCurrentMessage ;
65
65
this . BanUserCurrentMessage = config . BanUserCurrentMessage ;
@@ -162,6 +162,11 @@ public void Delete() {
162
162
this . deleteCallback ? . Invoke ( this ) ;
163
163
}
164
164
165
+ private string ? GetStreamingAccount ( ) {
166
+ return this . SelectedTwitchChat ??
167
+ Configuration . Instance . TwitchAccounts ? . FirstOrDefault ( a => a . IsUsersStreamingAccount ) ? . Username ;
168
+ }
169
+
165
170
/// <summary>
166
171
/// Raised when keystrokes are received from the keyboard.
167
172
/// </summary>
@@ -178,9 +183,7 @@ private void OnKeystrokeReceived(string keycode) {
178
183
}
179
184
180
185
int receivedKeycode ;
181
- if ( string . IsNullOrWhiteSpace ( this . SelectedTwitchChat ) ||
182
- null == this . KeyCode ||
183
- string . IsNullOrWhiteSpace ( this . Command ) ||
186
+ if ( null == this . KeyCode ||
184
187
! int . TryParse ( keycode , out receivedKeycode ) || this . KeyCode != receivedKeycode ) {
185
188
return ;
186
189
}
@@ -291,11 +294,12 @@ private void HandleBanUserCurrentMessage() {
291
294
}
292
295
293
296
private void HandleSendChatMessage ( ) {
294
- if ( null == this . SelectedTwitchChat ) {
297
+ string ? account = GetStreamingAccount ( ) ;
298
+ if ( null == account ) {
295
299
return ;
296
300
}
297
301
298
- var client = TwitchChatManager . Instance . GetTwitchChannelClient ( this . SelectedTwitchChat ) ;
302
+ var client = TwitchChatManager . Instance . GetTwitchChannelClient ( account ) ;
299
303
if ( null == client ) {
300
304
return ;
301
305
}
@@ -304,7 +308,7 @@ private void HandleSendChatMessage() {
304
308
client . Reconnect ( ) ;
305
309
}
306
310
307
- client . SendMessage ( this . SelectedTwitchChat , this . Command ) ;
311
+ client . SendMessage ( account , this . Command ) ;
308
312
}
309
313
310
314
/// <summary>
@@ -316,10 +320,9 @@ private void SaveToConfiguration(object? sender, PropertyChangedEventArgs e) {
316
320
if ( null == Configuration . Instance . KeystrokeCommand ) {
317
321
return ;
318
322
}
319
-
323
+
320
324
config . KeyCode = this . KeyCode ;
321
325
config . Command = this . Command ;
322
- config . TwitchChat = this . SelectedTwitchChat ;
323
326
this . config . SkipMessage = this . SkipMessage ;
324
327
config . ClearMessageQueue = this . ClearMessageQueue ;
325
328
config . TimeoutUserCurrentMessage = this . TimeoutUserCurrentMessage ;
0 commit comments