Skip to content

Commit

Permalink
feat: status and minecraft modules
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Feb 11, 2024
1 parent d1914be commit f100467
Show file tree
Hide file tree
Showing 20 changed files with 392 additions and 2 deletions.
Binary file modified kotori.db
Binary file not shown.
1 change: 1 addition & 0 deletions modules/bangumi/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bangumi.msg.bgm": "Original name: {0}\nChinese name: {1}\nIntroduction: {2}\nTags: {3}\nDetails: {4}\n{5}",
"bangumi.msg.bgm.list": "{0}.{1}{2}\n",
"bangumi.msg.bgm.fail": "No relevant items found: {0}",
"bangumi.option.bangumi.order": "Order number",
"bangumi.msg.bgmc": "Date: {0}~{1}",
"bangumi.msg.bgmc.list": "\nOriginal name: {0}\nChinese name: {1}\nBroadcast time: {2}\n{3}"
}
1 change: 1 addition & 0 deletions modules/bangumi/locales/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"bangumi.descr.bgmc": "今日放送の番組を取得",
"bangumi.msg.bgm": "原題:{0}\n中国語名:{1}\n紹介:{2}\nタグ:{3}\n詳細:{4}\n{5}",
"bangumi.msg.bgm.list": "{0}.{1}{2}\n",
"bangumi.option.bangumi.order": "番号",
"bangumi.msg.bgm.fail": "関連項目が見つかりませんでした:{0}",
"bangumi.msg.bgmc": "日付:{0}~{1}",
"bangumi.msg.bgmc.list": "\n原題:{0}\n中国語名:{1}\n放送開始時間:{2}\n{3}"
Expand Down
1 change: 1 addition & 0 deletions modules/bangumi/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"bangumi.descr.bgmc": "获取番组计划今日放送",
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介绍:{2}\n标签:{3}\n详情:{4}\n{5}",
"bangumi.msg.bgm.list": "{0}.{1}{2}\n",
"bangumi.option.bangumi.order": "序号",
"bangumi.msg.bgm.fail": "未找到相关条目:{0}",
"bangumi.msg.bgmc": "日期:{0}~{1}",
"bangumi.msg.bgmc.list": "\n原名:{0}\n中文名:{1}\n开播时间:{2}\n{3}"
Expand Down
1 change: 1 addition & 0 deletions modules/bangumi/locales/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介紹:{2}\n標簽:{3}\n詳情:{4}\n{5}",
"bangumi.msg.bgm.list": "{0}.{1}{2}\n",
"bangumi.msg.bgm.fail": "未找到相關條目:{0}",
"bangumi.option.bangumi.order": "番号",
"bangumi.msg.bgmc": "日期:{0}~{1}",
"bangumi.msg.bgmc.list": "\n原名:{0}\n中文名:{1}\n開播時間:{2}\n{3}"
}
13 changes: 13 additions & 0 deletions modules/minecraft/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"minecraft.descr.motd": "MCJE服务器信息查询",
"minecraft.descr.motdbe": "MCBE服务器信息查询",
"minecraft.descr.mcskin": "MC正版账号皮肤查询",
"minecraft.descr.mcv": "查询Minecraft版本信息",
"minecraft.msg.motd": "状态:在线\nIP:{0}\n端口:{1}\n物理地址:{2}\nMOTD:{3}\n协议版本:{4}\n游戏版本:{5}\n在线人数:{6} / {7}\n延迟:{8} ms\n图标:{9}",
"minecraft.msg.motd.fail": "状态:离线\nIP:{0}\n端口:{1}",
"minecraft.msg.motdbe": "状态:在线\nIP:{0}\n端口:{1}\n物理地址:{2}\nMOTD:{3}\n游戏模式:{4}\n协议版本:{5}\n游戏版本:{6}\n在线人数:{7} / {8}\n延迟: {9} ms",
"minecraft.msg.motdbe.fail": "状态:离线\nIP:{0}\n端口:{1}",
"minecraft.msg.mcskin": "玩家:{0}\n皮肤:{1}\n披风:{2}\n头颅:{3}",
"minecraft.msg.mcskin.fail": "{0}查无此人!",
"minecraft.msg.mcv": "MinecraftJava:\n最新版:{0}\n发布时间:{1}\n最新快照:{2}\n发布时间:{3}\nMinecraftBedrock:\n最新版:{4}\n发布时间:{5}"
}
35 changes: 35 additions & 0 deletions modules/minecraft/package1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "kotori-plugin-minecraft",
"version": "1.0.0",
"description": "Plugin Of For Minecraft!",
"main": "lib/index.js",
"scripts": {
"build": "tsc --build"
},
"keywords": [
"kotori",
"chatbot",
"kotori-plugin"
],
"license": "GPL-3.0",
"files": [
"lib",
"locales",
"LICENSE",
"README.md"
],
"author": "Hotaru <[email protected]>",
"peerDependencies": {
"kotori-bot": "workspace:^"
},
"kotori": {
"meta": {
"language": [
"en_US",
"ja_JP",
"zh_TW",
"zh_CN"
]
}
}
}
127 changes: 127 additions & 0 deletions modules/minecraft/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Context, Tsu } from 'kotori-bot';

