-
Notifications
You must be signed in to change notification settings - Fork 1
/
TwitchOldConfig.cs
260 lines (232 loc) · 8.41 KB
/
TwitchOldConfig.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
using System.Collections.Generic;
using System.ComponentModel;
using Razorwing.Framework;
using Razorwing.Framework.Configuration;
using Razorwing.Framework.Platform;
using Razorwing.Framework.Platform.Linux;
using Razorwing.Framework.Platform.Windows;
using Terraria.ModLoader.Config;
namespace TwitchChat
{
public class TwitchConfig : ModConfig
{
private bool autoReconnect = true;
private string channel = "";
private string commandPrefix = "!";
private bool funMode;
private bool ignoreCommands;
private bool showIRC;
private string username = "";
public override ConfigScope Mode => ConfigScope.ClientSide;
private bool available => mod != null && ((TwitchChat) mod).OldConfig != null;
private TwitchOldConfig cfg => ((TwitchChat) mod)?.OldConfig;
[Label("Twitch Username")]
[Tooltip("Username used to authorize you in twitch IRC server. Lowercase will be forced automatically")]
[DefaultValue("missingno")]
public string Username
{
get => !available
? username
: cfg?.Get<string>(TwitchCfg.Username);
set
{
username = value;
if (!available)
return;
cfg?.Set(TwitchCfg.Username, value.ToLower());
}
}
[Label("Target channel")]
[Tooltip("IRC name of channel where to listen messages. In nearly any cases equal streamer username. Require mod reloading to confirm channel rejoining. Lowercase will be forced automatically")]
[DefaultValue("#kindredthefox")]
public string Channel
{
get => !available
? channel
: cfg?.Get<string>(TwitchCfg.Channel);
set
{
channel = value;
if (!available)
return;
cfg?.Set(TwitchCfg.Channel,
value.StartsWith("#") ? value.ToLower() : ("#" + value).ToLower());
}
}
/// <summary>
/// Duplicate it to old config to prevent a token
/// </summary>
private string token
{
get => !available
? string.Empty
: (cfg?.Get<string>(TwitchCfg.OAToken) ?? string.Empty).StartsWith("oauth:")
? "oauth:"
: string.Empty;
set => cfg?.Set(TwitchCfg.OAToken, value);
}
[Label("Copy OAToken from clipboard")]
[Tooltip("Copy token directly from your OS clipboard. Works only for Windows and Linux. Not implemented for OSX, so use backup field")]
public bool ButtonToken
{
get => token != string.Empty;
set
{
switch (RuntimeInfo.OS)
{
case RuntimeInfo.Platform.Windows:
WindowsClipboard cw = new WindowsClipboard();
var sw = cw.GetText();
if (sw != null && sw.StartsWith("oauth:") && sw != token)
token = sw;
break;
case RuntimeInfo.Platform.Linux:
LinuxClipboard cl = new LinuxClipboard();
var sl = cl.GetText();
if (sl != null && sl.StartsWith("oauth:") && sl != token)
token = sl;
break;
case RuntimeInfo.Platform.MacOsx:
default:
//RIP since i don't have any device with MacOS so idk how it works
//And i don't want to carry even more dependency to support apple things since it can be broken trought tML sandboxing
//And yeah, i hate apple devices
break;
}
}
}
[Label("Backup: manual token entry")]
[Tooltip("Used if copy from clipboard won't work. Important note: mod use this config field only to reroute data to own config file. Changing fields here won't all ways mean changing actual settings!")]
public string TokenEntry
{
get => "";
set
{
if (value?.StartsWith("oauth:") ?? false)
token = value;
}
}
[Label("Auto reconnect")]
[Tooltip("Force client to automatically reconnect to IRC when connection get losted")]
[DefaultValue(true)]
public bool AutoReconnect
{
get => cfg?.Get<bool>(TwitchCfg.AutoConnect) ?? autoReconnect;
set
{
autoReconnect = value;
if (!available)
return;
cfg?.Set(TwitchCfg.AutoConnect, value);
}
}
[Label("Ignore Commands")]
[Tooltip("Force client to ignore commands messages and messages from known bots including your own in case self botting")]
[DefaultValue(false)]
public bool IgnoreCommands
{
get => cfg?.Get<bool>(TwitchCfg.IgnoreCommands) ?? ignoreCommands;
set
{
ignoreCommands = false;
if (!available)
return;
cfg?.Set(TwitchCfg.IgnoreCommands, value);
}
}
[Label("Command prefix")]
[DefaultValue("!")]
public string CommandPrefix
{
get => !available
? commandPrefix
: cfg?.Get<string>(TwitchCfg.IgnoreCommandPrefix);
set
{
commandPrefix = value;
if (!available)
return;
cfg?.Set(TwitchCfg.IgnoreCommandPrefix, value);
}
}
[Label("Known bots")]
[Tooltip("List of bots usernames to ignore")]
public List<string> UsersToIgnore { get; set; } = new List<string>
{
"nightbot",
"moobot",
"starbotttv",
"stay_hydrated_bot"
};
[Label("Show Debug")]
[Tooltip("Show all IRC data in chat and also enables internal mod logging.")]
[DefaultValue(false)]
public bool ShowIRC
{
get => cfg?.Get<bool>(TwitchCfg.ShowAllIrc) ?? showIRC;
set
{
showIRC = value;
if (!available)
return;
cfg?.Set(TwitchCfg.ShowAllIrc, value);
}
}
[Label("NPC's renaming to twitch chatters")]
[Tooltip("Renames NPC's to a random nick from chat.")]
[DefaultValue(true)]
public bool RenameNPC { get; set; }
[Label("Enable Fun (Twitch Plays Terraria)")]
[Tooltip("Enables experimental features.")]
[DefaultValue(false)]
public bool FunMode
{
get => cfg?.Get<bool>(TwitchCfg.EnableFun) ?? funMode;
set
{
funMode = value;
if (!available)
return;
cfg?.Set(TwitchCfg.EnableFun, value);
}
}
[Label("Don't forget to reload mod by /t r command!")]
[Tooltip("Required in order to apply changes.")]
[DefaultValue(false)]
public bool ReloadBtn { get; set; }
}
/// <summary>
/// No more needed since ModLoader now has own config manager, but remain this for legacy loading
/// for update
/// </summary>
public class TwitchOldConfig : IniConfigManager<TwitchCfg>
{
public TwitchOldConfig(Storage storage)
: base(storage)
{
}
protected override string Filename => @"Twitch.ini";
protected override void InitialiseDefaults()
{
Set(TwitchCfg.AutoConnect, true);
Set(TwitchCfg.Channel, "#kindredthefox");
Set(TwitchCfg.Username, "missingno");
Set(TwitchCfg.OAToken, "https://twitchapps.com/tmi/");
Set(TwitchCfg.ShowAllIrc, false);
Set(TwitchCfg.IgnoreCommands, false);
Set(TwitchCfg.IgnoreCommandPrefix, "!");
Set(TwitchCfg.EnableFun, false);
}
}
public enum TwitchCfg
{
Channel,
OAToken,
Username,
AutoConnect,
ShowAllIrc,
IgnoreCommands,
IgnoreCommandPrefix,
EnableFun
}
}