-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedSettings.cs
366 lines (323 loc) · 11.2 KB
/
SharedSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using BasicTwitchSoundPlayer.Extensions;
using BasicTwitchSoundPlayer.Interfaces;
using BasicTwitchSoundPlayer.Structs;
using BasicTwitchSoundPlayer.Structs.Gemini;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace BasicTwitchSoundPlayer
{
[Serializable]
public class ColorStruct
{
//Form background
[XmlElement]
public ColorWrapper FormBackground { get; set; }
[XmlElement]
public ColorWrapper FormTextColor { get; set; }
//MenuStripBar
[XmlElement]
public ColorWrapper MenuStripBarBackground { get; set; }
[XmlElement]
public ColorWrapper MenuStripBarText { get; set; }
//MenuStripColors
[XmlElement]
public ColorWrapper MenuStripBackground { get; set; }
[XmlElement]
public ColorWrapper MenuStripText { get; set; }
[XmlElement]
public ColorWrapper MenuStripBackgroundSelected { get; set; }
//LineColors
[XmlElement]
public ColorWrapper LineColorBackground { get; set; }
[XmlElement]
public ColorWrapper LineColorGeneric { get; set; }
[XmlElement]
public ColorWrapper LineColorIrcCommand { get; set; }
[XmlElement]
public ColorWrapper LineColorModeration { get; set; }
[XmlElement]
public ColorWrapper LineColorSoundPlayback { get; set; }
[XmlElement]
public ColorWrapper LineColorWebSocket { get; set; }
public ColorStruct()
{
FormBackground = Color.WhiteSmoke;
FormTextColor = Color.Black;
MenuStripBarBackground = Color.WhiteSmoke;
MenuStripBarText = Color.Black;
MenuStripBackground = Color.WhiteSmoke;
MenuStripText = Color.Black;
MenuStripBackgroundSelected = Color.SkyBlue;
LineColorBackground = Color.GhostWhite;
LineColorGeneric = Color.Black;
LineColorIrcCommand = Color.DarkGreen;
LineColorModeration = Color.DarkBlue;
LineColorSoundPlayback = Color.DarkOrange;
LineColorWebSocket = Color.DarkMagenta;
}
}
[Serializable]
public class PrivateSettings
{
private static string GetConfigPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BasicTwitchSoundPlayer", "Config.xml");
private static PrivateSettings m_Instance;
public static PrivateSettings GetInstance()
{
if (m_Instance == null)
m_Instance = LoadSettings();
return m_Instance;
}
#region Properties
[XmlElement] public ColorStruct Colors { get; set; }
[XmlElement] public bool Debug_mode { get; set; }
[XmlElement] public bool Autostart { get; set; }
[XmlElement] public float Volume { get; set; }
[XmlElement] public int Delay { get; set; }
[XmlElement] public Guid OutputDevice { get; set; }
[XmlElement] public string TwitchServer { get; set; }
[XmlElement] public string UserName { get; set; }
[XmlElement] public EncryptedString UserAuth { get; set; }
[XmlElement] public string BotUsername { get; set; }
[XmlElement] public EncryptedString BotAuth { get; set; }
[XmlElement] public bool RunWebSocketsServer { get; set; }
[XmlElement] public int WebSocketsServerPort { get; set; }
[XmlElement] public string UniversalRewardID { get; set; }
#endregion
public PrivateSettings()
{
//NOTE: Make sure everything is initialized first!
Debug_mode = false;
Autostart = false;
Volume = 0.5f;
Delay = 15;
this.Colors = new ColorStruct();
TwitchServer = "irc.twitch.tv";
UserName = "";
UserAuth = "";
BotUsername = "";
BotAuth = "";
RunWebSocketsServer = false;
WebSocketsServerPort = 8005;
UniversalRewardID = "";
}
#region Load/Save
private static PrivateSettings LoadSettings()
{
var path = GetConfigPath();
if (File.Exists(path))
{
PrivateSettings obj;
XmlSerializer serializer = new XmlSerializer(typeof(PrivateSettings));
FileStream fs = new FileStream(path, FileMode.Open);
obj = (PrivateSettings)serializer.Deserialize(fs);
fs.Close();
return obj;
}
else
return new PrivateSettings();
}
public void SaveSettings() => XML_Utils.Save(GetConfigPath(), this);
#endregion
}
[Serializable]
public class VoiceModConfig
{
private static string GetConfigPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BasicTwitchSoundPlayer", "VoiceModConfig.xml");
private static VoiceModConfig m_Instance;
public static VoiceModConfig GetInstance()
{
if (m_Instance == null)
m_Instance = LoadSettings();
return m_Instance;
}
private static VoiceModConfig LoadSettings()
{
if (File.Exists(GetConfigPath()))
{
VoiceModConfig obj;
XmlSerializer serializer = new XmlSerializer(typeof(VoiceModConfig));
FileStream fs = new FileStream(GetConfigPath(), FileMode.Open);
obj = (VoiceModConfig)serializer.Deserialize(fs);
fs.Close();
return obj;
}
else
return new VoiceModConfig();
}
public void Save()
{
XmlSerializer serializer = new XmlSerializer(typeof(VoiceModConfig));
StreamWriter fw = new StreamWriter(GetConfigPath());
serializer.Serialize(fw, this);
fw.Close();
}
public string APIKey { get; set; }
public string AdressPort { get; set; }
public List<VoiceModReward> Rewards { get; set; } = new List<VoiceModReward>();
private Dictionary<string, VoiceModReward> IDToReward;
public VoiceModReward GetReward(string rewardID)
{
if (IDToReward == null)
{
IDToReward = new Dictionary<string, VoiceModReward>();
foreach (var reward in Rewards)
{
if (string.IsNullOrEmpty(reward.RewardID))
continue;
if (IDToReward.ContainsKey(reward.RewardID))
continue;
IDToReward.Add(reward.RewardID, reward);
}
}
if (IDToReward.TryGetValue(rewardID, out var foundReward))
return foundReward;
else
return null;
}
public VoiceModConfig()
{
APIKey = "";
AdressPort = "ws://localhost:59129/v1";
}
[Serializable]
public class VoiceModReward : IVoiceModeRewardBindingInterface
{
[XmlAttribute]
public string VoiceModFriendlyName { get; set; }
[XmlAttribute]
public string RewardTitle { get; set; }
[XmlAttribute]
public string RewardID { get; set; }
[XmlAttribute]
public int RewardCost { get; set; }
[XmlAttribute]
public int RewardCooldown { get; set; }
[XmlAttribute]
public int RewardDuration { get; set; }
[XmlAttribute]
public bool Enabled { get; set; }
[XmlText]
public string RewardDescription { get; set; }
[XmlIgnore]
public bool IsSetup = false;
public VoiceModReward()
{
VoiceModFriendlyName = "";
RewardTitle = "";
RewardID = "";
RewardCost = 240;
RewardDuration = 30;
RewardCooldown = 1;
Enabled = true;
RewardDescription = "";
}
public object Clone()
{
return new VoiceModReward()
{
VoiceModFriendlyName = this.VoiceModFriendlyName,
RewardTitle = this.RewardTitle,
RewardID = this.RewardID,
RewardCost = this.RewardCost,
RewardCooldown = this.RewardCooldown,
RewardDuration = this.RewardDuration,
Enabled = this.Enabled,
RewardDescription = this.RewardDescription
};
}
}
}
[Serializable]
public class AIConfig
{
[Serializable]
public class FilterSet
{
public AISafetySettingsValues Harassment { get; set; } = AISafetySettingsValues.BLOCK_ONLY_HIGH;
public AISafetySettingsValues Hate { get; set; } = AISafetySettingsValues.BLOCK_ONLY_HIGH;
public AISafetySettingsValues Sexually_Explicit { get; set; } = AISafetySettingsValues.BLOCK_ONLY_HIGH;
public AISafetySettingsValues Dangerous_Content { get; set; } = AISafetySettingsValues.BLOCK_ONLY_HIGH;
public AISafetySettingsValues Civic_Integrity { get; set; } = AISafetySettingsValues.BLOCK_LOW_AND_ABOVE;
}
private static string GetConfigPath() => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BasicTwitchSoundPlayer", "AI_Config.xml");
public static string GetAIHistoryPath(string username) => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BasicTwitchSoundPlayer", "AI_History", username + ".xml");
private static AIConfig m_Instance;
public static AIConfig GetInstance()
{
if (m_Instance == null)
m_Instance = LoadSettings();
return m_Instance;
}
public EncryptedString ApiKey { get; set; } = "";
public string Instruction_Streamer { get; set; } = "The responses are always 200-550 characters long.";
public int TokenLimit_Streamer { get; set; } = 1_048_576 - 8096 - 512;
public FilterSet FilterSet_Streamer = new FilterSet()
{
Harassment = AISafetySettingsValues.BLOCK_NONE,
Hate = AISafetySettingsValues.BLOCK_NONE,
Sexually_Explicit = AISafetySettingsValues.BLOCK_NONE,
Dangerous_Content = AISafetySettingsValues.BLOCK_NONE,
Civic_Integrity = AISafetySettingsValues.BLOCK_LOW_AND_ABOVE,
};
public string Instruction_User { get; set; } = "The user is {0}\nThe responses are always 200-450 characters long.";
public int TokenLimit_User { get; set; } = 8096;
public FilterSet FilterSet_User = new FilterSet()
{
Harassment = AISafetySettingsValues.BLOCK_MEDIUM_AND_ABOVE,
Hate = AISafetySettingsValues.BLOCK_MEDIUM_AND_ABOVE,
Sexually_Explicit = AISafetySettingsValues.BLOCK_MEDIUM_AND_ABOVE,
Dangerous_Content = AISafetySettingsValues.BLOCK_MEDIUM_AND_ABOVE,
Civic_Integrity = AISafetySettingsValues.BLOCK_LOW_AND_ABOVE,
};
public string Model { get; set; } = "models/gemini-2.0-flash-exp";
public string TwitchAwardID { get; set; } = "";
private static AIConfig LoadSettings() => XML_Utils.Load(GetConfigPath(), new AIConfig());
public void SaveSettings() => XML_Utils.Save(GetConfigPath(), this);
public SafetySettingsCategory[] GetSafetySettingsStreamer()
{
return new SafetySettingsCategory[]
{
new SafetySettingsCategory("HARM_CATEGORY_HARASSMENT", FilterSet_Streamer.Harassment),
new SafetySettingsCategory("HARM_CATEGORY_HATE_SPEECH", FilterSet_Streamer.Hate),
new SafetySettingsCategory("HARM_CATEGORY_SEXUALLY_EXPLICIT", FilterSet_Streamer.Sexually_Explicit),
new SafetySettingsCategory("HARM_CATEGORY_DANGEROUS_CONTENT", FilterSet_Streamer.Dangerous_Content),
new SafetySettingsCategory("HARM_CATEGORY_CIVIC_INTEGRITY", FilterSet_Streamer.Civic_Integrity),
};
}
public SafetySettingsCategory[] GetSafetySettingsGeneral()
{
return new SafetySettingsCategory[]
{
new SafetySettingsCategory("HARM_CATEGORY_HARASSMENT", FilterSet_User.Harassment),
new SafetySettingsCategory("HARM_CATEGORY_HATE_SPEECH", FilterSet_User.Hate),
new SafetySettingsCategory("HARM_CATEGORY_SEXUALLY_EXPLICIT", FilterSet_User.Sexually_Explicit),
new SafetySettingsCategory("HARM_CATEGORY_DANGEROUS_CONTENT", FilterSet_User.Dangerous_Content),
new SafetySettingsCategory("HARM_CATEGORY_CIVIC_INTEGRITY", FilterSet_User.Civic_Integrity),
};
}
public GeminiMessage GetInstruction(string username, bool isStreamer, bool attachIsLive, bool attachTimeDate = true)
{
var sb = new StringBuilder();
sb.AppendLine(isStreamer ? Instruction_Streamer : Instruction_User);
if (!isStreamer)
sb.AppendLine("The user is " + username + ".");
sb.AppendStreamInstructionPostfix(attachTimeDate, attachIsLive);
return new GeminiMessage()
{
role = Role.user,
parts = new GeminiMessagePart[]
{
new GeminiMessagePart()
{
text = sb.ToString()
}
}
};
}
}
}