diff --git a/.github/workflows/build-and-package.yml b/.github/workflows/build-and-package.yml index 4a4ffff..fe0c3b0 100644 --- a/.github/workflows/build-and-package.yml +++ b/.github/workflows/build-and-package.yml @@ -24,6 +24,9 @@ jobs: - name: Copy images run: cp -r PrismBot/images ${{ matrix.arch }}/images + + - name: Copy fonts + run: cp -r PrismBot/fonts ${{ matrix.arch }}/fonts - name: Upload Artifact uses: actions/upload-artifact@v2 diff --git a/PrismBot.SDK/Models/BossProgress.cs b/PrismBot.SDK/Models/BossProgress.cs new file mode 100644 index 0000000..78b582b --- /dev/null +++ b/PrismBot.SDK/Models/BossProgress.cs @@ -0,0 +1,77 @@ +namespace PrismBot.SDK.Models; +using System.Text.Json.Serialization; + +public class BossProgress +{ + [JsonPropertyName("status")] + public string Status { get; set; } + + [JsonPropertyName("response")] + public BossStatus Response { get; set; } +} + +public class BossStatus +{ + [JsonPropertyName("King Slime")] + public bool KingSlime { get; set; } + + [JsonPropertyName("Eye of Cthulhu")] + public bool EyeOfCthulhu { get; set; } + + [JsonPropertyName("Eater of Worlds / Brain of Cthulhu")] + public bool EaterOfWorldsOrBrainOfCthulhu { get; set; } + + [JsonPropertyName("Queen Bee")] + public bool QueenBee { get; set; } + + [JsonPropertyName("Skeletron")] + public bool Skeletron { get; set; } + + [JsonPropertyName("Deerclops")] + public bool Deerclops { get; set; } + + [JsonPropertyName("Wall of Flesh")] + public bool WallOfFlesh { get; set; } + + [JsonPropertyName("Queen Slime")] + public bool QueenSlime { get; set; } + + [JsonPropertyName("The Twins")] + public bool TheTwins { get; set; } + + [JsonPropertyName("The Destroyer")] + public bool TheDestroyer { get; set; } + + [JsonPropertyName("Skeletron Prime")] + public bool SkeletronPrime { get; set; } + + [JsonPropertyName("Plantera")] + public bool Plantera { get; set; } + + [JsonPropertyName("Golem")] + public bool Golem { get; set; } + + [JsonPropertyName("Duke Fishron")] + public bool DukeFishron { get; set; } + + [JsonPropertyName("Empress of Light")] + public bool EmpressOfLight { get; set; } + + [JsonPropertyName("Lunatic Cultist")] + public bool LunaticCultist { get; set; } + + [JsonPropertyName("Moon Lord")] + public bool MoonLord { get; set; } + + [JsonPropertyName("Solar Pillar")] + public bool SolarPillar { get; set; } + + [JsonPropertyName("Nebula Pillar")] + public bool NebulaPillar { get; set; } + + [JsonPropertyName("Vortex Pillar")] + public bool VortexPillar { get; set; } + + [JsonPropertyName("Stardust Pillar")] + public bool StardustPillar { get; set; } +} diff --git a/PrismBot.SDK/Models/Server.cs b/PrismBot.SDK/Models/Server.cs index ecab8d0..80eb596 100644 --- a/PrismBot.SDK/Models/Server.cs +++ b/PrismBot.SDK/Models/Server.cs @@ -132,4 +132,12 @@ public async Task GetPlayerInfoAsync(Player player) {"player", player.UserName} }); } + + public async Task GetServerProgressAsync() + { + return await SendGetToEndpointAsync("prismbot/progress", new Dictionary + { + {"token", Token} + }); + } } \ No newline at end of file diff --git a/PrismBot/InternalPlugins/ServerStatus/GroupCommands/Progress.cs b/PrismBot/InternalPlugins/ServerStatus/GroupCommands/Progress.cs new file mode 100644 index 0000000..dac3f55 --- /dev/null +++ b/PrismBot/InternalPlugins/ServerStatus/GroupCommands/Progress.cs @@ -0,0 +1,104 @@ +using System.Reflection; +using PrismBot.SDK.Data; +using PrismBot.SDK.Extensions; +using PrismBot.SDK.Interfaces; +using PrismBot.SDK.Models; +using SixLabors.Fonts; +using SixLabors.ImageSharp.Drawing.Processing; +using Sora.Entities; +using Sora.Entities.Segment; +using Sora.EventArgs.SoraEvent; + +namespace PrismBot.InternalPlugins.ServerStatus.GroupCommands; + +public class Progress : IGroupCommand +{ + public string GetCommand() + { + return "进度"; + } + + public string GetPermission() + { + return "ss.progress"; + } + + public async Task OnPermissionDeniedAsync(string type, GroupMessageEventArgs eventArgs) + { + await eventArgs.SendDefaultPermissionDeniedMessageAsync(); + } + + public async Task OnPermissionGrantedAsync(string type, GroupMessageEventArgs eventArgs) + { + var args = eventArgs.Message.GetCommandArgs(); + if (args.Length != 2) + { + await eventArgs.SourceGroup.SendGroupMessage("您输入的参数不符合要求。请参考以下语法进行输入:进度 <服务器标识符>"); + return; + } + var db = new BotDbContext(); + + var server = await db.Servers.FindAsync(args[1]); + if (server == null) + { + await eventArgs.SourceGroup.SendGroupMessage("不存在该服务器。"); + return; + } + + var bossProgress = await server.GetServerProgressAsync(); + var bossStatus = bossProgress.Response; + var backgroundImage = + await Image.LoadAsync(Path.Combine(AppContext.BaseDirectory, "images", "progress_bg.png")); + var x = 260; + var y = 460; + var count = 0; + + // 定义你的字体文件的路径 + var fontPath = Path.Combine(AppContext.BaseDirectory, "fonts", "Alibaba-PuHuiTi-Medium.otf"); + + // 加载字体 + var fontCollection = new FontCollection(); + var fontFamily = fontCollection.Add(fontPath); + var font = fontFamily.CreateFont(32, FontStyle.Regular); + + foreach (var value in GetBossStatusValues(bossStatus)) + { + backgroundImage.Mutate(image => image.DrawText(value ? "已 击 败" : "未 击 败", + font, value ? Color.Red : Color.Black, new PointF(x, y))); + x += 265; + if (x > 1670 && count == 0) + { + x = 260; + y += 270; + count ++; + } + else if (x > 1670 && count != 0) + { + x = 260; + y += 210; + } + } + + await backgroundImage.SaveAsync(Path.Combine(AppContext.BaseDirectory, "imageCache", "progress.png")); + await eventArgs.SourceGroup.SendGroupMessage(SoraSegment.Image(Path.Combine(AppContext.BaseDirectory, + "imageCache", "progress.png"))); + } + + public List GetBossStatusValues(BossStatus bossStatus) + { + List values = new List(); + + PropertyInfo[] properties = typeof(BossStatus).GetProperties(); + + foreach (PropertyInfo property in properties) + { + if (property.PropertyType == typeof(bool)) + { + bool value = (bool)property.GetValue(bossStatus); + values.Add(value); + } + } + + return values; + } +} \ No newline at end of file diff --git a/PrismBot/InternalPlugins/ServerStatus/ServerStatus.cs b/PrismBot/InternalPlugins/ServerStatus/ServerStatus.cs index a4f7325..7d08f3c 100644 --- a/PrismBot/InternalPlugins/ServerStatus/ServerStatus.cs +++ b/PrismBot/InternalPlugins/ServerStatus/ServerStatus.cs @@ -1,5 +1,6 @@ using PrismBot.InternalPlugins.ServerStatus.GroupCommands; using PrismBot.SDK; +using PrismBot.SDK.Models; using PrismBot.SDK.Static; using YukariToolBox.LightLog; @@ -9,7 +10,7 @@ public class ServerStatus : Plugin { public override string GetPluginName() { - return "OnlinePlayerFinder"; + return "ServerStatus"; } public override string GetVersion() @@ -41,5 +42,6 @@ public override void OnLoad() CommandManager.RegisterGroupCommand(this, new OnlinePlayer()); CommandManager.RegisterGroupCommand(this, new MyBag()); CommandManager.RegisterGroupCommand(this, new UserBag()); + CommandManager.RegisterGroupCommand(this, new Progress()); } } \ No newline at end of file diff --git a/PrismBot/PrismBot.csproj b/PrismBot/PrismBot.csproj index d39d8f9..ceacaa3 100644 --- a/PrismBot/PrismBot.csproj +++ b/PrismBot/PrismBot.csproj @@ -17,7 +17,7 @@ - + diff --git a/PrismBot/fonts/Alibaba-PuHuiTi-Medium.otf b/PrismBot/fonts/Alibaba-PuHuiTi-Medium.otf new file mode 100755 index 0000000..a308250 Binary files /dev/null and b/PrismBot/fonts/Alibaba-PuHuiTi-Medium.otf differ diff --git a/PrismBot/images/progress_bg.png b/PrismBot/images/progress_bg.png new file mode 100644 index 0000000..a6e1347 Binary files /dev/null and b/PrismBot/images/progress_bg.png differ