Skip to content

Commit 4be7c65

Browse files
committed
Fixed settings for simple strings
1 parent 06e4bc4 commit 4be7c65

File tree

8 files changed

+47
-28
lines changed

8 files changed

+47
-28
lines changed

TS3AudioBot/CommandSystem/Ast/AstValue.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ internal class AstValue : AstNode
1616
public override AstType Type => AstType.Value;
1717
public string Value { get; set; }
1818

19+
public void BuildValue()
20+
{
21+
Value = FullRequest.Substring(Position, Length);
22+
}
23+
1924
public override void Write(StringBuilder strb, int depth) => strb.Space(depth).Append(Value);
2025
}
2126
}

TS3AudioBot/CommandSystem/CommandParser.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
5757
strPtr.SkipChar(delimeterChar);
5858

5959
if (strPtr.End)
60+
{
6061
build = BuildStatus.End;
62+
}
6163
else
6264
{
6365
switch (strPtr.Char)
@@ -66,20 +68,28 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
6668
build = BuildStatus.ParseQuotedString;
6769
//goto case BuildStatus.ParseQuotedString;
6870
break;
71+
6972
case '(':
7073
if (!strPtr.HasNext)
74+
{
7175
build = BuildStatus.ParseFreeString;
76+
}
7277
else if (strPtr.IsNext(commandChar))
7378
{
7479
strPtr.Next('(');
7580
build = BuildStatus.ParseCommand;
7681
}
7782
else
83+
{
7884
build = BuildStatus.ParseFreeString;
85+
}
7986
break;
87+
8088
case ')':
8189
if (comAst.Count <= 0)
90+
{
8291
build = BuildStatus.End;
92+
}
8393
else
8494
{
8595
comAst.Pop();
@@ -88,6 +98,7 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
8898
}
8999
strPtr.Next();
90100
break;
101+
91102
default:
92103
build = BuildStatus.ParseFreeString;
93104
break;
@@ -96,8 +107,6 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
96107
break;
97108

98109
case BuildStatus.ParseFreeString:
99-
strb.Clear();
100-
101110
var valFreeAst = new AstValue();
102111
using (strPtr.TrackNode(valFreeAst))
103112
{
@@ -106,11 +115,12 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
106115
if ((strPtr.Char == '(' && strPtr.HasNext && strPtr.IsNext(commandChar))
107116
|| strPtr.Char == ')'
108117
|| strPtr.Char == delimeterChar)
118+
{
109119
break;
110-
strb.Append(strPtr.Char);
120+
}
111121
}
112122
}
113-
valFreeAst.Value = strb.ToString();
123+
valFreeAst.BuildValue();
114124
buildCom = comAst.Peek();
115125
buildCom.Parameter.Add(valFreeAst);
116126
build = BuildStatus.SelectParam;
@@ -127,14 +137,21 @@ public static AstNode ParseCommandRequest(string request, char commandChar = Def
127137
bool escaped = false;
128138
for (; !strPtr.End; strPtr.Next())
129139
{
130-
if (strPtr.Char == '\\') escaped = true;
140+
if (strPtr.Char == '\\')
141+
{
142+
escaped = true;
143+
}
131144
else if (strPtr.Char == '"')
132145
{
133-
if (escaped) strb.Length--;
146+
if (escaped) { strb.Length--; }
134147
else { strPtr.Next(); break; }
135148
escaped = false;
136149
}
137-
else escaped = false;
150+
else
151+
{
152+
escaped = false;
153+
}
154+
138155
strb.Append(strPtr.Char);
139156
}
140157
}
@@ -208,7 +225,7 @@ public NodeTracker TrackNode(AstNode node)
208225
astnode.Position = index;
209226
astnode.Length = 0;
210227
}
211-
return (curTrack = new NodeTracker(this));
228+
return curTrack = new NodeTracker(this);
212229
}
213230

214231
private void UntrackNode()

TS3AudioBot/Config/ConfigEnumerable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public abstract class ConfigEnumerable : ConfigPart
2020

2121
protected virtual TomlTable.TableTypes TableType { get => TomlTable.TableTypes.Default; }
2222
public TomlTable TomlObject { get; set; }
23+
public override bool ExpectsString => false;
2324

2425
public override void FromToml(TomlObject tomlObject)
2526
{

TS3AudioBot/Config/ConfigPart.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected ConfigPart(string key)
3434
Key = key;
3535
}
3636

37+
public abstract bool ExpectsString { get; }
3738
public abstract void FromToml(TomlObject tomlObject);
3839
public abstract void ToToml(bool writeDefaults, bool writeDocumentation);
3940
public abstract void Derive(ConfigPart derived);

