Removed cmd source generator. Commands are no longer partial methods. Compilations should be slightly faster now. Updated packages and adapted drawing code to the new apis. There may be some bugs.

This commit is contained in:
Kwoth
2022-07-18 04:33:50 +02:00
parent 3db194c186
commit 99c60459f8
98 changed files with 747 additions and 788 deletions

View File

@@ -15,7 +15,7 @@ public partial class Xp
=> _xps = xps;
[Cmd]
public async partial Task ClubTransfer([Leftover] IUser newOwner)
public async Task ClubTransfer([Leftover] IUser newOwner)
{
var club = _service.TransferClub(ctx.User, newOwner);
@@ -35,7 +35,7 @@ public partial class Xp
}
[Cmd]
public async partial Task ClubAdmin([Leftover] IUser toAdmin)
public async Task ClubAdmin([Leftover] IUser toAdmin)
{
var admin = await _service.ToggleAdminAsync(ctx.User, toAdmin);
@@ -47,7 +47,7 @@ public partial class Xp
await ReplyConfirmLocalizedAsync(strs.club_admin_remove(Format.Bold(toAdmin.ToString())));
}
[Cmd]
public async partial Task ClubCreate([Leftover] string clubName)
public async Task ClubCreate([Leftover] string clubName)
{
if (string.IsNullOrWhiteSpace(clubName) || clubName.Length > 20)
{
@@ -73,7 +73,7 @@ public partial class Xp
}
[Cmd]
public async partial Task ClubIcon([Leftover] string url = null)
public async Task ClubIcon([Leftover] string url = null)
{
if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url is not null)
|| !await _service.SetClubIconAsync(ctx.User.Id, url))
@@ -135,7 +135,7 @@ public partial class Xp
[Cmd]
[Priority(1)]
public async partial Task ClubInformation(IUser user = null)
public async Task ClubInformation(IUser user = null)
{
user ??= ctx.User;
var club = _service.GetClubByMember(user);
@@ -150,7 +150,7 @@ public partial class Xp
[Cmd]
[Priority(0)]
public async partial Task ClubInformation([Leftover] string clubName = null)
public async Task ClubInformation([Leftover] string clubName = null)
{
if (string.IsNullOrWhiteSpace(clubName))
{
@@ -168,7 +168,7 @@ public partial class Xp
}
[Cmd]
public partial Task ClubBans(int page = 1)
public Task ClubBans(int page = 1)
{
if (--page < 0)
return Task.CompletedTask;
@@ -194,7 +194,7 @@ public partial class Xp
}
[Cmd]
public partial Task ClubApps(int page = 1)
public Task ClubApps(int page = 1)
{
if (--page < 0)
return Task.CompletedTask;
@@ -220,7 +220,7 @@ public partial class Xp
}
[Cmd]
public async partial Task ClubApply([Leftover] string clubName)
public async Task ClubApply([Leftover] string clubName)
{
if (string.IsNullOrWhiteSpace(clubName))
return;
@@ -239,12 +239,12 @@ public partial class Xp
[Cmd]
[Priority(1)]
public partial Task ClubAccept(IUser user)
public Task ClubAccept(IUser user)
=> ClubAccept(user.ToString());
[Cmd]
[Priority(0)]
public async partial Task ClubAccept([Leftover] string userName)
public async Task ClubAccept([Leftover] string userName)
{
if (_service.AcceptApplication(ctx.User.Id, userName, out var discordUser))
await ReplyConfirmLocalizedAsync(strs.club_accepted(Format.Bold(discordUser.ToString())));
@@ -253,7 +253,7 @@ public partial class Xp
}
[Cmd]
public async partial Task Clubleave()
public async Task Clubleave()
{
if (_service.LeaveClub(ctx.User))
await ReplyConfirmLocalizedAsync(strs.club_left);
@@ -263,12 +263,12 @@ public partial class Xp
[Cmd]
[Priority(1)]
public partial Task ClubKick([Leftover] IUser user)
public Task ClubKick([Leftover] IUser user)
=> ClubKick(user.ToString());
[Cmd]
[Priority(0)]
public partial Task ClubKick([Leftover] string userName)
public Task ClubKick([Leftover] string userName)
{
if (_service.Kick(ctx.User.Id, userName, out var club))
{
@@ -281,12 +281,12 @@ public partial class Xp
[Cmd]
[Priority(1)]
public partial Task ClubBan([Leftover] IUser user)
public Task ClubBan([Leftover] IUser user)
=> ClubBan(user.ToString());
[Cmd]
[Priority(0)]
public partial Task ClubBan([Leftover] string userName)
public Task ClubBan([Leftover] string userName)
{
if (_service.Ban(ctx.User.Id, userName, out var club))
{
@@ -299,12 +299,12 @@ public partial class Xp
[Cmd]
[Priority(1)]
public partial Task ClubUnBan([Leftover] IUser user)
public Task ClubUnBan([Leftover] IUser user)
=> ClubUnBan(user.ToString());
[Cmd]
[Priority(0)]
public partial Task ClubUnBan([Leftover] string userName)
public Task ClubUnBan([Leftover] string userName)
{
if (_service.UnBan(ctx.User.Id, userName, out var club))
{
@@ -316,7 +316,7 @@ public partial class Xp
}
[Cmd]
public async partial Task ClubDescription([Leftover] string desc = null)
public async Task ClubDescription([Leftover] string desc = null)
{
if (_service.SetDescription(ctx.User.Id, desc))
{
@@ -339,7 +339,7 @@ public partial class Xp
}
[Cmd]
public async partial Task ClubDisband()
public async Task ClubDisband()
{
if (_service.Disband(ctx.User.Id, out var club))
await ReplyConfirmLocalizedAsync(strs.club_disbanded(Format.Bold(club.Name)));
@@ -348,7 +348,7 @@ public partial class Xp
}
[Cmd]
public partial Task ClubLeaderboard(int page = 1)
public Task ClubLeaderboard(int page = 1)
{
if (--page < 0)
return Task.CompletedTask;

View File

@@ -33,7 +33,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task Experience([Leftover] IUser user = null)
public async Task Experience([Leftover] IUser user = null)
{
user ??= ctx.User;
await ctx.Channel.TriggerTypingAsync();
@@ -46,7 +46,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task XpNotify()
public async Task XpNotify()
{
var globalSetting = _service.GetNotificationType(ctx.User);
var serverSetting = _service.GetNotificationType(ctx.User.Id, ctx.Guild.Id);
@@ -61,7 +61,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task XpNotify(NotifyPlace place, XpNotificationLocation type)
public async Task XpNotify(NotifyPlace place, XpNotificationLocation type)
{
if (place == NotifyPlace.Guild)
await _service.ChangeNotificationType(ctx.User.Id, ctx.Guild.Id, type);
@@ -74,7 +74,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public async partial Task XpExclude(Server _)
public async Task XpExclude(Server _)
{
var ex = _service.ToggleExcludeServer(ctx.Guild.Id);
@@ -87,7 +87,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[UserPerm(GuildPerm.ManageRoles)]
[RequireContext(ContextType.Guild)]
public async partial Task XpExclude(Role _, [Leftover] IRole role)
public async Task XpExclude(Role _, [Leftover] IRole role)
{
var ex = _service.ToggleExcludeRole(ctx.Guild.Id, role.Id);
@@ -100,7 +100,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[UserPerm(GuildPerm.ManageChannels)]
[RequireContext(ContextType.Guild)]
public async partial Task XpExclude(Channel _, [Leftover] IChannel channel = null)
public async Task XpExclude(Channel _, [Leftover] IChannel channel = null)
{
if (channel is null)
channel = ctx.Channel;
@@ -115,7 +115,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task XpExclusionList()
public async Task XpExclusionList()
{
var serverExcluded = _service.IsServerExcluded(ctx.Guild.Id);
var roles = _service.GetExcludedRoles(ctx.Guild.Id)
@@ -157,14 +157,14 @@ public partial class Xp : NadekoModule<XpService>
[NadekoOptions(typeof(LbOpts))]
[Priority(0)]
[RequireContext(ContextType.Guild)]
public partial Task XpLeaderboard(params string[] args)
public Task XpLeaderboard(params string[] args)
=> XpLeaderboard(1, args);
[Cmd]
[NadekoOptions(typeof(LbOpts))]
[Priority(1)]
[RequireContext(ContextType.Guild)]
public async partial Task XpLeaderboard(int page = 1, params string[] args)
public async Task XpLeaderboard(int page = 1, params string[] args)
{
if (--page < 0 || page > 100)
return;
@@ -225,7 +225,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
public async partial Task XpGlobalLeaderboard(int page = 1)
public async Task XpGlobalLeaderboard(int page = 1)
{
if (--page < 0 || page > 99)
return;
@@ -251,7 +251,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public async partial Task XpAdd(int amount, ulong userId)
public async Task XpAdd(int amount, ulong userId)
{
if (amount == 0)
return;
@@ -264,13 +264,13 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public partial Task XpAdd(int amount, [Leftover] IGuildUser user)
public Task XpAdd(int amount, [Leftover] IGuildUser user)
=> XpAdd(amount, user.Id);
[Cmd]
[RequireContext(ContextType.Guild)]
[OwnerOnly]
public async partial Task XpTemplateReload()
public async Task XpTemplateReload()
{
_service.ReloadXpTemplate();
await Task.Delay(1000);
@@ -280,13 +280,13 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public partial Task XpReset(IGuildUser user)
public Task XpReset(IGuildUser user)
=> XpReset(user.Id);
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public async partial Task XpReset(ulong userId)
public async Task XpReset(ulong userId)
{
var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_user_confirm));
@@ -301,7 +301,7 @@ public partial class Xp : NadekoModule<XpService>
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public async partial Task XpReset()
public async Task XpReset()
{
var embed = _eb.Create().WithTitle(GetText(strs.reset)).WithDescription(GetText(strs.reset_server_confirm));

View File

@@ -15,7 +15,7 @@ public partial class Xp
[Cmd]
[RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.Administrator)]
public async partial Task XpRewsReset()
public async Task XpRewsReset()
{
var promptEmbed = _eb.Create()
.WithPendingColor()
@@ -32,7 +32,7 @@ public partial class Xp
[Cmd]
[RequireContext(ContextType.Guild)]
public partial Task XpLevelUpRewards(int page = 1)
public Task XpLevelUpRewards(int page = 1)
{
page--;
@@ -92,7 +92,7 @@ public partial class Xp
[BotPerm(GuildPerm.ManageRoles)]
[RequireContext(ContextType.Guild)]
[Priority(2)]
public async partial Task XpRoleReward(int level)
public async Task XpRoleReward(int level)
{
_service.ResetRoleReward(ctx.Guild.Id, level);
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_cleared(level));
@@ -103,7 +103,7 @@ public partial class Xp
[BotPerm(GuildPerm.ManageRoles)]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async partial Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role)
public async Task XpRoleReward(int level, AddRemove action, [Leftover] IRole role)
{
if (level < 1)
return;
@@ -121,7 +121,7 @@ public partial class Xp
[Cmd]
[RequireContext(ContextType.Guild)]
[OwnerOnly]
public async partial Task XpCurrencyReward(int level, int amount = 0)
public async Task XpCurrencyReward(int level, int amount = 0)
{
if (level < 1 || amount < 0)
return;

View File

@@ -653,7 +653,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
{
Guild = channel.Guild,
User = user,
XpAmount = actualXp
XpAmount = actualXp,
});
}
}
@@ -862,24 +862,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
public Task<(Stream Image, IImageFormat Format)> GenerateXpImageAsync(FullUserStats stats)
=> Task.Run(async () =>
{
var usernameTextOptions = new TextGraphicsOptions
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center
}
}.WithFallbackFonts(_fonts.FallBackFonts);
var clubTextOptions = new TextGraphicsOptions
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top
}
}.WithFallbackFonts(_fonts.FallBackFonts);
using var img = Image.Load<Rgba32>(await GetXpBackgroundAsync(stats.User.UserId), out var imageFormat);
if (template.User.Name.Show)
{
@@ -894,11 +876,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
img.Mutate(x =>
{
x.DrawText(usernameTextOptions,
x.DrawText(new TextOptions(usernameFont)
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
FallbackFontFamilies = _fonts.FallBackFonts,
Origin = new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8)
},
"@" + username,
usernameFont,
template.User.Name.Color,
new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8));
template.User.Name.Color);
});
}
@@ -910,11 +896,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
var clubFont = _fonts.NotoSans.CreateFont(template.Club.Name.FontSize, FontStyle.Regular);
img.Mutate(x => x.DrawText(clubTextOptions,
img.Mutate(x => x.DrawText(new TextOptions(clubFont)
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
FallbackFontFamilies = _fonts.FallBackFonts,
Origin = new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8)
},
clubName,
clubFont,
template.Club.Name.Color,
new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8)));
template.Club.Name.Color));
}
Font GetTruncatedFont(
@@ -989,37 +979,29 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
if (template.User.Xp.Global.Show)
{
img.Mutate(x => x.DrawText(
new()
new TextOptions(_fonts.NotoSans.CreateFont(template.User.Xp.Global.FontSize, FontStyle.Bold))
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Origin = new(template.User.Xp.Global.Pos.X, template.User.Xp.Global.Pos.Y),
},
$"{global.LevelXp}/{global.RequiredXp}",
_fonts.NotoSans.CreateFont(template.User.Xp.Global.FontSize, FontStyle.Bold),
Brushes.Solid(template.User.Xp.Global.Color),
pen,
new(template.User.Xp.Global.Pos.X, template.User.Xp.Global.Pos.Y)));
pen));
}
if (template.User.Xp.Guild.Show)
{
img.Mutate(x => x.DrawText(
new()
new TextOptions(_fonts.NotoSans.CreateFont(template.User.Xp.Guild.FontSize, FontStyle.Bold))
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
}
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Origin = new(template.User.Xp.Guild.Pos.X, template.User.Xp.Guild.Pos.Y)
},
$"{guild.LevelXp}/{guild.RequiredXp}",
_fonts.NotoSans.CreateFont(template.User.Xp.Guild.FontSize, FontStyle.Bold),
Brushes.Solid(template.User.Xp.Guild.Color),
pen,
new(template.User.Xp.Guild.Pos.X, template.User.Xp.Guild.Pos.Y)));
pen));
}
if (stats.FullGuildStats.AwardedXp != 0 && template.User.Xp.Awarded.Show)
@@ -1083,14 +1065,14 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
using (var http = _httpFactory.CreateClient())
{
var avatarData = await http.GetByteArrayAsync(avatarUrl);
using (var tempDraw = Image.Load(avatarData))
using (var tempDraw = Image.Load<Rgba32>(avatarData))
{
tempDraw.Mutate(x => x
.Resize(template.User.Icon.Size.X, template.User.Icon.Size.Y)
.ApplyRoundedCorners(Math.Max(template.User.Icon.Size.X,
template.User.Icon.Size.Y)
/ 2.0f));
await using (var stream = tempDraw.ToStream())
await using (var stream = await tempDraw.ToStreamAsync())
{
data = stream.ToArray();
}
@@ -1217,14 +1199,14 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
return;
var imgData = await temp.Content.ReadAsByteArrayAsync();
using (var tempDraw = Image.Load(imgData))
using (var tempDraw = Image.Load<Rgba32>(imgData))
{
tempDraw.Mutate(x => x
.Resize(template.Club.Icon.Size.X, template.Club.Icon.Size.Y)
.ApplyRoundedCorners(Math.Max(template.Club.Icon.Size.X,
template.Club.Icon.Size.Y)
/ 2.0f));
await using (var tds = tempDraw.ToStream())
await using (var tds = await tempDraw.ToStreamAsync())
{
data = tds.ToArray();
}