Skip to content

Commit c7fc4f2

Browse files
committed
More cleanups, maybe github actions wants to work?
1 parent 499cdfd commit c7fc4f2

19 files changed

+176
-185
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@main
1717
- uses: actions/setup-dotnet@v1
1818
with:
19-
dotnet-version: '5.0.201'
19+
dotnet-version: '3.1.408'
2020
- name: Compile
2121
run: bash build.sh
2222
- name: Upload Linux binary

src/Commands/Modules/AdminUtility/AnnounceCommand.cs

+21-26
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,17 @@ public async Task<ActionResult> AnnounceAsync(
2121
"Unix-style command line arguments. Example: `-description=\"Some cool thing!\"` will set the embed's description.")]
2222
Dictionary<string, string> options)
2323
{
24-
var embed = new EmbedBuilder();
25-
var shouldPublish = options.TryGetValue("publish", out _) || options.TryGetValue("crosspost", out _);
26-
27-
string GetRoleMention(TypeParserResult<SocketRole> res) => res.IsSuccessful ? res.Value.Mention : null;
24+
static string GetRoleMention(TypeParserResult<SocketRole> res) =>
25+
res.IsSuccessful ? res.Value.Mention : null;
2826

29-
Color GetColor(TypeParserResult<Color> res) =>
27+
static Color GetColor(TypeParserResult<Color> res) =>
3028
res.IsSuccessful ? res.Value : new Color(Config.SuccessColor);
3129

32-
RestGuildUser GetUser(TypeParserResult<RestGuildUser> res) => res.IsSuccessful ? res.Value : null;
30+
static RestGuildUser GetUser(TypeParserResult<RestGuildUser> res) => res.IsSuccessful ? res.Value : null;
3331

34-
string toMention = null;
35-
36-
if (options.TryGetValue("mention", out var result) || options.TryGetValue("ping", out result))
37-
{
38-
toMention = result switch
39-
{
40-
"none" => null,
41-
"everyone" => "@everyone",
42-
"here" => "@here",
43-
_ => GetRoleMention(await CommandService.GetTypeParser<SocketRole>()
44-
.ParseAsync(null, result, Context))
45-
};
46-
}
32+
var embed = new EmbedBuilder();
4733

48-
if (options.TryGetValue("footer", out result) || options.TryGetValue("foot", out result))
34+
if (options.TryGetValue("footer", out var result) || options.TryGetValue("foot", out result))
4935
embed.WithFooter(result);
5036

5137
if (options.TryGetValue("thumbnail", out result))
@@ -76,11 +62,9 @@ Color GetColor(TypeParserResult<Color> res) =>
7662

7763
if (options.TryGetValue("author", out result))
7864
{
79-
if (result.EqualsIgnoreCase("self") || result.EqualsIgnoreCase("me"))
65+
if (result.EqualsAnyIgnoreCase("self", "me"))
8066
embed.WithAuthor(Context.User);
81-
else if (result.EqualsIgnoreCase("bot")
82-
|| result.EqualsIgnoreCase("you")
83-
|| result.EqualsIgnoreCase("volte"))
67+
else if (result.EqualsAnyIgnoreCase("bot", "you", "volte"))
8468
embed.WithAuthor(Context.Guild.CurrentUser);
8569
else
8670
{
@@ -93,9 +77,20 @@ Color GetColor(TypeParserResult<Color> res) =>
9377

9478
return Ok(async () =>
9579
{
96-
var m = await Context.Channel.SendMessageAsync(toMention, embed: embed.Build());
80+
var m = await Context.Channel.SendMessageAsync(options.TryGetValue("mention", out result) || options.TryGetValue("ping", out result)
81+
? result switch
82+
{
83+
"none" => null,
84+
"everyone" => "@everyone",
85+
"here" => "@here",
86+
_ => GetRoleMention(await CommandService.GetTypeParser<SocketRole>()
87+
.ParseAsync(null, result, Context))
88+
}
89+
: null, embed: embed.Build());
9790
await Context.Message.TryDeleteAsync();
98-
if (shouldPublish) await m.CrosspostAsync();
91+
if ((options.TryGetValue("publish", out _) || options.TryGetValue("crosspost", out _))
92+
&& Context.Channel is INewsChannel)
93+
await m.CrosspostAsync();
9994
});
10095
}
10196
}

src/Commands/Modules/BotOwner/AddonCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Task<ActionResult> AddonAsync([Remainder, Description("An addon's name.")
2929
.ToList();
3030

3131
if (addonEmbeds.Count is 1) return Ok(addonEmbeds.First());
32-
return Ok(PaginatedMessageBuilder.New
32+
return Ok(PaginatedMessage.Builder.New
3333
.WithDefaults(Context)
3434
.WithPages(addonEmbeds)
3535
.WithTitle("All installed addons"));

src/Commands/Modules/HelpCommand.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ public async Task<ActionResult> HelpAsync(
2323
{
2424
if (query != null)
2525
{
26-
if (query.EqualsIgnoreCase("pages") || query.EqualsIgnoreCase("pager"))
26+
if (query.EqualsAnyIgnoreCase("pages", "pager"))
2727
{
28-
return Ok(PaginatedMessageBuilder.New
29-
.WithDefaults(Context)
30-
.WithPages(await GetPagesAsync().ToListAsync()));
28+
return Ok(await GetPagesAsync().ToListAsync());
3129
}
3230

3331
var search = CommandService.FindCommands(query);

src/Commands/Modules/Moderation/WarnCommands.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Task<ActionResult> WarnsAsync([Remainder, Description("The member to list
4141
{
4242
var warns = Db.GetData(Context.Guild).Extras.Warns.Where(x => x.User == member.Id)
4343
.Select(x => $"{Format.Bold(x.Reason)}, on {Format.Bold(x.Date.FormatDate())}");
44-
return Ok(PaginatedMessageBuilder.New
44+
return Ok(PaginatedMessage.Builder.New
4545
.WithPages(warns)
4646
.WithTitle($"Warns for {member}")
4747
.SplitPages(8)

src/Commands/Modules/Utility/UrbanCommand.cs

+14-11
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ public async Task<ActionResult> UrbanAsync([Remainder, Description("The word to
1919
{
2020
var res = await RequestUrbanDefinitionsAsync(word);
2121

22-
EmbedBuilder CreateEmbed(UrbanEntry entry)
22+
EmbedBuilder CreateEmbed(UrbanEntry entry)
2323
{
2424
if (entry.Definition.Length > 1024)
2525
{
2626
var oldDefLength = entry.Definition.Length;
27-
entry.Definition = string.Join("", entry.Definition.Take(980)) + Format.Bold($"\n...and {oldDefLength - 980} more {"character".ToQuantity(oldDefLength - 980).Split(" ").Last()}.");
28-
} else if (entry.Definition.IsEmpty())
27+
entry.Definition = string.Join("", entry.Definition.Take(980)) +
28+
Format.Bold(
29+
$"\n...and {oldDefLength - 980} more {"character".ToQuantity(oldDefLength - 980).Split(" ").Last()}.");
30+
}
31+
else if (entry.Definition.IsEmpty())
2932
entry.Definition = "<error occurred>";
3033

3134
return Context.CreateEmbedBuilder()
32-
.WithThumbnailUrl("https://upload.wikimedia.org/wikipedia/vi/7/70/Urban_Dictionary_logo.png")
33-
.AddField("URL", entry.Permalink.IsNullOrEmpty() ? "None provided" : entry.Permalink, true)
34-
.AddField("Thumbs Up/Down", $"{entry.Upvotes}/{entry.Downvotes}", true)
35-
.AddField("Definition", entry.Definition)
36-
.AddField("Example", entry.Example.IsNullOrEmpty() ? "None provided" : entry.Example)
37-
.AddField("Author", entry.Author.IsNullOrEmpty() ? "None provided" : entry.Author, true)
38-
.AddField("Created", entry.CreatedAt.FormatBoldString(), true);
35+
.WithThumbnailUrl("https://upload.wikimedia.org/wikipedia/vi/7/70/Urban_Dictionary_logo.png")
36+
.AddField("URL", entry.Permalink.IsNullOrEmpty() ? "None provided" : entry.Permalink, true)
37+
.AddField("Thumbs Up/Down", $"{entry.Upvotes}/{entry.Downvotes}", true)
38+
.AddField("Definition", entry.Definition)
39+
.AddField("Example", entry.Example.IsNullOrEmpty() ? "None provided" : entry.Example)
40+
.AddField("Author", entry.Author.IsNullOrEmpty() ? "None provided" : entry.Author, true)
41+
.AddField("Created", entry.CreatedAt.FormatBoldString(), true);
3942
}
4043

4144

@@ -45,7 +48,7 @@ EmbedBuilder CreateEmbed(UrbanEntry entry)
4548
? BadRequest("That word didn't have a definition of Urban Dictionary.")
4649
: pages.Count is 1
4750
? Ok(pages.First())
48-
: Ok(PaginatedMessageBuilder.New
51+
: Ok(PaginatedMessage.Builder.New
4952
.WithPages(pages)
5053
.WithTitle(word)
5154
.WithDefaults(Context));

src/Commands/Modules/Utility/WikiCommand.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Task<ActionResult> WikiAsync(
2020
string page = null)
2121
{
2222
var embed = Context.CreateEmbedBuilder()
23-
.WithThumbnailUrl("https://i.greemdev.net/volte_whitepinkyellow.png");
23+
.WithThumbnailUrl("https://img.greemdev.net/YmdTzPoEYx/volte_whiteorangepurple.png");
2424
var pages = new Dictionary<string, string>
2525
{
2626
{"Home", _baseWikiUrl},
@@ -34,21 +34,18 @@ public Task<ActionResult> WikiAsync(
3434
};
3535

3636
if (page is null)
37-
return Ok(embed.WithDescription(FormatPages()));
37+
return Ok(pages.Select(x => embed.WithTitle(x.Key).WithDescription(x.Value)));
3838

3939
return Ok(embed.WithDescription(pages.ContainsKey(page)
4040
? $"[{pages.Keys.FirstOrDefault(x => x.EqualsIgnoreCase(page))}]({pages.FirstOrDefault(x => x.Key.EqualsIgnoreCase(page)).Value})"
4141
: $"{page} wasn't found. Here's a list of valid wiki pages: {FormatPages()}"));
4242

4343

44-
string FormatPages()
44+
string FormatPages() => new StringBuilder().Apply(sb =>
4545
{
46-
var formattedPages = new StringBuilder();
4746
foreach (var (key, value) in pages)
48-
formattedPages.AppendLine($"[{key}]({value})");
49-
50-
return formattedPages.ToString();
51-
}
47+
sb.AppendLine($"[{key}]({value})");
48+
}).ToString();
5249
}
5350
}
5451
}

src/Commands/Parsers/UserParsers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public override ValueTask<TypeParserResult<SocketGuildUser>> ParseAsync(Paramete
2222
if (ulong.TryParse(value, out var id) || MentionUtils.TryParseUser(value, out id))
2323
user = users.FirstOrDefault(x => x.Id == id);
2424

25-
if (user is null) user = users.FirstOrDefault(x => x.ToString().EqualsIgnoreCase(value));
25+
user ??= users.FirstOrDefault(x => x.ToString().EqualsIgnoreCase(value));
2626

2727
if (user is null)
2828
{

src/Commands/Results/OkResult.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public OkResult(string text, bool shouldEmbed = true, EmbedBuilder embed = null,
2727
public OkResult(IEnumerable<EmbedBuilder> pages, int pageSplit = -1, Color? color = null, IGuildUser author = null,
2828
VolteContext ctx = null, string title = null, PaginatedAppearanceOptions options = null)
2929
{
30-
_pager = PaginatedMessageBuilder.New
30+
_pager = PaginatedMessage.Builder.New
3131
.WithPages(pages);
3232

3333
if (color.HasValue)
@@ -44,7 +44,7 @@ public OkResult(IEnumerable<EmbedBuilder> pages, int pageSplit = -1, Color? colo
4444
_pager.SplitPages(pageSplit);
4545
}
4646

47-
public OkResult(PaginatedMessageBuilder pager) => _pager = pager;
47+
public OkResult(PaginatedMessage.Builder pager) => _pager = pager;
4848

4949
public OkResult(Func<Task> logic, bool awaitFunc = true)
5050
{
@@ -56,7 +56,7 @@ public OkResult(Func<Task> logic, bool awaitFunc = true)
5656

5757
private readonly string _message;
5858
private readonly bool _shouldEmbed;
59-
private readonly PaginatedMessageBuilder _pager;
59+
private readonly PaginatedMessage.Builder _pager;
6060
private readonly Func<IUserMessage, Task> _callback;
6161
private readonly Func<Task> _separateLogic;
6262
private readonly EmbedBuilder _embed;

src/Commands/VolteModule.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected ActionResult Ok(
2929

3030
protected ActionResult Ok(StringBuilder text, Func<IUserMessage, Task> callback = null, bool shouldEmbed = true)
3131
=> Ok(text.ToString(), callback, shouldEmbed);
32-
protected ActionResult Ok(PaginatedMessageBuilder pager) => new OkResult(pager);
32+
protected ActionResult Ok(PaginatedMessage.Builder pager) => new OkResult(pager);
3333
protected ActionResult Ok(IEnumerable<EmbedBuilder> embeds) => new OkResult(embeds);
3434

3535

src/Core/Entities/EvalEnvironment.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ public async Task<IUserMessage> MessageAsync(ulong id)
5757
}
5858

5959
public SocketGuild Guild(ulong id) => Context.Client.GetGuild(id);
60-
public T GetFromProvider<T>() => Context.Services.GetRequiredService<T>();
60+
public T Service<T>() => Context.Services.GetRequiredService<T>();
6161

6262
public SocketUserMessage Message(string id)
63-
{
64-
if (ulong.TryParse(id, out var ulongId))
65-
{
66-
return Message(ulongId);
67-
}
63+
=> ulong.TryParse(id, out var ulongId)
64+
? Message(ulongId)
65+
: throw new ArgumentException(
66+
$"Method parameter {nameof(id)} is not a valid {typeof(ulong).FullName}.");
6867

69-
throw new ArgumentException($"Method parameter {nameof(id)} is not a valid {typeof(ulong).FullName}.");
70-
}
71-
7268
public Task ReplyAsync(string content) => Context.Channel.SendMessageAsync(content);
7369

7470
public Task ReplyAsync(Embed embed) => embed.SendToAsync(Context.Channel);

src/Core/Helpers/Extensions/SystemExtensions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Linq;
45
using System.Runtime.Serialization.Json;
56
using System.Text;
67
using System.Threading.Tasks;
@@ -14,6 +15,9 @@ namespace Gommon
1415
/// </summary>
1516
public static partial class Extensions
1617
{
18+
public static bool EqualsAnyIgnoreCase(this string str, params string[] potentialMatches)
19+
=> potentialMatches.Any(str.EqualsIgnoreCase);
20+
1721
public static string ReplaceIgnoreCase(this string str, string toReplace, object replacement)
1822
=> str.Replace(toReplace, replacement.ToString(), StringComparison.OrdinalIgnoreCase);
1923

src/Core/Interactive/InteractiveServiceConfig.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace Volte.Interactive
55
{
66
public class InteractiveServiceConfig
77
{
8-
public TimeSpan DefaultTimeout { get; set; } = 15.Seconds();
8+
public TimeSpan DefaultTimeout { get; set; }
9+
10+
public InteractiveServiceConfig(TimeSpan? defaultTimeout = null)
11+
{
12+
DefaultTimeout = defaultTimeout ?? 15.Seconds();
13+
}
914
}
1015
}

0 commit comments

Comments
 (0)