Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit fb333ce

Browse files
casually update this bot
1 parent 9d352fd commit fb333ce

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

Modules/Commands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public async Task EvalAsync(CommandContext ctx, [RemainingText] string code)
280280
[RequireOwner]
281281
public async Task SetDocsUrlAsync(CommandContext ctx, [RemainingText] string url)
282282
{
283-
if (!url.EndsWith("/"))
283+
if (!url.EndsWith('/'))
284284
{
285285
url += "/";
286286
}

Query/Extensions/BaseDisplay.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static async Task<DocsHttpResult> GetWebDocsAsync(string url, object o)
4444
string html = result.Item2;
4545
if (result.Item1 && !string.IsNullOrEmpty(html))
4646
{
47-
string block = (o is TypeInfoWrapper) ? html[html.IndexOf($"<h1 id=\"{search}")..] : html[html.IndexOf($"<h4 id=\"{search}")..];
47+
string block = o is TypeInfoWrapper ? html[html.IndexOf($"<h1 id=\"{search}")..] : html[html.IndexOf($"<h4 id=\"{search}")..];
4848
string anchor = block[(block.IndexOf('"') + 1)..];
4949
anchor = anchor[..anchor.IndexOf('"')];
5050
summary = block[(block.IndexOf("summary\">") + 9)..];
@@ -89,9 +89,9 @@ private static async Task<DocsHttpResult> GetWebDocsAsync(string url, object o)
8989
}
9090
}
9191
}
92-
using (HttpClient httpClient = new()
93-
{ Timeout = TimeSpan.FromSeconds(6) })
92+
using (HttpClient httpClient = new())
9493
{
94+
httpClient.Timeout = TimeSpan.FromSeconds(6);
9595
HttpResponseMessage res = await httpClient.GetAsync(url);
9696
if (!res.IsSuccessStatusCode)
9797
{
@@ -236,7 +236,7 @@ private static string FormatDocsUrl(string url)
236236
{
237237
int idx = url.IndexOf('#');
238238
string[] arr = idx == -1 ? url[..].Split('.') : url[..idx].Split('.');
239-
return $"[{arr.ElementAt(arr.Length - 2)}.html]({url})";
239+
return $"[{arr[^2]}.html]({url})";
240240
}
241241
}
242242
}

Query/Extensions/MethodDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private static string BuildMethod(MethodInfoWrapper methodWrapper)
102102
{
103103
MethodInfo mi = methodWrapper.Method;
104104
ParameterInfo[] parametersInfo = mi.GetParameters();
105-
IEnumerable<string> parameters = mi.IsDefined(typeof(ExtensionAttribute)) && parametersInfo.First().ParameterType.IsAssignableFrom(methodWrapper.Parent.TypeInfo.AsType())
105+
IEnumerable<string> parameters = mi.IsDefined(typeof(ExtensionAttribute)) && parametersInfo[0].ParameterType.IsAssignableFrom(methodWrapper.Parent.TypeInfo.AsType())
106106
? parametersInfo.Skip(1).Select(x => $"{BuildPreParameter(x)}{Utils.BuildType(x.ParameterType)} {x.Name}{GetParameterDefaultValue(x)}")
107107
: parametersInfo.Select(x => $"{BuildPreParameter(x)}{Utils.BuildType(x.ParameterType)} {x.Name}{GetParameterDefaultValue(x)}");
108108
return $"{Utils.BuildType(mi.ReturnType)} {mi.Name}({string.Join(", ", parameters)})";

Query/ResultDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private async Task<DiscordEmbedBuilder> ShowAsync(IEnumerable<object> o)
6767

6868
private async Task<DiscordEmbedBuilder> ShowMultipleAsync(IEnumerable<IEnumerable<object>> obj)
6969
{
70-
DiscordEmbedBuilder eb = new();
70+
DiscordEmbedBuilder eb;
7171
IEnumerable<object> singleList = obj.Select(x => x.First());
7272
IEnumerable<IGrouping<string, object>> same = singleList.GroupBy(x => GetSimplePath(x));
7373
if (same.Count() == 1)

Query/TextInterpreter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace DSharpPlusDocs.Query
2929
{
30-
public class TextInterpreter
30+
public partial class TextInterpreter
3131
{
3232
private static readonly Regex rgx = new("[^0-9a-z_ ]", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ECMAScript);
3333

@@ -61,7 +61,7 @@ public InterpreterResult Run()
6161
searchEvents = false;
6262
}
6363

64-
Regex rgx = new("( property | method | type | event )", RegexOptions.IgnoreCase);
64+
Regex rgx = TypeRegex();
6565
_text = rgx.Replace(_text, " ");
6666
}
6767
if (_text.IndexOf(" list ", StringComparison.OrdinalIgnoreCase) != -1)
@@ -112,5 +112,8 @@ public InterpreterResult Run()
112112
? new InterpreterResult("No text to search.")
113113
: new InterpreterResult(_text, nspace, search, searchTypes, searchMethods, searchProperties, searchEvents, isList);
114114
}
115+
116+
[GeneratedRegex("( property | method | type | event )", RegexOptions.IgnoreCase, "ru-RU")]
117+
private static partial Regex TypeRegex();
115118
}
116119
}