export const lang = [__dirname, '../locales'];

const motdSchema = Tsu.Union([
Tsu.Object({
data: Tsu.Object({
status: Tsu.Literal('offline')
})
}),
Tsu.Object({
data: Tsu.Object({
status: Tsu.Literal('online'),
ip: Tsu.String(),
real: Tsu.String(),
location: Tsu.String(),
port: Tsu.String(),
motd: Tsu.String(),
version: Tsu.String(),
agreement: Tsu.Number(),
online: Tsu.Number(),
max: Tsu.Number(),
ping: Tsu.Number(),
icon: Tsu.String()
})
})
]);

const motdbeSchema = Tsu.Union([
Tsu.Object({
data: Tsu.Object({
status: Tsu.Literal('offline')
})
}),
Tsu.Object({
data: Tsu.Object({
status: Tsu.Literal('online'),
ip: Tsu.String(),
real: Tsu.String(),
location: Tsu.String(),
port: Tsu.String(),
motd: Tsu.String(),
version: Tsu.String(),
agreement: Tsu.Number(),
online: Tsu.Number(),
max: Tsu.Number(),
delay: Tsu.Number(),
gamemode: Tsu.String()
})
})
]);

export function main(ctx: Context) {
ctx.command('motd <ip:string> [port:number=25565] - minecraft.descr.motd').action(async (data, session) => {
const res = motdSchema.parse(
await ctx.http.get('https://api.hotaru.icu/api/motd', { ip: data.args[0], port: data.args[1] })
);
if (res.data.status !== 'online') return ['minecraft.msg.motd.fail', [data.args[0], data.args[1]]];
const { ip, port, location, motd, agreement, version, online, max, ping } = res.data;
const icon = typeof res.data.icon === 'string' ? session.el.image(`base64://${res.data.icon.substring(22)}`) : '';
return ['minecraft.msg.motd', [ip, port, location, motd, agreement, version, online, max, ping, icon]];
});

ctx.command('motdbe <ip:string> [port:number=19132] - minecraft.descr.motdbe').action(async (data) => {
const res = motdbeSchema.parse(
await ctx.http.get('https://api.hotaru.icu/api/motdpe', { ip: data.args[0], port: data.args[1] })
);
if (res.data.status !== 'online') return ['minecraft.msg.motdbe.fail', [data.args[0], data.args[1]]];
const { ip, port, location, motd, agreement, version, online, max, delay } = res.data;
return ['minecraft.msg.motdbe', [ip, port, location, motd, agreement, version, online, max, delay]];
});

ctx
.command('mcskin')
.action(async (data) => {
const res = await ctx.http.get('https://api.hotaru.icu/api/mcskin', { name: data.args[0] });
if (!isObj(res)) return ['BOT_RESULT.SERVER_ERROR', { res }];
if (res.code === 502 || !isObj(res.data)) return ['minecraft.msg.mcskin.fail', { input: data.args[0] }];

return [
'minecraft.msg.mcskin',
{
input: data.args[0],
skin: image(res.data.skin),
cape: res.data.cape ? image(res.data.cape) : '',
avatar: res.data.avatar ? image(`base64://${res.data.avatar.substring(22)}`) : ''
}
];
})
.help('minecraft.descr.mcskin');

ctx
.command('mcv')
.action(async () => {
const res = await ctx.http.get('https://piston-meta.mojang.com/mc/game/version_manifest.json');
if (!res || !res.latest || !Array.isArray(res.versions)) return 'BOT_RESULT.SERVER_ERROR';
const res2 = await ctx.http.get('https://bugs.mojang.com/rest/api/2/project/10200/versions');
if (!res2 || !Array.isArray(res2)) return 'BOT_RESULT.SERVER_ERROR';
const date = {
releaseDate: '',
snapshotDate: '',
mcbe: '',
mcbeDate: ''
};
let count = 0;
for (const element of res.versions) {
count += 1;
if (count > 100) break;
if (date.releaseDate && date.snapshotDate) break;
if (element.id === res.latest.release) {
date.releaseDate = formatTime(new Date(element.releaseTime));
continue;
}
if (element.id === res.latest.snapshot) date.snapshotDate = formatTime(new Date(element.releaseTime));
}
for (const element of res2) {
if (count > 100) break;
if (!element.releaseDate) continue;
date.mcbe = element.name;
date.mcbeDate = formatTime(new Date(element.releaseDate));
break;
}

return ['minecraft.msg.mcv', { ...res.latest, ...date }];
})
.help('minecraft.descr.mcv');
}
12 changes: 12 additions & 0 deletions modules/minecraft/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
},
"references": [
{
"path": "../../packages/kotori"
}
]
}
23 changes: 23 additions & 0 deletions modules/status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# @kotori-bot/kotori-plugin-status

