Commit c627a968 authored by nanahira's avatar nanahira

half

parent 420d8bd3
Pipeline #6078 failed with stage
in 1 minute and 19 seconds
......@@ -44,7 +44,7 @@ export interface Config {
### 说明
* `adminContext` 一个上下文函数,设置管理员接口作用域。如 `(ctx) => ctx.private('1111111111')` 为只对 QQ 号是 1111111111 的私聊消息有效
* `adminContext` 管理员接口作用域
* `autoChangeName` 公演开始之前是否修改每个演员机器人的群名片。推荐开启。
......@@ -60,4 +60,4 @@ export interface Config {
* `groupId` 目标群。`playbookFilename` 是公演剧本文件,需要在服务器放好。后面的参数可以以 人物名=帐号 的形式指定特定的人物,否则随机分配。
* 例: `act.create 11111111 play1 幽幽子=2222222` 在群 11111111 创建一个公演,剧本是 play1,位于 `/path/to/playbookPathPrefix/play1.json`,同时指定人物幽幽子为 2222222 扮演。
* `.delete <groupId:number>` 停止公演。
\ No newline at end of file
* `.delete <groupId:number>` 停止公演。
This diff is collapsed.
......@@ -3,7 +3,9 @@ import type { Context } from 'koishi-core';
import { Config, MyPlugin } from './plugin';
export { Config } from './plugin';
export const name = 'act-index';
export const name = 'act-index';
const plugin = new MyPlugin();
export const schema = plugin.schema;
export function apply(ctx: Context, config: Config) {
ctx.plugin(new MyPlugin(), config);
ctx.plugin(plugin, config);
}
import { Playbook } from './Playbook';
import type { CQBot } from 'koishi-adapter-onebot';
import type { OneBotBot } from '@koishijs/plugin-onebot';
import moment, { Moment } from 'moment';
export enum ShowStatus {
......@@ -10,7 +10,7 @@ export enum ShowStatus {
export class Show {
status: ShowStatus = ShowStatus.Idle;
private characterBotMap = new Map<number, CQBot>();
private characterBotMap = new Map<number, OneBotBot>();
// eslint-disable-next-line @typescript-eslint/no-empty-function
onFinish: (message: string, show: Show) => void = () => {};
private step = 0;
......@@ -30,7 +30,7 @@ export class Show {
private getPerformingBots() {
return Array.from(this.characterBotMap.values());
}
useCharacter(id: number, bot: CQBot) {
useCharacter(id: number, bot: OneBotBot) {
this.characterBotMap.set(id, bot);
}
isCharacterFull() {
......@@ -38,8 +38,8 @@ export class Show {
this.characterBotMap.has(c.id),
);
}
async autoCharacters(bots: CQBot[]) {
let availableBots: CQBot[] = [];
async autoCharacters(bots: OneBotBot[]) {
let availableBots: OneBotBot[] = [];
const botNameMap = new Map<string, string>();
for (const bot of bots) {
if (!(bot.type && bot.type.startsWith('onebot'))) {
......
import 'source-map-support/register';
import type { Context, Session } from 'koishi-core';
import { Context, Schema, Session } from 'koishi';
import { Show } from './playbook/Show';
import { Playbook } from './playbook/Playbook';
import { plainToClass } from 'class-transformer';
import loadJsonFile from 'load-json-file';
import type { CQBot } from 'koishi-adapter-onebot';
import { MaybeArray } from 'koishi';
const selectors = [
'user',
'guild',
'channel',
'self',
'private',
'platform',
] as const;
type SelectorType = typeof selectors[number];
type SelectorValue = boolean | MaybeArray<string | number>;
type BaseSelection = { [K in SelectorType as `$${K}`]?: SelectorValue };
export interface Selection extends BaseSelection {
$and?: Selection[];
$or?: Selection[];
$not?: Selection;
}
export interface Config {
adminContext: (ctx: Context) => Context;
adminContext: Selection;
autoChangeName: boolean;
dropHelp: boolean;
playbookPathPrefix: string;
......@@ -20,20 +39,25 @@ export class MyPlugin {
shows = new Map<number, Show>();
name = 'act';
schema: Schema<Config> = Schema.object({
adminContext: Schema.any('管理员接口作用域。'),
autoChangeName: Schema.boolean(
'公演开始之前是否修改每个演员机器人的群名片。推荐开启。',
).default(true),
playbookPathPrefix: Schema.string(
'公演剧本存放路径。公演剧本的文件名是 `/path/to/playbookPathPrefix/name.json` 对应于 name 剧本。',
).default('./playbooks'),
dropHelp: Schema.boolean('是否删除 `help` 命令,避免社死 (?)').default(
false,
),
});
apply(ctx: Context, config: Config) {
this.ctx = ctx;
this.config = {
adminContext: (ctx) => ctx.private(),
autoChangeName: false,
dropHelp: false,
playbookPathPrefix: './playbooks',
...config,
};
this.config = Schema.validate(config, this.schema);
if (this.config.dropHelp) {
ctx.command('help').dispose();
}
this.adminCtx = this.config.adminContext(ctx);
this.adminCtx = this.ctx.select(this.config.adminContext);
const showComamnd = this.adminCtx
.command('act [groupId:number]', '获取公演状态')
.usage('不带参数获取所有正在公演的群,带参数则获取特定群。')
......@@ -110,9 +134,9 @@ export class MyPlugin {
} catch (e) {
return `无法加载剧本文件 ${playbookPath}: ${e.toString()}`;
}
const bots: CQBot[] = (this.ctx.bots.filter(
const bots: OneBotBot[] = this.ctx.bots.filter(
(b) => b.type && b.type.startsWith('onebot'),
) as unknown) as CQBot[];
) as OneBotBot[];
const show = new Show(groupId, playbook, this.config.autoChangeName);
for (const specificCharacter of specificCharacters) {
const [characterName, botId] = specificCharacter.split('=');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment