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