Browse Source

Merge branch 'release/3.x' of https://github.com/Discord-Net-Labs/Discord.Net-Labs into release/3.x

pull/1958/head
quin lynch 3 years ago
parent
commit
45ec6ae82d
2 changed files with 11 additions and 20 deletions
  1. +8
    -2
      src/Discord.Net.Interactions/Map/CommandMap.cs
  2. +3
    -18
      src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs

+ 8
- 2
src/Discord.Net.Interactions/Map/CommandMap.cs View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;


namespace Discord.Interactions namespace Discord.Interactions
{ {
@@ -46,8 +47,13 @@ namespace Discord.Interactions
_root.RemoveCommand(key, 0); _root.RemoveCommand(key, 0);
} }


public SearchResult<T> GetCommand(string input) =>
GetCommand(input.Split(_seperators));
public SearchResult<T> GetCommand(string input)
{
if(_seperators.Any())
return GetCommand(input.Split(_seperators));
else
return GetCommand(new string[] { input });
}


public SearchResult<T> GetCommand(string[] input) => public SearchResult<T> GetCommand(string[] input) =>
_root.GetCommand(input, 0); _root.GetCommand(input, 0);


+ 3
- 18
src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs View File

@@ -2,10 +2,6 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;


namespace Discord.Net.Converters namespace Discord.Net.Converters
{ {
@@ -18,9 +14,6 @@ namespace Discord.Net.Converters
public override bool CanWrite => false; public override bool CanWrite => false;
public override bool CanRead => true; public override bool CanRead => true;



private Regex _readRegex = new Regex(@"_(\w)");

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{ {
var obj = JToken.Load(reader); var obj = JToken.Load(reader);
@@ -31,20 +24,11 @@ namespace Discord.Net.Converters


foreach(var item in arr) foreach(var item in arr)
{ {
var name = _readRegex.Replace(item.ToLower(), (x) =>
if (Enum.TryParse<GuildFeature>(string.Concat(item.Split('_')), true, out var result))
{ {
return x.Groups[1].Value.ToUpper();
});

name = name[0].ToString().ToUpper() + new string(name.Skip(1).ToArray());

try
{
var result = (GuildFeature)Enum.Parse(typeof(GuildFeature), name);

features |= result; features |= result;
} }
catch
else
{ {
experimental.Add(item); experimental.Add(item);
} }
@@ -52,6 +36,7 @@ namespace Discord.Net.Converters


return new GuildFeatures(features, experimental.ToArray()); return new GuildFeatures(features, experimental.ToArray());
} }

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
throw new NotImplementedException(); throw new NotImplementedException();


Loading…
Cancel
Save