diff --git a/package.json b/package.json index a9429c1..cb93fb7 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,28 @@ { "name": "koishi-plugin-minecraft-vc-rcon", - "description": "", - "version": "0.0.1", + "description": "velocity和lls_manager的自助白名单添加", + "version": "1.0.0", + "contributors": [ + "SharwOrange " + ], + "homepage": "https://example.com", "main": "lib/index.js", "typings": "lib/index.d.ts", "files": [ "lib", "dist" ], - "license": "MIT", + "license": "MPL-2.0", "scripts": {}, "keywords": [ "chatbot", "koishi", "plugin" ], - "devDependencies": {}, "peerDependencies": { "koishi": "^4.17.9" + }, + "dependencies": { + "rcon-client": "^4.2.4" } } diff --git a/src/index.ts b/src/index.ts index 554fc4b..9de960d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,63 @@ -import { Context, Schema } from 'koishi' +import { Context, Schema} from 'koishi' +import { Rcon } from "rcon-client" export const name = 'minecraft-vc-rcon' -export interface Config {} - -export const Config: Schema = Schema.object({}) - -export function apply(ctx: Context) { - // write your plugin here +export interface Config { + host:string + port:number + password:string +} + +export const Config: Schema = Schema.object({ + host: Schema.string() + .description("服务器IP") + .default("127.0.0.1"), + port: Schema.number() + .description("Rcon端口") + .default(25575), + password: Schema.string() + .description("Rcon密码") +}) + +export async function apply(ctx: Context,config:Config) { + + const rcon = new Rcon({ + host: config.host, + port: config.port, + password: config.password, + }) + + async function whitelist_add(playername:string) { + try{ + await rcon.connect() + await rcon.send(`lls_create_player ${playername}`) + await rcon.send(`lls_whitelist add ${playername} Login`) + await rcon.send(`lls_whitelist add ${playername} Survival`) + await rcon.send(`lls_whitelist add ${playername} Creative`) + await rcon.send(`lls_whitelist add ${playername} Mod-120`) + await rcon.end() + return true + }catch(e){ + console.error(e) + return false + } + } + + ctx.on('message', (session) => { + if (session.content === '天王盖地虎') { + session.send('宝塔镇河妖') + } + }) + + ctx.command('whitelist ', {checkArgCount: true}) + .action(async ({ session }, playername) => { + let back = whitelist_add(playername) + if(await back){ + session.send(`成功为 ${playername} 添加了白名单`) + }else{ + session.send('白名单添加失败,请查看日志') + } + }) + .usage('自助白名单添加,请将playername替换为你的游戏ID') }