TS3AudioBot/Config/ConfigValue.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace TS3AudioBot.Config
1919
[DebuggerDisplay("{Key}:{Value}")]
2020
public class ConfigValue<T> : ConfigPart
2121
{
22+
public override bool ExpectsString => typeof(T) == typeof(string);
2223
private ConfigValue<T> backingValue;
2324
private bool hasValue = false;
2425
public T Default { get; }

TS3AudioBot/Helper/IJsonConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace TS3AudioBot.Helper
1616

1717
public interface IJsonSerializable
1818
{
19+
bool ExpectsString { get; }
1920
void ToJson(JsonWriter writer);
2021
E<string> FromJson(JsonReader reader);
2122
}
@@ -24,6 +25,9 @@ public static class JsonSerializableExtensions
2425
{
2526
public static E<string> FromJson(this IJsonSerializable jsonConfig, string json)
2627
{
28+
if (jsonConfig.ExpectsString)
29+
json = JsonConvert.SerializeObject(json);
30+
2731
var sr = new StringReader(json);
2832
using (var reader = new JsonTextReader(sr))
2933
{

TS3AudioBot/MainCommands.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,11 @@ public static void CommandListPlay(PlaylistManager playlistManager, PlayManager
817817
{
818818
var plist = AutoGetPlaylist(session, invoker);
819819

820-
if (!index.HasValue || (index.Value >= 0 && index.Value < plist.Count))
821-
{
822-
playlistManager.PlayFreelist(plist);
823-
playlistManager.Index = index ?? 0;
824-
}
825-
else
826-
{
820+
if (index.HasValue && (index.Value < 0 || index.Value >= plist.Count))
827821
throw new CommandException(strings.error_playlist_item_index_out_of_range, CommandExceptionReason.CommandError);
828-
}
822+
823+
playlistManager.PlayFreelist(plist);
824+
playlistManager.Index = index ?? 0;
829825

830826
var item = playlistManager.Current();
831827
if (item != null)
@@ -891,9 +887,7 @@ public static JsonArray<PlaylistItem> CommandListShow(PlaylistManager playlistMa
891887

892888
[Command("next")]
893889
public static void CommandNext(PlayManager playManager, InvokerData invoker)
894-
{
895-
playManager.Next(invoker).UnwrapThrow();
896-
}
890+
=> playManager.Next(invoker).UnwrapThrow();
897891

898892
[Command("pm")]
899893
public static string CommandPm(CallerInfo caller, InvokerData invoker)
@@ -1340,20 +1334,16 @@ public static void CommandUnsubscribe(IVoiceTarget targetManager, InvokerData in
13401334
[Command("unsubscribe channel")]
13411335
public static void CommandUnsubscribeChannel(IVoiceTarget targetManager, InvokerData invoker, ulong? channel = null)
13421336
{
1343-
var subChan = channel ?? invoker.ChannelId ?? 0;
1344-
if (subChan != 0)
1345-
targetManager.WhisperChannelUnsubscribe(subChan, false);
1337+
var subChan = channel ?? invoker.ChannelId;
1338+
if (subChan.HasValue)
1339+
targetManager.WhisperChannelUnsubscribe(subChan.Value, false);
13461340
}
13471341

13481342
[Command("unsubscribe temporary")]
13491343
public static void CommandUnsubscribeTemporary(IVoiceTarget targetManager) => targetManager.ClearTemporary();
13501344

13511345
[Command("version")]
1352-
public static JsonValue<BuildData> CommandVersion()
1353-
{
1354-
var data = SystemData.AssemblyData;
1355-
return new JsonValue<BuildData>(data, data.ToLongString());
1356-
}
1346+
public static JsonValue<BuildData> CommandVersion() => new JsonValue<BuildData>(SystemData.AssemblyData, d => d.ToLongString());
13571347

13581348
[Command("volume")]
13591349
[Usage("<level>", "A new volume level between 0 and 100.")]

TS3Client/Full/Ts3FullClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ partial void ProcessEachInitServer(InitServer initServer)
269269
partial void ProcessEachPluginCommand(PluginCommand cmd)
270270
{
271271
if (cmd.Name == "cliententerview" && cmd.Data == "version")
272-
SendPluginCommand("cliententerview", "TAB", PluginTargetMode.Client);
272+
SendPluginCommand("cliententerview", "TAB", PluginTargetMode.Server);
273273
}
274274

275275
partial void ProcessEachCommandError(CommandError error)

0 commit comments

Comments
 (0)