Skip to content

Commit eba66c2

Browse files
[Keystrokes] Adding the ability to specify more bot commands
1 parent 813cc1b commit eba66c2

14 files changed

+444
-72
lines changed
4.89 KB
Loading
5.54 KB
Loading
5.16 KB
Loading

streaming-tools/streaming-tools/Configuration.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Configuration : INotifyPropertyChanged {
2626
/// <summary>
2727
/// The command to execute on keystroke.
2828
/// </summary>
29-
private KeystokeCommand? keystokeCommand;
29+
private ObservableCollection<KeystokeCommand>? keystrokeCommand;
3030

3131
/// <summary>
3232
/// The monitor selected in the layout view.
@@ -80,10 +80,10 @@ public static Configuration Instance {
8080
/// <summary>
8181
/// Gets or sets the command to execute on keystroke.
8282
/// </summary>
83-
public KeystokeCommand? KeystokeCommand {
84-
get => this.keystokeCommand;
83+
public ObservableCollection<KeystokeCommand>? KeystrokeCommand {
84+
get => this.keystrokeCommand;
8585
set {
86-
this.keystokeCommand = value;
86+
this.keystrokeCommand = value;
8787
this.OnPropertyChanged();
8888
}
8989
}
@@ -191,8 +191,8 @@ public static Configuration ReadConfiguration() {
191191
config.TtsPhoneticUsernames = new ObservableCollection<KeyValuePair<string, string>>();
192192
}
193193

194-
if (null == config.KeystokeCommand) {
195-
config.KeystokeCommand = new KeystokeCommand();
194+
if (null == config.KeystrokeCommand) {
195+
config.KeystrokeCommand = new ObservableCollection<KeystokeCommand>();
196196
}
197197

198198
if (null == config.ChannelPointSoundRedemptions) {
@@ -345,6 +345,26 @@ public class KeystokeCommand {
345345
/// Gets or sets the twitch chat to type in.
346346
/// </summary>
347347
public string? TwitchChat { get; set; }
348+
349+
/// <summary>
350+
/// Gets or sets a value indicating whether this is a keystroke to skip all current messages.
351+
/// </summary>
352+
public bool ClearMessageQueue { get; set; }
353+
354+
/// <summary>
355+
/// Gets or sets a value indicating whether the user that typed the current message should be timed out.
356+
/// </summary>
357+
public bool TimeoutUserCurrentMessage { get; set; }
358+
359+
/// <summary>
360+
/// Gets or sets a value indicating whether the user that typed the current message should be banned.
361+
/// </summary>
362+
public bool BanUserCurrentMessage { get; set; }
363+
364+
/// <summary>
365+
/// Gets or sets a value indicating whether this is a keystroke to send a message in chat.
366+
/// </summary>
367+
public bool SendChatMessage { get; set; }
348368
}
349369

350370
/// <summary>

streaming-tools/streaming-tools/Twitch/Tts/TwitchChatTts.cs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TwitchChatTts : IDisposable {
1717
/// <summary>
1818
/// The configuration for the twitch chat.
1919
/// </summary>
20-
private readonly TwitchChatConfiguration? chatConfig;
20+
public TwitchChatConfiguration? ChatConfig { get; }
2121

2222
/// <summary>
2323
/// The collection of sounds to play.
@@ -59,6 +59,8 @@ public class TwitchChatTts : IDisposable {
5959
/// </summary>
6060
private ManualResetEvent? ttsSoundOutputSignal;
6161

62+
private int messageToSkip;
63+
6264
/// <summary>
6365
/// Initializes a new instance of the <see cref="TwitchChatTts" /> class.
6466
/// </summary>
@@ -69,8 +71,7 @@ public TwitchChatTts(TwitchChatConfiguration? config) {
6971
this.soundThread.Name = "TwitchChatTts Thread";
7072
this.soundThread.IsBackground = true;
7173
this.soundThread.Start();
72-
this.chatConfig = config;
73-
GlobalKeyboardListener.Instance.Callback += this.KeyboardPressCallback;
74+
this.ChatConfig = config;
7475
}
7576

7677
/// <summary>
@@ -92,21 +93,23 @@ public void Dispose() {
9293
this.ttsSoundOutput = null;
9394
}
9495

95-
if (null == this.chatConfig) {
96+
if (null == this.ChatConfig) {
9697
return;
9798
}
9899

99-
var user = Configuration.Instance.GetTwitchAccount(this.chatConfig.AccountUsername);
100+
var user = Configuration.Instance.GetTwitchAccount(this.ChatConfig.AccountUsername);
100101
if (null == user) {
101102
return;
102103
}
103104

104105
var twitchManager = TwitchChatManager.Instance;
105-
twitchManager.RemoveTwitchChannel(user, this.chatConfig.TwitchChannel, this.Client_OnMessageReceived);
106+
twitchManager.RemoveTwitchChannel(user, this.ChatConfig.TwitchChannel, this.Client_OnMessageReceived);
106107
if (this.soundThread.Join(5000)) {
107108
this.soundThread.Interrupt();
108109
}
109110
}
111+
112+
public string? CurrentUsername { get; set; }
110113

111114
/// <summary>
112115
/// The main thread used to play sound asynchronously.
@@ -119,8 +122,14 @@ private void PlaySoundsThread() {
119122
return;
120123
}
121124

125+
if (messageToSkip > 0) {
126+
--messageToSkip;
127+
Console.WriteLine($"Skipping: {e.ChatMessage.Username} says {e.ChatMessage.Message}");
128+
continue;
129+
}
130+
122131
Console.WriteLine($"Running: {e.ChatMessage.Username} says {e.ChatMessage.Message}");
123-
if (null == this.chatConfig) {
132+
if (null == this.ChatConfig) {
124133
continue;
125134
}
126135

@@ -154,8 +163,8 @@ private void PlaySoundsThread() {
154163
using (var stream = new MemoryStream()) {
155164
// Setup the microsoft TTS object according to the settings.
156165
synth.SetOutputToWaveStream(stream);
157-
synth.SelectVoice(this.chatConfig.TtsVoice);
158-
synth.Volume = (int)this.chatConfig.TtsVolume;
166+
synth.SelectVoice(this.ChatConfig.TtsVoice);
167+
synth.Volume = (int)this.ChatConfig.TtsVolume;
159168
synth.Speak(chatMessage);
160169

161170
// Now that we filled the stream, seek to the beginning so we can play it.
@@ -173,8 +182,8 @@ private void PlaySoundsThread() {
173182
this.ttsSoundOutput = new WaveOutEvent();
174183
this.ttsSoundOutputSignal = new ManualResetEvent(false);
175184

176-
this.ttsSoundOutput.DeviceNumber = NAudioUtilities.GetOutputDeviceIndex(this.chatConfig.OutputDevice);
177-
this.ttsSoundOutput.Volume = this.chatConfig.TtsVolume / 100.0f;
185+
this.ttsSoundOutput.DeviceNumber = NAudioUtilities.GetOutputDeviceIndex(this.ChatConfig.OutputDevice);
186+
this.ttsSoundOutput.Volume = this.ChatConfig.TtsVolume / 100.0f;
178187

179188
this.ttsSoundOutput.Init(reader);
180189

@@ -191,8 +200,10 @@ private void PlaySoundsThread() {
191200
}
192201

193202
// Wait for the play to finish, we will get signaled.
203+
CurrentUsername = e.ChatMessage.Username;
194204
var signal = this.ttsSoundOutputSignal;
195205
signal?.WaitOne();
206+
CurrentUsername = null;
196207
} finally {
197208
// Finally dispose of everything safely in the lock.
198209
lock (this.ttsSoundOutputLock)
@@ -215,18 +226,18 @@ private void PlaySoundsThread() {
215226
/// Connects to the chat to listen for messages to read in text to speech.
216227
/// </summary>
217228
public void Connect() {
218-
if (null == this.chatConfig) {
229+
if (null == this.ChatConfig) {
219230
return;
220231
}
221232

222233
var config = Configuration.Instance;
223-
var user = config.GetTwitchAccount(this.chatConfig.AccountUsername);
234+
var user = config.GetTwitchAccount(this.ChatConfig.AccountUsername);
224235
if (null == user) {
225236
return;
226237
}
227238

228239
var twitchManager = TwitchChatManager.Instance;
229-
twitchManager.AddTwitchChannel(user, this.chatConfig.TwitchChannel, this.Client_OnMessageReceived);
240+
twitchManager.AddTwitchChannel(user, this.ChatConfig.TwitchChannel, this.Client_OnMessageReceived);
230241
}
231242

232243
/// <summary>
@@ -261,18 +272,13 @@ private void Client_OnMessageReceived(TwitchClient twitchClient, OnMessageReceiv
261272
}
262273
}
263274

264-
/// <summary>
265-
/// Handles key press anywhere in the OS.
266-
/// </summary>
267-
/// <param name="keyboard">The key that was pressed in string format.</param>
268-
/// <remarks>
269-
/// See:
270-
/// <see href="https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN" />
271-
/// </remarks>
272-
private void KeyboardPressCallback(string keyboard) {
273-
if ("123".Equals(keyboard, StringComparison.InvariantCultureIgnoreCase)) {
274-
this.ttsSoundOutput?.Stop();
275-
}
275+
public void SkipCurrentTts() {
276+
this.ttsSoundOutput?.Stop();
277+
}
278+
279+
public void SkipAllTts() {
280+
messageToSkip = this.soundsToPlay.Count;
281+
this.ttsSoundOutput?.Stop();
276282
}
277283
}
278284
}

streaming-tools/streaming-tools/ViewModels/ChannelPointViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using ReactiveUI;
1111
using Twitch;
1212
using TwitchLib.Api.Core.Enums;
13+
using TwitchLib.Api.Helix.Models.ChannelPoints.CreateCustomReward;
1314
using TwitchLib.Api.Helix.Models.ChannelPoints.UpdateCustomRewardRedemptionStatus;
1415
using TwitchLib.PubSub.Events;
1516
using Utilities;
@@ -111,7 +112,7 @@ public async void RefreshChannelPointRewards() {
111112
var toAdd = actualRewardNames.Except(knownRewardNames);
112113
var toDelete = knownRewardNames.Except(actualRewardNames);
113114

114-
// foreach (var reward in rewards.Data.Where(d => d.Title.StartsWith("Sound:"))) {
115+
// foreach (var reward in rewards.Data.Where(d => d.Title.StartsWith("Sound: Jura"))) {
115116
// await api.Helix.ChannelPoints.CreateCustomRewards(user.Id, new CreateCustomRewardsRequest {
116117
// BackgroundColor = reward.BackgroundColor,
117118
// Cost = reward.Cost,
@@ -124,7 +125,7 @@ public async void RefreshChannelPointRewards() {
124125
// IsUserInputRequired = reward.IsUserInputRequired,
125126
// MaxPerStream = reward.MaxPerStreamSetting.MaxPerStream,
126127
// MaxPerUserPerStream = reward.MaxPerUserPerStreamSetting.MaxPerStream,
127-
// Title = "Sound: Scream",
128+
// Title = reward.Title,
128129
// Prompt = reward.Prompt
129130
// });
130131
// }

0 commit comments

Comments
 (0)