Skip to content

Commit 7d56d9a

Browse files
committed
feat: 模板支持,没用
1 parent c6fdbf8 commit 7d56d9a

File tree

10 files changed

+59
-7
lines changed

10 files changed

+59
-7
lines changed

apps/qqofbot/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"@clansty/maibot-types": "workspace:^",
2222
"@guiiai/logg": "^1.0.5",
2323
"@types/level-ttl": "^3.1.5",
24+
"@types/markdown-escape": "^1.1.3",
2425
"@types/node": "^22.4.0",
2526
"esbuild": "^0.23.1",
27+
"markdown-escape": "^2.0.0",
2628
"nushell": "^0.98.0",
2729
"qq-official-bot": "^1.0.2",
2830
"tsx": "^4.17.0",

apps/qqofbot/src/adapter/Bot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Bot, BotTypes as BotTypesBase, CallbackQueryEventBase, CommandEventBase
22
import { createLogg } from '@guiiai/logg';
33
import { SendMessageAction } from './MessageAction';
44
import { CommandEvent, KeywordEvent } from './MessageEvent';
5-
import { NoReportError } from '@clansty/maibot-core';
5+
import { MESSAGE_TEMPLATE, NoReportError } from '@clansty/maibot-core';
66
import { Bot as BotClient, GroupMessageEvent, MessageElem, PrivateMessageEvent, TextElem } from 'qq-official-bot';
77

88
export class ChatId {
@@ -14,7 +14,7 @@ export class ChatId {
1414
}
1515
}
1616

17-
export interface BotTypes extends BotTypesBase<ChatId, string, string, never> {
17+
export interface BotTypes extends BotTypesBase<ChatId, string, string, never, MESSAGE_TEMPLATE> {
1818
}
1919

2020
export class BotAdapter extends Bot<BotTypes> {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { MESSAGE_TEMPLATE } from '@clansty/maibot-core';
2+
3+
export default {
4+
[MESSAGE_TEMPLATE.MusicInfo]: '102375493_1729439946',
5+
};

apps/web/wrangler.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ main = ".worker-next/index.mjs"
88
[observability]
99
enabled = true
1010

11-
[[kv_namespaces]]
12-
binding = "NEXT_CACHE_WORKERS_KV"
13-
id = "8d9858ccb8714276803d569b5dc82f24"
11+
#[[kv_namespaces]]
12+
#binding = "NEXT_CACHE_WORKERS_KV"
13+
#id = "8d9858ccb8714276803d569b5dc82f24"
1414

1515
# Automatically place your workloads in an optimal location to minimize latency.
1616
# If you are running back-end logic in a Pages Function, running it closer to your back-end infrastructure
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum MESSAGE_TEMPLATE {
2+
// 文本,图片,文本
3+
MusicInfo,
4+
}

packages/botcore/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { buildBot } from './botBuilder';
22
export { default as NoReportError } from './utils/NoReportError';
3+
export * from './MessageTemplate';

packages/botcore/src/modules/musicSearch.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Song } from '@clansty/maibot-types/src';
33
import LyricsHelper from '../utils/LyricsHelper';
44
import { BotTypes, MessageButtonSwitchInline, MessageButtonUrl, SendMessageAction } from '@clansty/maibot-firm';
55
import { BuilderEnv } from '../botBuilder';
6+
import { MESSAGE_TEMPLATE } from '../MessageTemplate';
67

78
export default <T extends BotTypes>({ bot, env, getContext, musicToFile }: BuilderEnv<T>) => {
89
const genSongInfoButtonsWithCachedLyrics = async (song: Song) => {
@@ -74,7 +75,15 @@ export default <T extends BotTypes>({ bot, env, getContext, musicToFile }: Build
7475
if (musicToFile[song.id]) {
7576
req.addAudio(musicToFile[song.id]);
7677
} else if (song.coverUrl) {
77-
req.addPhoto(song.coverUrl);
78+
const msgTitle = song.display.substring(0, song.display.indexOf('\n'));
79+
const msgText = song.display.substring(song.display.indexOf('\n') + 1);
80+
req
81+
.addPhoto(song.coverUrl)
82+
.setTemplatedMessage(MESSAGE_TEMPLATE.MusicInfo, {
83+
title: msgTitle,
84+
content: msgText,
85+
image: song.coverUrl
86+
});
7887
}
7988
const message = await req.setText(song.display).setButtons(buttons).dispatch();
8089
// 异步获取歌词,只在 undefined 的时候

packages/botfirm/src/Bot.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { CommandEventBase, KeywordEventBase } from './MessageEvent';
33
import { CallbackQueryEventBase } from './CallbackQuery';
44
import { InlineQueryEventBase, InlineQueryResultChosenEventBase } from './InlineQuery';
55

6-
export interface BotTypes<TChatId = unknown, TMessageId = unknown, TSendableFile = unknown, TInlineQueryAnswer = unknown> {
6+
export interface BotTypes<TChatId = unknown, TMessageId = unknown, TSendableFile = unknown, TInlineQueryAnswer = unknown, TMessageTemplateID = unknown> {
77
ChatId: TChatId;
88
MessageId: TMessageId;
99
SendableFile: TSendableFile;
1010
InlineQueryAnswer: TInlineQueryAnswer;
11+
MessageTemplateID: TMessageTemplateID;
1112
}
1213

1314
export abstract class EventBase<T extends BotTypes> {

packages/botfirm/src/MessageAction.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export abstract class SendMessageAction<T extends BotTypes> extends Dispatchable
9393

9494
protected _file: T['SendableFile'] = null;
9595
protected _fileType: 'audio' | 'document' | 'photo' = null;
96+
protected _templatedMessage: TemplatedMessage<T> = null;
9697

9798
public addPhoto(file: T['SendableFile']) {
9899
this._fileType = 'photo';
@@ -112,6 +113,11 @@ export abstract class SendMessageAction<T extends BotTypes> extends Dispatchable
112113
return this;
113114
}
114115

116+
public setTemplatedMessage(template: T['MessageTemplateID'], values: Record<string, string>) {
117+
this._templatedMessage = new TemplatedMessage(template, values);
118+
return this;
119+
}
120+
115121
// 防止 tg 压缩图片,qq 里应该不用理会
116122
public filesAsDocument() {
117123
this._fileType = 'document';
@@ -149,3 +155,11 @@ export class MessageButtonUrl implements MessageButton {
149155
) {
150156
}
151157
}
158+
159+
export class TemplatedMessage<T extends BotTypes> {
160+
constructor(
161+
public readonly template: T['MessageTemplateID'],
162+
public readonly values: Record<string, string>
163+
) {
164+
}
165+
}

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)