Commit a0c30ed4 authored by nanahira's avatar nanahira

better type

parent 53f5352c
...@@ -107,15 +107,15 @@ app.command('dish').action(async (argv) => { ...@@ -107,15 +107,15 @@ app.command('dish').action(async (argv) => {
card_type: 'multiple_interaction', card_type: 'multiple_interaction',
}, },
[ [
segment('mainTitle', { segment('main_title', {
title: '晚上想吃什么?', title: '晚上想吃什么?',
desc: '有很多好吃的呢!', desc: '有很多好吃的呢!',
}), }),
segment('selectList', {}, [ segment('select_list', {}, [
segment( segment(
'', '',
{ {
questionKey: 'main', question_key: 'main',
title: '主食', title: '主食',
}, },
[ [
...@@ -126,7 +126,7 @@ app.command('dish').action(async (argv) => { ...@@ -126,7 +126,7 @@ app.command('dish').action(async (argv) => {
segment( segment(
'', '',
{ {
questionKey: 'meat', question_key: 'meat',
title: '肉类', title: '肉类',
}, },
[ [
...@@ -138,11 +138,11 @@ app.command('dish').action(async (argv) => { ...@@ -138,11 +138,11 @@ app.command('dish').action(async (argv) => {
segment( segment(
'', '',
{ {
questionKey: 'soup', question_key: 'soup',
title: '', title: '',
}, },
[ [
segment('optionList', {}, [ segment('option_list', {}, [
segment('', { id: 'tomato', text: '番茄汤' }), segment('', { id: 'tomato', text: '番茄汤' }),
segment('', { id: 'mushroom', text: '蘑菇汤' }), segment('', { id: 'mushroom', text: '蘑菇汤' }),
segment('', { id: 'fish', text: '鱼汤' }), segment('', { id: 'fish', text: '鱼汤' }),
...@@ -150,7 +150,7 @@ app.command('dish').action(async (argv) => { ...@@ -150,7 +150,7 @@ app.command('dish').action(async (argv) => {
], ],
), ),
]), ]),
segment('submitButton', { segment('submit_button', {
text: '点菜!', text: '点菜!',
key: 'submit', key: 'submit',
}), }),
...@@ -170,7 +170,7 @@ app.command('dish').action(async (argv) => { ...@@ -170,7 +170,7 @@ app.command('dish').action(async (argv) => {
}); });
app.on('bot-status-updated', (bot) => { app.on('bot-status-updated', (bot) => {
console.log(`Bot ${bot.selfId} status updated: ${bot.status}`); console.log(`Bot ${bot.sid} status updated: ${bot.status}`);
}); });
app.start(); app.start();
import { WecomEventBody } from './def'; import { WecomEventBody } from './def';
import { Session } from 'koishi'; import { Session } from 'koishi';
import { ChangeContact } from './specific/ChangeContact';
import { ApprovalInfo } from './specific/ApprovalInfo';
type MayBeArray<T> = T | T[]; type MayBeArray<T> = T | T[];
...@@ -52,3 +54,56 @@ export interface CardEvent extends CardMenuEvent { ...@@ -52,3 +54,56 @@ export interface CardEvent extends CardMenuEvent {
export type WecomEventFunction<T = {}> = ( export type WecomEventFunction<T = {}> = (
session: Session & { wecom: WecomEventBody & T }, session: Session & { wecom: WecomEventBody & T },
) => void; ) => void;
export interface WecomInternalEvents {
enter_agent: {};
subscribe: {};
unsubscribe: {};
LOCATION: {
Latitude: number;
Longitude: number;
Precision: number;
};
batch_job_result: {
BatchJob: {
JobId: string;
JobType: string;
ErrCode: number;
ErrMsg: string;
};
};
click: EventKeyBody;
view: EventKeyBody;
scancode_push: ScanCodeEventBody;
scancode_waitmsg: ScanCodeEventBody;
pic_sysphoto: PhotoEventBody;
pic_photo_or_album: PhotoEventBody;
pic_weixin: PhotoEventBody;
location_select: EventKeyBody & {
SendLocationInfo: {
Location_X: number;
Location_Y: number;
Scale: number;
Label: string;
Poiname: string;
};
};
share_agent_change: {};
share_chain_change: {};
template_card_event: CardEvent & {
SelectedItems: CardEventSelectedItems;
};
template_card_menu_event: CardEvent;
open_approval_change: {
ApprovalInfo: ApprovalInfo;
};
change_contact: ChangeContact;
}
export type WecomEvents = {
[K in keyof WecomInternalEvents as `wecom/${K}`]: WecomEventFunction<
WecomInternalEvents[K]
>;
};
...@@ -11,25 +11,16 @@ import { ...@@ -11,25 +11,16 @@ import {
} from 'koishi'; } from 'koishi';
import { import {
adaptMenu, adaptMenu,
ApprovalInfo,
CardEvent,
CardEventSelectedItems,
ChangeContact,
EventKeyBody,
PhotoEventBody,
ScanCodeEventBody,
TokenReturnMessage, TokenReturnMessage,
WeComAgentInfo, WeComAgentInfo,
WecomEventBody, WecomEventBody,
WecomEventFunction, WecomEvents,
WecomMenuDef, WecomMenuDef,
WecomSendMessageResponse, WecomSendMessageResponse,
WeComUser, WeComUser,
} from './def'; } from './def';
import { import {
Apply,
DefinePlugin, DefinePlugin,
DefineSchema,
Inject, Inject,
InjectLogger, InjectLogger,
PluginDef, PluginDef,
...@@ -50,57 +41,14 @@ declare global { ...@@ -50,57 +41,14 @@ declare global {
interface Session { interface Session {
wecom?: WecomEventBody; wecom?: WecomEventBody;
} }
interface Events {
'wecom/enter_agent': WecomEventFunction;
'wecom/subscribe': WecomEventFunction;
'wecom/unsubscribe': WecomEventFunction;
'wecom/LOCATION': WecomEventFunction<{
Latitude: number;
Longitude: number;
Precision: number;
}>;
'wecom/batch_job_result': WecomEventFunction<{
BatchJob: {
JobId: string;
JobType: string;
ErrCode: number;
ErrMsg: string;
};
}>;
'wecom/click': WecomEventFunction<EventKeyBody>;
'wecom/view': WecomEventFunction<EventKeyBody>;
'wecom/scancode_push': WecomEventFunction<ScanCodeEventBody>;
'wecom/scancode_waitmsg': WecomEventFunction<ScanCodeEventBody>;
'wecom/pic_sysphoto': WecomEventFunction<PhotoEventBody>;
'wecom/pic_photo_or_album': WecomEventFunction<PhotoEventBody>;
'wecom/pic_weixin': WecomEventFunction<PhotoEventBody>;
'wecom/location_select': WecomEventFunction<
EventKeyBody & {
SendLocationInfo: {
Location_X: number;
Location_Y: number;
Scale: number;
Label: string;
Poiname: string;
};
}
>;
'wecom/share_agent_change': WecomEventFunction;
'wecom/share_chain_change': WecomEventFunction;
'wecom/template_card_event': WecomEventFunction<
CardEvent & {
SelectedItems: CardEventSelectedItems;
}
>;
'wecom/template_card_menu_event': WecomEventFunction<CardEvent>;
'wecom/open_approval_change': WecomEventFunction<{
ApprovalInfo: ApprovalInfo;
}>;
'wecom/change_contact': WecomEventFunction<ChangeContact>;
}
} }
} }
declare module 'koishi' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Events extends WecomEvents {}
}
@RegisterSchema() @RegisterSchema()
export class WeComBotConfig { export class WeComBotConfig {
@SchemaProperty({ @SchemaProperty({
......
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