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

Commit 9bf043f

Browse files
committed
Fix IDE errors
1 parent f199f6c commit 9bf043f

28 files changed

+1288
-1382
lines changed

Controllers/MainHandler.cs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
// This file is part of the DSharpPlus project.
2-
//
3-
// Copyright (c) 2015 Mike Santiago
4-
// Copyright (c) 2016-2022 DSharpPlus Contributors
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
1+
// This file is part of the DSharpPlus project.
2+
//
3+
// Copyright (c) 2015 Mike Santiago
4+
// Copyright (c) 2016-2022 DSharpPlus Contributors
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
2424
using System.Threading.Tasks;
2525
using DSharpPlus;
2626
using DSharpPlusDocs.Handlers;
@@ -48,7 +48,5 @@ public async Task InitializeEarlyAsync()
4848
await CommandHandler.InitializeAsync(this);
4949
QueryHandler.Initialize();
5050
}
51-
52-
public MainHandler() => new MainHandler();
5351
}
5452
}

EmbedExtension/PaginatorBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// SOFTWARE.
2323

2424
using System.Collections.Generic;
25-
using DSharpPlus.Entities;
25+
using DSharpPlus.Entities;
2626

2727
namespace DSharpPlusDocs.EmbedExtension
2828
{

Handlers/CommandHandler.cs

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
// This file is part of the DSharpPlus project.
2-
//
3-
// Copyright (c) 2015 Mike Santiago
4-
// Copyright (c) 2016-2022 DSharpPlus Contributors
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files (the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions:
12-
//
13-
// The above copyright notice and this permission notice shall be included in all
14-
// copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
// SOFTWARE.
23-
1+
// This file is part of the DSharpPlus project.
2+
//
3+
// Copyright (c) 2015 Mike Santiago
4+
// Copyright (c) 2016-2022 DSharpPlus Contributors
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
2424
using System;
2525
using System.Threading.Tasks;
2626
using DSharpPlus;
@@ -43,13 +43,13 @@ public class CommandHandler
4343
private DiscordClient _client;
4444
private MainHandler _mainHandler;
4545
private IServiceProvider _services;
46-
private readonly MemoryCache cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(3) });
46+
private readonly MemoryCache cache = new(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(3) });
4747

4848
public Task InitializeAsync(MainHandler mainHandler)
4949
{
5050
_mainHandler = mainHandler;
5151
_client = mainHandler.Client;
52-
ServiceCollection services = new ServiceCollection();
52+
ServiceCollection services = new();
5353
services.AddSingleton(mainHandler);
5454
services.AddSingleton(new PaginationService(_client));
5555
_services = services.BuildServiceProvider();
@@ -66,42 +66,42 @@ public Task InitializeAsync(MainHandler mainHandler)
6666
_commands.RegisterCommands<GeneralCommands>();
6767

6868
_client.MessageUpdated += HandleUpdate;
69-
_commands.CommandErrored += _commands_CommandErrored;
69+
_commands.CommandErrored += CommandErroredAsync;
7070

7171
return Task.CompletedTask;
7272
}
7373

74-
private async Task _commands_CommandErrored(CommandsNextExtension commandsNext, CommandErrorEventArgs e)
74+
private async Task CommandErroredAsync(CommandsNextExtension commandsNext, CommandErrorEventArgs e)
7575
{
7676
if (e.Exception is CommandNotFoundException)
7777
{
78-
(string, DiscordEmbedBuilder, PaginatedMessage) reply = await BuildReply(e.Context.Message, e.Context.Message.Content.Substring(e.Context.Message.GetMentionPrefixLength(_client.CurrentUser)));
79-
if (reply.Item1 == null && reply.Item2 == null && reply.Item3 == null)
80-
{
81-
return;
82-
}
83-
84-
DiscordMessage message = reply.Item3 != null
85-
? await e.Context.Services.GetService<PaginationService>().SendPaginatedMessageAsync(e.Context.Channel, reply.Item3)
78+
(string, DiscordEmbedBuilder, PaginatedMessage) reply = await BuildReplyAsync(e.Context.Message, e.Context.Message.Content[e.Context.Message.GetMentionPrefixLength(_client.CurrentUser)..]);
79+
if (reply.Item1 == null && reply.Item2 == null && reply.Item3 == null)
80+
{
81+
return;
82+
}
83+
84+
DiscordMessage message = reply.Item3 != null
85+
? await e.Context.Services.GetService<PaginationService>().SendPaginatedMessageAsync(e.Context.Channel, reply.Item3)
8686
: await e.Context.RespondAsync(reply.Item1, embed: reply.Item2);
8787
AddCache(e.Context.Message.Id, message.Id);
8888
}
89-
else
90-
{
91-
Console.WriteLine(e.Exception);
92-
}
89+
else
90+
{
91+
Console.WriteLine(e.Exception);
92+
}
9393
}
9494

