Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.x' of https://github.com/Discord-Net-Labs/Dis…
Browse files Browse the repository at this point in the history
…cord.Net-Labs into release/3.x
quinchs committed Nov 26, 2021
2 parents d472882 + 27c249b commit 45ec6ae
Showing 2 changed files with 11 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/Discord.Net.Interactions/Map/CommandMap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Discord.Interactions
{
@@ -46,8 +47,13 @@ public void RemoveCommand(T command)
_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) =>
_root.GetCommand(input, 0);
21 changes: 3 additions & 18 deletions src/Discord.Net.Rest/Net/Converters/GuildFeaturesConverter.cs
Original file line number Diff line number Diff line change
@@ -2,10 +2,6 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

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


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

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var obj = JToken.Load(reader);
@@ -31,27 +24,19 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist

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;
}
catch
else
{
experimental.Add(item);
}
}

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

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

0 comments on commit 45ec6ae

Please sign in to comment.