Commit 0feb8753 authored by nanahira's avatar nanahira

migrate

parent c627a968
{ {
"name": "koishi-plugin-act", "name": "koishi-plugin-act",
"version": "1.0.3", "version": "2.0.0",
"description": "A plugin playing acts in QQ groups", "description": "A plugin playing acts in QQ groups",
"main": "dist/index.js", "main": "dist/index.js",
"dependencies": { "dependencies": {
......
import 'source-map-support/register'; import 'source-map-support/register';
import type { Context } from 'koishi-core'; import type { Context } from 'koishi';
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';
const plugin = new MyPlugin(); const plugin = new MyPlugin();
export const schema = plugin.schema; export const schema = plugin.schema;
export function apply(ctx: Context, config: Config) { export function apply(ctx: Context, config: Config) {
......
import { Playbook } from './Playbook'; import { Playbook } from './Playbook';
import type { OneBotBot } from '@koishijs/plugin-onebot'; import type { OneBotBot } from '@koishijs/plugin-onebot/lib/bot';
import moment, { Moment } from 'moment'; import moment, { Moment } from 'moment';
export enum ShowStatus { export enum ShowStatus {
...@@ -23,7 +23,7 @@ export class Show { ...@@ -23,7 +23,7 @@ export class Show {
for (const character of playbook.characters) { for (const character of playbook.characters) {
character.playFun = async (line, text) => { character.playFun = async (line, text) => {
const bot = this.characterBotMap.get(character.id); const bot = this.characterBotMap.get(character.id);
await bot.$sendGroupMsg(this.groupId, text, true); await bot.internal.sendGroupMsg(this.groupId, text, true);
}; };
} }
} }
...@@ -42,16 +42,17 @@ export class Show { ...@@ -42,16 +42,17 @@ export class Show {
let availableBots: OneBotBot[] = []; 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.adapter.platform !== 'onebot') {
continue; continue;
} }
const groups = await bot.$getGroupList(); const groups = await bot.internal.getGroupList();
const matchGroup = groups.find((g) => g.groupId === this.groupId); const matchGroup = groups.find((g) => g.group_id === this.groupId);
if (matchGroup) { if (matchGroup) {
availableBots.push(bot); availableBots.push(bot);
botNameMap.set( botNameMap.set(
bot.selfId.toString(), bot.selfId.toString(),
(await bot.$getGroupMemberInfo(this.groupId, bot.selfId)).nickname, (await bot.internal.getGroupMemberInfo(this.groupId, bot.selfId))
.nickname,
); );
} }
} }
...@@ -109,7 +110,11 @@ export class Show { ...@@ -109,7 +110,11 @@ export class Show {
for (const character of this.playbook.characters) { for (const character of this.playbook.characters) {
const bot = this.characterBotMap.get(character.id); const bot = this.characterBotMap.get(character.id);
try { try {
await bot.$setGroupCard(this.groupId, bot.selfId, character.name); await bot.internal.setGroupCard(
this.groupId,
bot.selfId,
character.name,
);
} catch (e) { } catch (e) {
return `Change name for ${bot.selfId} ${ return `Change name for ${bot.selfId} ${
character.name character.name
......
...@@ -5,6 +5,7 @@ import { Playbook } from './playbook/Playbook'; ...@@ -5,6 +5,7 @@ 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 { MaybeArray } from 'koishi'; import { MaybeArray } from 'koishi';
import type { OneBotBot } from '@koishijs/plugin-onebot/lib/bot';
const selectors = [ const selectors = [
'user', 'user',
...@@ -38,7 +39,7 @@ export class MyPlugin { ...@@ -38,7 +39,7 @@ export class MyPlugin {
adminCtx: Context; adminCtx: Context;
shows = new Map<number, Show>(); shows = new Map<number, Show>();
name = 'act'; name = 'act-main';
schema: Schema<Config> = Schema.object({ schema: Schema<Config> = Schema.object({
adminContext: Schema.any('管理员接口作用域。'), adminContext: Schema.any('管理员接口作用域。'),
autoChangeName: Schema.boolean( autoChangeName: Schema.boolean(
...@@ -135,7 +136,7 @@ export class MyPlugin { ...@@ -135,7 +136,7 @@ export class MyPlugin {
return `无法加载剧本文件 ${playbookPath}: ${e.toString()}`; return `无法加载剧本文件 ${playbookPath}: ${e.toString()}`;
} }
const bots: OneBotBot[] = this.ctx.bots.filter( const bots: OneBotBot[] = this.ctx.bots.filter(
(b) => b.type && b.type.startsWith('onebot'), (b) => b.adapter.platform === 'onebot',
) as OneBotBot[]; ) 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) {
......
...@@ -25,4 +25,8 @@ module.exports = { ...@@ -25,4 +25,8 @@ module.exports = {
}, },
path: path.resolve(__dirname, "dist"), path: path.resolve(__dirname, "dist"),
}, },
externals: {
'koishi': 'koishi',
'@koishijs/plugin-onebot/lib/bot': '@koishijs/plugin-onebot/lib/bot',
}
}; };
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