9595
public Task<int> HandleCommand(DiscordMessage msg)
9696
{
97-
if (!msg.Channel.IsPrivate && msg.Channel.Guild.Id == 81384788765712384)
98-
{
99-
if (msg.Channel.Name != "dotnet_dsharpplus" && msg.Channel.Name != "testing" && msg.Channel.Name != "playground")
100-
{
101-
return Task.FromResult(-1);
102-
}
103-
}
104-
97+
if (!msg.Channel.IsPrivate && msg.Channel.Guild.Id == 81384788765712384)
98+
{
99+
if (msg.Channel.Name is not "dotnet_dsharpplus" and not "testing" and not "playground")
100+
{
101+
return Task.FromResult(-1);
102+
}
103+
}
104+
105105
return Task.FromResult(msg.GetMentionPrefixLength(_client.CurrentUser));
106106
}
107107

@@ -113,36 +113,36 @@ private Task HandleUpdate(DiscordClient client, MessageUpdateEventArgs e)
113113
if ((id = GetOurMessageIdFromCache(e.Message.Id)) != null)
114114
{
115115
DiscordMessage botMessage = await e.Channel.GetMessageAsync(id.Value);
116-
if (botMessage == null)
117-
{
118-
return;
119-
}
120-
116+
if (botMessage == null)
117+
{
118+
return;
119+
}
120+
121121
int argPos = 0;
122-
if ((argPos = await HandleCommand(e.Message)) == -1)
123-
{
124-
return;
125-
}
126-
127-
(string, DiscordEmbedBuilder, PaginatedMessage) reply = await BuildReply(e.Message, e.Message.Content.Substring(argPos));
122+
if ((argPos = await HandleCommand(e.Message)) == -1)
123+
{
124+
return;
125+
}
126+
127+
(string, DiscordEmbedBuilder, PaginatedMessage) reply = await BuildReplyAsync(e.Message, e.Message.Content[argPos..]);
128+
129+
if (reply.Item1 == null && reply.Item2 == null && reply.Item3 == null)
130+
{
131+
return;
132+
}
128133

129-
if (reply.Item1 == null && reply.Item2 == null && reply.Item3 == null)
130-
{
131-
return;
132-
}
133-
134134
PaginationService pagination = _services.GetService<PaginationService>();
135135
bool isPaginatedMessage = pagination.IsPaginatedMessage(id.Value);
136136
if (reply.Item3 != null)
137137
{
138-
if (isPaginatedMessage)
139-
{
140-
await pagination.UpdatePaginatedMessageAsync(botMessage, reply.Item3);
141-
}
142-
else
143-
{
144-
await pagination.EditMessageToPaginatedMessageAsync(botMessage, reply.Item3);
145-
}
138+
if (isPaginatedMessage)
139+
{
140+
await pagination.UpdatePaginatedMessageAsync(botMessage, reply.Item3);
141+
}
142+
else
143+
{
144+
await pagination.EditMessageToPaginatedMessageAsync(botMessage, reply.Item3);
145+
}
146146
}
147147
else
148148
{
@@ -158,7 +158,7 @@ private Task HandleUpdate(DiscordClient client, MessageUpdateEventArgs e)
158158
return Task.CompletedTask;
159159
}
160160

161-
private async Task<(string, DiscordEmbedBuilder, PaginatedMessage)> BuildReply(DiscordMessage msg, string message)
161+
private async Task<(string, DiscordEmbedBuilder, PaginatedMessage)> BuildReplyAsync(DiscordMessage msg, string message)
162162
{
163163
if (!_mainHandler.QueryHandler.IsReady())
164164
{
@@ -171,13 +171,13 @@ private Task HandleUpdate(DiscordClient client, MessageUpdateEventArgs e)
171171
(string, object) tuple = await _mainHandler.QueryHandler.RunAsync(message);
172172
if (tuple.Item2 is PaginatorBuilder pag)
173173
{
174-
PaginatedMessage paginated = new PaginatedMessage(pag.Pages, "Results", user: msg.Author, options: new AppearanceOptions { Timeout = TimeSpan.FromMinutes(10) });
174+
PaginatedMessage paginated = new(pag.Pages, "Results", user: msg.Author, options: new AppearanceOptions { Timeout = TimeSpan.FromMinutes(10) });
175175
return (null, null, paginated);
176176
}
177-
else
178-
{
179-
return (tuple.Item1, tuple.Item2 as DiscordEmbedBuilder, null);
180-
}
177+
else
178+
{
179+
return (tuple.Item1, tuple.Item2 as DiscordEmbedBuilder, null);
180+
}
181181
}
182182
catch (Exception e)
183183
{

Handlers/QueryHandler.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@
2121
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
// SOFTWARE.
2323

24-
using System.Threading.Tasks;
25-
using DSharpPlusDocs.Query;
26-
using DSharpPlusDocs.Query.Results;
27-
28-
namespace DSharpPlusDocs.Handlers
29-
{
30-
public class QueryHandler
31-
{
32-
public Cache Cache { get; private set; }
33-
public static string DocsBaseUrl { get; set; } = "https://dsharpplus.emzi0767.com/";
34-
35-
public QueryHandler() => Cache = new Cache();
36-
37-
public void Initialize() => Cache.Initialize();
38-
39-
public async Task<(string, object)> RunAsync(string text)
40-
{
41-
InterpreterResult interpreterResult = new TextInterpreter(text).Run();
24+
using System.Threading.Tasks;
25+
using DSharpPlusDocs.Query;
26+
using DSharpPlusDocs.Query.Results;
27+
28+
namespace DSharpPlusDocs.Handlers
29+
{
30+
public class QueryHandler
31+
{
32+
public Cache Cache { get; private set; }
33+
public static string DocsBaseUrl { get; set; } = "https://dsharpplus.emzi0767.com/";
34+
35+
public QueryHandler() => Cache = new Cache();
36+
37+
public void Initialize() => Cache.Initialize();
38+
39+
public async Task<(string, object)> RunAsync(string text)
40+
{
41+
InterpreterResult interpreterResult = new TextInterpreter(text).Run();
4242
if (!interpreterResult.IsSuccess)
4343
{
4444
return ($"{interpreterResult.Error}", null);
4545
}
4646

47-
object result = interpreterResult.Search == SearchType.JUST_NAMESPACE
48-
? await SearchAsync(interpreterResult, SearchType.NONE) ?? await SearchAsync(interpreterResult, SearchType.JUST_NAMESPACE) ?? await SearchAsync(interpreterResult, SearchType.JUST_TEXT) ?? await SearchAsync(interpreterResult, SearchType.ALL)
49-
: await SearchAsync(interpreterResult, SearchType.NONE) ?? await SearchAsync(interpreterResult, SearchType.JUST_TEXT) ?? await SearchAsync(interpreterResult, SearchType.JUST_NAMESPACE) ?? await SearchAsync(interpreterResult, SearchType.ALL);
50-
return result == null ? ($"No results found for `{text}`.", null) : ("", result);
51-
}
52-
53-
private async Task<object> SearchAsync(InterpreterResult interpreterResult, SearchType type)
54-
{
55-
interpreterResult.Search = type;
56-
SearchResult<object> searchResult = new Search(interpreterResult, Cache).Run();
57-
return searchResult.Count != 0 ? await new ResultDisplay(searchResult, Cache, interpreterResult.IsList).RunAsync() : null;
58-
}
59-
60-
public bool IsReady() => Cache.IsReady();
61-
}
62-
}
47+
object result = interpreterResult.Search == SearchType.JustNamespace
48+
? await SearchAsync(interpreterResult, SearchType.None) ?? await SearchAsync(interpreterResult, SearchType.JustNamespace) ?? await SearchAsync(interpreterResult, SearchType.JustText) ?? await SearchAsync(interpreterResult, SearchType.All)
49+
: await SearchAsync(interpreterResult, SearchType.None) ?? await SearchAsync(interpreterResult, SearchType.JustText) ?? await SearchAsync(interpreterResult, SearchType.JustNamespace) ?? await SearchAsync(interpreterResult, SearchType.All);
50+
return result == null ? ($"No results found for `{text}`.", null) : ("", result);
51+
}
52+
53+
private async Task<object> SearchAsync(InterpreterResult interpreterResult, SearchType type)
54+
{
55+
interpreterResult.Search = type;
56+
SearchResult<object> searchResult = new Search(interpreterResult, Cache).Run();
57+
return searchResult.Count != 0 ? await new ResultDisplay(searchResult, Cache, interpreterResult.IsList).RunAsync() : null;
58+
}
59+
60+
public bool IsReady() => Cache.IsReady();
61+
}
62+
}

0 commit comments

Comments
 (0)