Rest/GithubRest.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,11 @@ namespace DSharpPlusDocs.Rest
3636
public class GithubRest
3737
{
3838
private const string ApiUrl = "https://api.github.com";
39-
private const string AcceptHeader = "application/vnd.github.v3+json";
40-
4139
private static async Task<JObject> SendRequestAsync(HttpMethod method, string endpoint, string extra = null, string acceptHeader = null)
4240
{
4341
using HttpClient http = new();
4442
HttpRequestMessage request = new(method, $"{ApiUrl}{endpoint}{extra}");
45-
if (acceptHeader == null)
46-
{
47-
acceptHeader = "application/vnd.github.v3+json";
48-
}
43+
acceptHeader ??= "application/vnd.github.v3+json";
4944

5045
request.Headers.Add("Accept", acceptHeader);
5146
request.Headers.Add("User-Agent", "DSharpPlus Docs Bot/1.0");
@@ -89,20 +84,20 @@ private static async Task<List<GitSearchResult>> SearchAsync(string search, stri
8984
public static async Task<string> GetTypeUrlAsync(TypeInfoWrapper type)
9085
{
9186
List<GitSearchResult> search = await SearchAsync(type.Name, $"{type.Name}.cs");
92-
return search.FirstOrDefault(x => x.Name == $"{type.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl ?? null; //null = Not found
87+
return search.Find(x => x.Name == $"{type.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl ?? null; //null = Not found
9388
}
9489

9590
public static async Task<string> GetEventUrlAsync(EventInfoWrapper ev)
9691
{
9792
List<GitSearchResult> search = await SearchAsync(ev.Parent.Name, $"{ev.Parent.Name}.cs");
98-
string result = search.FirstOrDefault(x => x.Name == $"{ev.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
93+
string result = search.Find(x => x.Name == $"{ev.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
9994
if (result != null)
10095
{
10196
using HttpClient client = new();
10297
string url = result.Replace("/blob/", "/raw/");
10398
string code = await client.GetStringAsync(url);
10499
Microsoft.CodeAnalysis.SyntaxTree tree = CSharpSyntaxTree.ParseText(code);
105-
CompilationUnitSyntax root = (CompilationUnitSyntax)tree.GetRoot();
100+
CompilationUnitSyntax root = (CompilationUnitSyntax)await tree.GetRootAsync();
106101
EventDeclarationSyntax source = root.DescendantNodes().OfType<EventDeclarationSyntax>().FirstOrDefault(x => x.Identifier.ValueText == ev.Event.Name);
107102
if (source == null)
108103
{
@@ -119,14 +114,14 @@ public static async Task<string> GetEventUrlAsync(EventInfoWrapper ev)
119114
public static async Task<string> GetMethodUrlAsync(MethodInfoWrapper method)
120115
{
121116
List<GitSearchResult> search = await SearchAsync(method.Method.Name, $"{method.Parent.Name}.cs");
122-
string result = search.FirstOrDefault(x => x.Name == $"{method.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
117+
string result = search.Find(x => x.Name == $"{method.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
123118
if (result != null)
124119
{
125120
using HttpClient client = new();
126121
string url = result.Replace("/blob/", "/raw/");
127122
string code = await client.GetStringAsync(url);
128123
Microsoft.CodeAnalysis.SyntaxTree tree = CSharpSyntaxTree.ParseText(code);
129-
CompilationUnitSyntax root = (CompilationUnitSyntax)tree.GetRoot();
124+
CompilationUnitSyntax root = (CompilationUnitSyntax)await tree.GetRootAsync();
130125
MethodDeclarationSyntax source = root.DescendantNodes().OfType<MethodDeclarationSyntax>().FirstOrDefault(x => x.Identifier.ValueText == method.Method.Name);
131126
if (source == null)
132127
{
@@ -143,14 +138,14 @@ public static async Task<string> GetMethodUrlAsync(MethodInfoWrapper method)
143138
public static async Task<string> GetPropertyUrlAsync(PropertyInfoWrapper property)
144139
{
145140
List<GitSearchResult> search = await SearchAsync(property.Property.Name, $"{property.Parent.Name}.cs");
146-
string result = search.FirstOrDefault(x => x.Name == $"{property.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
141+
string result = search.Find(x => x.Name == $"{property.Parent.Name}.cs")?.HtmlUrl ?? search.FirstOrDefault()?.HtmlUrl;
147142
if (result != null)
148143
{
149144
using HttpClient client = new();
150145
string url = result.Replace("/blob/", "/raw/");
151146
string code = await client.GetStringAsync(url);
152147
Microsoft.CodeAnalysis.SyntaxTree tree = CSharpSyntaxTree.ParseText(code);
153-
CompilationUnitSyntax root = (CompilationUnitSyntax)tree.GetRoot();
148+
CompilationUnitSyntax root = (CompilationUnitSyntax)await tree.GetRootAsync();
154149
PropertyDeclarationSyntax source = root.DescendantNodes().OfType<PropertyDeclarationSyntax>().FirstOrDefault(x => x.Identifier.ValueText == property.Property.Name);
155150
if (source == null)
156151
{

0 commit comments

Comments
 (0)