## Config

```typescript
interface Config {
template?: string;
}
```

### Default

```text
服务器运行状态\n系统内核:%type%\n系统平台:%platform%\nCPU架构:%arch%\nCPU型号:%model%\nCPU频率:%speed%GHz\nCPU核心数:%num%\nCPU使用率:%cpu_rate%%\n内存总量:%total%GB\n可用内存:%used%GB\n内存使用率:%ram_rate%%\n网卡数量:%network%\n开机时间:%time%\n主机名字:%hostname%\n系统目录:%homedir%
```

## Commands

- `/status` View server running status

## Reference

- [Kotori Docs](https://kotori.js.org/)
4 changes: 4 additions & 0 deletions modules/status/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Status.descr.status": "View server running status",
"Status.msg.status": "Server running status \n System kernel:%type%\n System platform:%platform%\n CPU architecture:%arch%\n CPU model:%model%\n CPU frequency:%speed%GHz \n CPU cores:%num%\n CPU usage:%cpu_rate%%\n Total memory:%total%GB \n Free memory:%used%GB \n Memory usage:%ram_rate%%\n Number of network cards:%network%\n Boot time:%time%\n Host name:%host name%\n System directory:%homedir%"
}
4 changes: 4 additions & 0 deletions modules/status/locales/ja_JP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status.descr.status": "サーバーの稼働状態を表示",
"status.msg.status": "サーバ稼働状態\nシステムコア:%type%\nシステムプラットフォーム:%platform%\nCPUアーキテクチャ:%arch%\nCPUモデル:%model%\nCPU周波数:%speed%GHz \nCPUコア数:%num%\nCPU使用率:%cpu_rate%\nメモリ総量:%total%GB \n使用可能内部記憶:%used%GB \nメモリ使用率:%ram_rate%\nネットワークカード数:%network%\n電源投入時間:%time%\nホスト名前:%hostname%\nシステムディレクトリ:%homedir%"
}
4 changes: 4 additions & 0 deletions modules/status/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status.descr.status": "查看服务器运行状态",
"status.msg.status": "服务器运行状态\n系统内核:%type%\n系统平台:%platform%\nCPU架构:%arch%\nCPU型号:%model%\nCPU频率:%speed%GHz\nCPU核心数:%num%\nCPU使用率:%cpu_rate%%\n内存总量:%total%GB\n可用内存:%used%GB\n内存使用率:%ram_rate%%\n网卡数量:%network%\n开机时间:%time%\n主机名字:%hostname%\n系统目录:%homedir%"
}
4 changes: 4 additions & 0 deletions modules/status/locales/zh_TW.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status.descr.status": "查看服務器運行狀態",
"status.msg.status": "服務器運行狀態\n系統內核:%type%\n系統平台:%platform%\nCPU架構:%arch%\nCPU型號:%model%\nCPU頻率:%speed%GHz\nCPU核心數:%num%\nCPU使用率:%cpu_rate%%\n內存總量:%total%GB\n可用內存:%used%GB\n內存使用率:%ram_rate%%\n網卡數量:%network%\n開機時間:%time%\n主機名字:%hostname%\n系統目錄:%homedir%"
}
35 changes: 35 additions & 0 deletions modules/status/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@kotori-bot/kotori-plugin-status",
"version": "1.0.0",
"description": "status plugin",
"main": "lib/index.js",
"scripts": {
"build": "tsc --build"
},
"keywords": [
"kotori",
"chatbot",
"kotori-plugin"
],
"license": "GPL-3.0",
"files": [
"lib",
"locales",
"LICENSE",
"README.md"
],
"author": "Hotaru <[email protected]>",
"peerDependencies": {
"kotori-bot": "workspace:^"
},
"kotori": {
"meta": {
"language": [
"en_US",
"ja_JP",
"zh_TW",
"zh_CN"
]
}
}
}
Loading

0 comments on commit f100467

Please sign in to comment.