Skip to content

Commit

Permalink
新增进度
Browse files Browse the repository at this point in the history
  • Loading branch information
Qianyiovo committed Jul 12, 2023
1 parent 12f6539 commit 81b102c
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-and-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions PrismBot.SDK/Models/BossProgress.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
8 changes: 8 additions & 0 deletions PrismBot.SDK/Models/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,12 @@ public async Task<PlayerInfo> GetPlayerInfoAsync(Player player)
{"player", player.UserName}
});
}

public async Task<BossProgress> GetServerProgressAsync()
{
return await SendGetToEndpointAsync<BossProgress>("prismbot/progress", new Dictionary<string, object>
{
{"token", Token}
});
}
}
104 changes: 104 additions & 0 deletions PrismBot/InternalPlugins/ServerStatus/GroupCommands/Progress.cs
Original file line number Diff line number Diff line change
@@ -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<bool> GetBossStatusValues(BossStatus bossStatus)
{
List<bool> values = new List<bool>();

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;
}
}
4 changes: 3 additions & 1 deletion PrismBot/InternalPlugins/ServerStatus/ServerStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PrismBot.InternalPlugins.ServerStatus.GroupCommands;
using PrismBot.SDK;
using PrismBot.SDK.Models;
using PrismBot.SDK.Static;
using YukariToolBox.LightLog;

Expand All @@ -9,7 +10,7 @@ public class ServerStatus : Plugin
{
public override string GetPluginName()
{
return "OnlinePlayerFinder";
return "ServerStatus";
}

public override string GetVersion()
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion PrismBot/PrismBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
<PackageReference Include="Sora" Version="1.3.0" />
<PackageReference Include="Spectre.Console" Version="0.46.1-preview.0.2" />
Expand Down
Binary file added PrismBot/fonts/Alibaba-PuHuiTi-Medium.otf
Binary file not shown.
Binary file added PrismBot/images/progress_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 81b102c

Please sign in to comment.