@fedify/botkit 0.3.0-dev.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +75 -0
- package/dist/bot-impl.d.ts +111 -0
- package/dist/bot-impl.d.ts.map +1 -0
- package/dist/bot-impl.js +602 -0
- package/dist/bot-impl.js.map +1 -0
- package/dist/bot-impl.test.d.ts +2 -0
- package/dist/bot-impl.test.js +1642 -0
- package/dist/bot-impl.test.js.map +1 -0
- package/dist/bot.d.ts +270 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +118 -0
- package/dist/bot.js.map +1 -0
- package/dist/bot.test.d.ts +2 -0
- package/dist/bot.test.js +80 -0
- package/dist/bot.test.js.map +1 -0
- package/dist/components/Layout.d.ts +26 -0
- package/dist/components/Layout.d.ts.map +1 -0
- package/dist/components/Layout.js +36 -0
- package/dist/components/Layout.js.map +1 -0
- package/dist/components/Message.d.ts +21 -0
- package/dist/components/Message.d.ts.map +1 -0
- package/dist/components/Message.js +99 -0
- package/dist/components/Message.js.map +1 -0
- package/dist/components/Message.test.d.ts +2 -0
- package/dist/components/Message.test.js +32 -0
- package/dist/components/Message.test.js.map +1 -0
- package/dist/deno.js +73 -0
- package/dist/deno.js.map +1 -0
- package/dist/emoji.d.ts +87 -0
- package/dist/emoji.d.ts.map +1 -0
- package/dist/emoji.js +37 -0
- package/dist/emoji.js.map +1 -0
- package/dist/emoji.test.d.ts +2 -0
- package/dist/emoji.test.js +109 -0
- package/dist/emoji.test.js.map +1 -0
- package/dist/events.d.ts +110 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +4 -0
- package/dist/follow-impl.d.ts +23 -0
- package/dist/follow-impl.d.ts.map +1 -0
- package/dist/follow-impl.js +51 -0
- package/dist/follow-impl.js.map +1 -0
- package/dist/follow-impl.test.d.ts +2 -0
- package/dist/follow-impl.test.js +110 -0
- package/dist/follow-impl.test.js.map +1 -0
- package/dist/follow.d.ts +44 -0
- package/dist/follow.d.ts.map +1 -0
- package/dist/follow.js +4 -0
- package/dist/message-impl.d.ts +54 -0
- package/dist/message-impl.d.ts.map +1 -0
- package/dist/message-impl.js +439 -0
- package/dist/message-impl.js.map +1 -0
- package/dist/message-impl.test.d.ts +2 -0
- package/dist/message-impl.test.js +519 -0
- package/dist/message-impl.test.js.map +1 -0
- package/dist/message.d.ts +223 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +8 -0
- package/dist/mod.d.ts +13 -0
- package/dist/mod.js +13 -0
- package/dist/pages.d.ts +20 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +361 -0
- package/dist/pages.js.map +1 -0
- package/dist/reaction.d.ts +90 -0
- package/dist/reaction.d.ts.map +1 -0
- package/dist/reaction.js +7 -0
- package/dist/repository.d.ts +323 -0
- package/dist/repository.d.ts.map +1 -0
- package/dist/repository.js +483 -0
- package/dist/repository.js.map +1 -0
- package/dist/repository.test.d.ts +2 -0
- package/dist/repository.test.js +336 -0
- package/dist/repository.test.js.map +1 -0
- package/dist/session-impl.d.ts +32 -0
- package/dist/session-impl.d.ts.map +1 -0
- package/dist/session-impl.js +195 -0
- package/dist/session-impl.js.map +1 -0
- package/dist/session-impl.test.d.ts +20 -0
- package/dist/session-impl.test.d.ts.map +1 -0
- package/dist/session-impl.test.js +464 -0
- package/dist/session-impl.test.js.map +1 -0
- package/dist/session.d.ts +139 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +4 -0
- package/dist/text.d.ts +391 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +640 -0
- package/dist/text.js.map +1 -0
- package/dist/text.test.d.ts +2 -0
- package/dist/text.test.js +473 -0
- package/dist/text.test.js.map +1 -0
- package/package.json +137 -0
package/dist/bot.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
import { BotImpl } from "./bot-impl.js";
|
|
6
|
+
import { Application, Image, Service } from "@fedify/fedify/vocab";
|
|
7
|
+
import { parseSemVer } from "@fedify/fedify/nodeinfo";
|
|
8
|
+
|
|
9
|
+
//#region src/bot.ts
|
|
10
|
+
/**
|
|
11
|
+
* Creates a {@link Bot} instance.
|
|
12
|
+
* @param options The options for creating the bot.
|
|
13
|
+
* @returns The created bot instance.
|
|
14
|
+
*/
|
|
15
|
+
function createBot(options) {
|
|
16
|
+
const bot = new BotImpl(options);
|
|
17
|
+
const wrapper = {
|
|
18
|
+
impl: bot,
|
|
19
|
+
get federation() {
|
|
20
|
+
return bot.federation;
|
|
21
|
+
},
|
|
22
|
+
get identifier() {
|
|
23
|
+
return bot.identifier;
|
|
24
|
+
},
|
|
25
|
+
getSession(a, b) {
|
|
26
|
+
return bot.getSession(a, b);
|
|
27
|
+
},
|
|
28
|
+
fetch(request, contextData) {
|
|
29
|
+
return bot.fetch(request, contextData);
|
|
30
|
+
},
|
|
31
|
+
addCustomEmojis(emojis) {
|
|
32
|
+
return bot.addCustomEmojis(emojis);
|
|
33
|
+
},
|
|
34
|
+
get onFollow() {
|
|
35
|
+
return bot.onFollow;
|
|
36
|
+
},
|
|
37
|
+
set onFollow(value) {
|
|
38
|
+
bot.onFollow = value;
|
|
39
|
+
},
|
|
40
|
+
get onUnfollow() {
|
|
41
|
+
return bot.onUnfollow;
|
|
42
|
+
},
|
|
43
|
+
set onUnfollow(value) {
|
|
44
|
+
bot.onUnfollow = value;
|
|
45
|
+
},
|
|
46
|
+
get onAcceptFollow() {
|
|
47
|
+
return bot.onAcceptFollow;
|
|
48
|
+
},
|
|
49
|
+
set onAcceptFollow(value) {
|
|
50
|
+
bot.onAcceptFollow = value;
|
|
51
|
+
},
|
|
52
|
+
get onRejectFollow() {
|
|
53
|
+
return bot.onRejectFollow;
|
|
54
|
+
},
|
|
55
|
+
set onRejectFollow(value) {
|
|
56
|
+
bot.onRejectFollow = value;
|
|
57
|
+
},
|
|
58
|
+
get onMention() {
|
|
59
|
+
return bot.onMention;
|
|
60
|
+
},
|
|
61
|
+
set onMention(value) {
|
|
62
|
+
bot.onMention = value;
|
|
63
|
+
},
|
|
64
|
+
get onReply() {
|
|
65
|
+
return bot.onReply;
|
|
66
|
+
},
|
|
67
|
+
set onReply(value) {
|
|
68
|
+
bot.onReply = value;
|
|
69
|
+
},
|
|
70
|
+
get onQuote() {
|
|
71
|
+
return bot.onQuote;
|
|
72
|
+
},
|
|
73
|
+
set onQuote(value) {
|
|
74
|
+
bot.onQuote = value;
|
|
75
|
+
},
|
|
76
|
+
get onMessage() {
|
|
77
|
+
return bot.onMessage;
|
|
78
|
+
},
|
|
79
|
+
set onMessage(value) {
|
|
80
|
+
bot.onMessage = value;
|
|
81
|
+
},
|
|
82
|
+
get onSharedMessage() {
|
|
83
|
+
return bot.onSharedMessage;
|
|
84
|
+
},
|
|
85
|
+
set onSharedMessage(value) {
|
|
86
|
+
bot.onSharedMessage = value;
|
|
87
|
+
},
|
|
88
|
+
get onLike() {
|
|
89
|
+
return bot.onLike;
|
|
90
|
+
},
|
|
91
|
+
set onLike(value) {
|
|
92
|
+
bot.onLike = value;
|
|
93
|
+
},
|
|
94
|
+
get onUnlike() {
|
|
95
|
+
return bot.onUnlike;
|
|
96
|
+
},
|
|
97
|
+
set onUnlike(value) {
|
|
98
|
+
bot.onUnlike = value;
|
|
99
|
+
},
|
|
100
|
+
get onReact() {
|
|
101
|
+
return bot.onReact;
|
|
102
|
+
},
|
|
103
|
+
set onReact(value) {
|
|
104
|
+
bot.onReact = value;
|
|
105
|
+
},
|
|
106
|
+
get onUnreact() {
|
|
107
|
+
return bot.onUnreact;
|
|
108
|
+
},
|
|
109
|
+
set onUnreact(value) {
|
|
110
|
+
bot.onUnreact = value;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return wrapper;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { Application, Image, Service, createBot, parseSemVer };
|
|
118
|
+
//# sourceMappingURL=bot.js.map
|
package/dist/bot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.js","names":["options: CreateBotOptions<TContextData>","b?","emojis: Readonly<Record<TEmojiName, CustomEmoji>>"],"sources":["../src/bot.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport type {\n Context,\n Federation,\n KvStore,\n MessageQueue,\n} from \"@fedify/fedify/federation\";\nimport type { Software } from \"@fedify/fedify/nodeinfo\";\nimport type { Application, Image, Service } from \"@fedify/fedify/vocab\";\nimport { BotImpl } from \"./bot-impl.ts\";\nimport type { CustomEmoji, DeferredCustomEmoji } from \"./emoji.ts\";\nimport type {\n AcceptEventHandler,\n FollowEventHandler,\n LikeEventHandler,\n MentionEventHandler,\n MessageEventHandler,\n QuoteEventHandler,\n ReactionEventHandler,\n RejectEventHandler,\n ReplyEventHandler,\n SharedMessageEventHandler,\n UndoneReactionEventHandler,\n UnfollowEventHandler,\n UnlikeEventHandler,\n} from \"./events.ts\";\nimport type { Repository } from \"./repository.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { Text } from \"./text.ts\";\nexport {\n parseSemVer,\n type SemVer,\n type Software,\n} from \"@fedify/fedify/nodeinfo\";\nexport { Application, Image, Service } from \"@fedify/fedify/vocab\";\n\n/**\n * A bot that can interact with the ActivityPub network.\n */\nexport interface Bot<TContextData> {\n /**\n * An internal Fedify federation instance. Normally you don't need to access\n * this directly.\n */\n readonly federation: Federation<TContextData>;\n\n /**\n * The internal identifier for the bot actor. It is used for the actor URI.\n */\n readonly identifier: string;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: TContextData,\n ): Session<TContextData>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<TContextData>): Session<TContextData>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @param contextData The context data to pass to the federation.\n * @returns The response to the request.\n */\n fetch(request: Request, contextData: TContextData): Promise<Response>;\n\n /**\n * Defines custom emojis for the bot. The custom emojis are used for\n * rendering the bot's profile and posts. The custom emojis are defined\n * by their names, and the names are used as the keys of the emojis.\n * @param emojis The custom emojis to define. The keys are the names of\n * the emojis, and the values are the custom emoji definitions.\n * @returns The defined emojis. The keys are the names of the emojis, and\n * the values are the emoji objects, which are used for passing\n * to the {@link customEmoji} function.\n * @throws {TypeError} If any emoji name is invalid or duplicate.\n * @since 0.2.0\n */\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>>;\n\n /**\n * An event handler for a follow request to the bot.\n */\n onFollow?: FollowEventHandler<TContextData>;\n\n /**\n * An event handler for an unfollow event from the bot.\n */\n onUnfollow?: UnfollowEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is accepted.\n */\n onAcceptFollow?: AcceptEventHandler<TContextData>;\n\n /**\n * An event handler invoked when a follow request the bot sent is rejected.\n */\n onRejectFollow?: RejectEventHandler<TContextData>;\n\n /**\n * An event handler for a message mentioned to the bot.\n */\n onMention?: MentionEventHandler<TContextData>;\n\n /**\n * An event handler for a reply to the bot.\n */\n onReply?: ReplyEventHandler<TContextData>;\n\n /**\n * An event handler for a quote of the bot's message.\n * @since 0.2.0\n */\n onQuote?: QuoteEventHandler<TContextData>;\n\n /**\n * An event handler for a message shown to the bot's timeline. To listen\n * to this event, your bot needs to follow others first.\n */\n onMessage?: MessageEventHandler<TContextData>;\n\n /**\n * An event handler for a message shared to the bot. To listen to this event,\n * your bot needs to follow others first.\n */\n onSharedMessage?: SharedMessageEventHandler<TContextData>;\n\n /**\n * An event handler for a like of a message.\n */\n onLike?: LikeEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of a like of a message.\n */\n onUnlike?: UnlikeEventHandler<TContextData>;\n\n /**\n * An event handler for an emoji reaction to a message.\n * @since 0.2.0\n */\n onReact?: ReactionEventHandler<TContextData>;\n\n /**\n * An event handler for an undoing of an emoji reaction to a message.\n * @since 0.2.0\n */\n onUnreact?: UndoneReactionEventHandler<TContextData>;\n}\n\n/**\n * A specialized {@link Bot} tpe that doesn't require context data.\n */\nexport interface BotWithVoidContextData extends Bot<void> {\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n * @param contextData The context data to pass to the federation.\n * @returns The session for the origin and context data.\n */\n getSession(\n origin: string | URL,\n contextData: void,\n ): Session<void>;\n\n /**\n * Gets a new session to control bot for a specific Fedify context.\n * @param context The Fedify context of the session.\n * @returns The session for the Fedify context.\n */\n getSession(context: Context<void>): Session<void>;\n\n /**\n * Gets a new session to control the bot for a specific origin and context\n * data.\n * @param origin The origin of the session. Even if a URL with some path or\n * query is passed, only the origin part will be used.\n */\n getSession(origin: string | URL): Session<void>;\n\n /**\n * The fetch API for handling HTTP requests. You can pass this to an HTTP\n * server (e.g., `Deno.serve()`, `Bun.serve()`) to handle incoming requests.\n * @param request The request to handle.\n * @returns The response to the request.\n */\n fetch(request: Request): Promise<Response>;\n}\n\n/**\n * Options for creating a bot.\n */\nexport interface CreateBotOptions<TContextData> {\n /**\n * The internal identifier of the bot. Since it is used for the actor URI,\n * it *should not* be changed after the bot is federated.\n *\n * If omitted, `\"bot\"` will be used.\n * @default `\"bot\"`\n */\n readonly identifier?: string;\n\n /**\n * The type of the bot actor. It should be either `Service` or `Application`.\n *\n * If omitted, `Service` will be used.\n * @default `Service`\n */\n readonly class?: typeof Service | typeof Application;\n\n /**\n * The username of the bot. It will be a part of the fediverse handle.\n * It can be changed after the bot is federated.\n */\n readonly username: string;\n\n /**\n * The display name of the bot. It can be changed after the bot is federated.\n */\n readonly name?: string;\n\n /**\n * The description of the bot. It can be changed after the bot is federated.\n */\n readonly summary?: Text<\"block\", TContextData>;\n\n /**\n * The avatar URL of the bot. It can be changed after the bot is federated.\n */\n readonly icon?: URL | Image;\n\n /**\n * The header image URL of the bot. It can be changed after the bot is\n * federated.\n */\n readonly image?: URL | Image;\n\n /**\n * The custom properties of the bot. It can be changed after the bot is\n * federated.\n */\n readonly properties?: Record<string, Text<\"block\" | \"inline\", TContextData>>;\n\n /**\n * How to handle incoming follow requests. Note that this behavior can be\n * overridden by manually invoking {@link FollowRequest.accept} or\n * {@link FollowRequest.reject} in the {@link Bot.onFollow} event handler.\n *\n * - `\"accept\"` (default): Automatically accept all incoming follow requests.\n * - `\"reject\"`: Automatically reject all incoming follow requests.\n * - `\"manual\"`: Require manual handling of incoming follow requests.\n * @default `\"accept\"`\n */\n readonly followerPolicy?: \"accept\" | \"reject\" | \"manual\";\n\n /**\n * The underlying key-value store to use for storing data.\n */\n readonly kv: KvStore;\n\n /**\n * The underlying repository to use for storing data. If omitted,\n * {@link KvRepository} will be used.\n */\n readonly repository?: Repository;\n\n /**\n * The underlying message queue to use for handling incoming and outgoing\n * activities. If omitted, incoming activities are processed immediately,\n * and outgoing activities are sent immediately.\n */\n readonly queue?: MessageQueue;\n\n /**\n * The software information of the bot. If omitted, the NodeInfo protocol\n * will be unimplemented.\n */\n readonly software?: Software;\n\n /**\n * Whether to trust `X-Forwarded-*` headers. If your bot application is\n * behind an L7 reverse proxy, turn it on.\n *\n * Turned off by default.\n * @default `false`\n */\n readonly behindProxy?: boolean;\n\n /**\n * The options for the web pages of the bot. If omitted, the default options\n * will be used.\n */\n readonly pages?: PagesOptions;\n}\n\n/**\n * Options for the web pages of the bot.\n */\nexport interface PagesOptions {\n /**\n * The color of the theme. It will be used for the theme color of the web\n * pages. The default color is `\"green\"`.\n * @default `\"green\"`\n */\n readonly color?:\n | \"amber\"\n | \"azure\"\n | \"blue\"\n | \"cyan\"\n | \"fuchsia\"\n | \"green\"\n | \"grey\"\n | \"indigo\"\n | \"jade\"\n | \"lime\"\n | \"orange\"\n | \"pink\"\n | \"pumpkin\"\n | \"purple\"\n | \"red\"\n | \"sand\"\n | \"slate\"\n | \"violet\"\n | \"yellow\"\n | \"zinc\";\n\n /**\n * The CSS code for the bot. It will be used for the custom CSS of the web\n * pages.\n */\n readonly css?: string;\n}\n\n/**\n * Creates a {@link Bot} instance.\n * @param options The options for creating the bot.\n * @returns The created bot instance.\n */\nexport function createBot<TContextData = void>(\n options: CreateBotOptions<TContextData>,\n): TContextData extends void ? BotWithVoidContextData : Bot<TContextData> {\n const bot = new BotImpl<TContextData>(options);\n // Since `deno serve` does not recognize a class instance having fetch(),\n // we wrap a BotImpl instance with a plain object.\n // See also https://github.com/denoland/deno/issues/24062\n const wrapper = {\n impl: bot,\n get federation() {\n return bot.federation;\n },\n get identifier() {\n return bot.identifier;\n },\n getSession(a, b?) {\n // @ts-ignore: BotImpl.getSession() implements Bot.getSession()\n return bot.getSession(a, b);\n },\n fetch(request, contextData) {\n return bot.fetch(request, contextData);\n },\n addCustomEmojis<TEmojiName extends string>(\n emojis: Readonly<Record<TEmojiName, CustomEmoji>>,\n ): Readonly<Record<TEmojiName, DeferredCustomEmoji<TContextData>>> {\n return bot.addCustomEmojis(emojis);\n },\n get onFollow() {\n return bot.onFollow;\n },\n set onFollow(value) {\n bot.onFollow = value;\n },\n get onUnfollow() {\n return bot.onUnfollow;\n },\n set onUnfollow(value) {\n bot.onUnfollow = value;\n },\n get onAcceptFollow() {\n return bot.onAcceptFollow;\n },\n set onAcceptFollow(value) {\n bot.onAcceptFollow = value;\n },\n get onRejectFollow() {\n return bot.onRejectFollow;\n },\n set onRejectFollow(value) {\n bot.onRejectFollow = value;\n },\n get onMention() {\n return bot.onMention;\n },\n set onMention(value) {\n bot.onMention = value;\n },\n get onReply() {\n return bot.onReply;\n },\n set onReply(value) {\n bot.onReply = value;\n },\n get onQuote() {\n return bot.onQuote;\n },\n set onQuote(value) {\n bot.onQuote = value;\n },\n get onMessage() {\n return bot.onMessage;\n },\n set onMessage(value) {\n bot.onMessage = value;\n },\n get onSharedMessage() {\n return bot.onSharedMessage;\n },\n set onSharedMessage(value) {\n bot.onSharedMessage = value;\n },\n get onLike() {\n return bot.onLike;\n },\n set onLike(value) {\n bot.onLike = value;\n },\n get onUnlike() {\n return bot.onUnlike;\n },\n set onUnlike(value) {\n bot.onUnlike = value;\n },\n get onReact() {\n return bot.onReact;\n },\n set onReact(value) {\n bot.onReact = value;\n },\n get onUnreact() {\n return bot.onUnreact;\n },\n set onUnreact(value) {\n bot.onUnreact = value;\n },\n } satisfies Bot<TContextData> & { impl: BotImpl<TContextData> };\n // @ts-ignore: the wrapper implements BotWithVoidContextData\n return wrapper;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmXA,SAAgB,UACdA,SACwE;CACxE,MAAM,MAAM,IAAI,QAAsB;CAItC,MAAM,UAAU;EACd,MAAM;EACN,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,WAAW,GAAGC,GAAI;AAEhB,UAAO,IAAI,WAAW,GAAG,EAAE;EAC5B;EACD,MAAM,SAAS,aAAa;AAC1B,UAAO,IAAI,MAAM,SAAS,YAAY;EACvC;EACD,gBACEC,QACiE;AACjE,UAAO,IAAI,gBAAgB,OAAO;EACnC;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,aAAa;AACf,UAAO,IAAI;EACZ;EACD,IAAI,WAAW,OAAO;AACpB,OAAI,aAAa;EAClB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,iBAAiB;AACnB,UAAO,IAAI;EACZ;EACD,IAAI,eAAe,OAAO;AACxB,OAAI,iBAAiB;EACtB;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;EACD,IAAI,kBAAkB;AACpB,UAAO,IAAI;EACZ;EACD,IAAI,gBAAgB,OAAO;AACzB,OAAI,kBAAkB;EACvB;EACD,IAAI,SAAS;AACX,UAAO,IAAI;EACZ;EACD,IAAI,OAAO,OAAO;AAChB,OAAI,SAAS;EACd;EACD,IAAI,WAAW;AACb,UAAO,IAAI;EACZ;EACD,IAAI,SAAS,OAAO;AAClB,OAAI,WAAW;EAChB;EACD,IAAI,UAAU;AACZ,UAAO,IAAI;EACZ;EACD,IAAI,QAAQ,OAAO;AACjB,OAAI,UAAU;EACf;EACD,IAAI,YAAY;AACd,UAAO,IAAI;EACZ;EACD,IAAI,UAAU,OAAO;AACnB,OAAI,YAAY;EACjB;CACF;AAED,QAAO;AACR"}
|
package/dist/bot.test.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
import { createBot } from "./bot.js";
|
|
6
|
+
import { MemoryKvStore } from "@fedify/fedify/federation";
|
|
7
|
+
import assert from "node:assert";
|
|
8
|
+
import { test } from "node:test";
|
|
9
|
+
|
|
10
|
+
//#region src/bot.test.ts
|
|
11
|
+
test("createBot()", async () => {
|
|
12
|
+
const kv = new MemoryKvStore();
|
|
13
|
+
const bot = createBot({
|
|
14
|
+
kv,
|
|
15
|
+
identifier: "bot-id",
|
|
16
|
+
username: "bot"
|
|
17
|
+
});
|
|
18
|
+
const { impl } = bot;
|
|
19
|
+
const _federation = bot.federation;
|
|
20
|
+
assert.strictEqual(bot.identifier, "bot-id");
|
|
21
|
+
const session = bot.getSession("https://example.com");
|
|
22
|
+
assert.strictEqual(session.actorHandle, "@bot@example.com");
|
|
23
|
+
function onFollow(_session, _followRequest) {}
|
|
24
|
+
bot.onFollow = onFollow;
|
|
25
|
+
assert.strictEqual(bot.onFollow, onFollow);
|
|
26
|
+
assert.strictEqual(impl.onFollow, onFollow);
|
|
27
|
+
function onUnfollow(_session, _follower) {}
|
|
28
|
+
bot.onUnfollow = onUnfollow;
|
|
29
|
+
assert.strictEqual(bot.onUnfollow, onUnfollow);
|
|
30
|
+
assert.strictEqual(impl.onUnfollow, onUnfollow);
|
|
31
|
+
function onAcceptFollow(_session, _accepter) {}
|
|
32
|
+
bot.onAcceptFollow = onAcceptFollow;
|
|
33
|
+
assert.strictEqual(bot.onAcceptFollow, onAcceptFollow);
|
|
34
|
+
assert.strictEqual(impl.onAcceptFollow, onAcceptFollow);
|
|
35
|
+
function onRejectFollow(_session, _rejecter) {}
|
|
36
|
+
bot.onRejectFollow = onRejectFollow;
|
|
37
|
+
assert.strictEqual(bot.onRejectFollow, onRejectFollow);
|
|
38
|
+
assert.strictEqual(impl.onRejectFollow, onRejectFollow);
|
|
39
|
+
function onMention(_session, _message) {}
|
|
40
|
+
bot.onMention = onMention;
|
|
41
|
+
assert.strictEqual(bot.onMention, onMention);
|
|
42
|
+
assert.strictEqual(impl.onMention, onMention);
|
|
43
|
+
function onReply(_session, _message) {}
|
|
44
|
+
bot.onReply = onReply;
|
|
45
|
+
assert.strictEqual(bot.onReply, onReply);
|
|
46
|
+
assert.strictEqual(impl.onReply, onReply);
|
|
47
|
+
function onMessage(_session, _message) {}
|
|
48
|
+
bot.onMessage = onMessage;
|
|
49
|
+
assert.strictEqual(bot.onMessage, onMessage);
|
|
50
|
+
assert.strictEqual(impl.onMessage, onMessage);
|
|
51
|
+
function onSharedMessage(_session, _message) {}
|
|
52
|
+
bot.onSharedMessage = onSharedMessage;
|
|
53
|
+
assert.strictEqual(bot.onSharedMessage, onSharedMessage);
|
|
54
|
+
assert.strictEqual(impl.onSharedMessage, onSharedMessage);
|
|
55
|
+
function onLike(_session, _like) {}
|
|
56
|
+
bot.onLike = onLike;
|
|
57
|
+
assert.strictEqual(bot.onLike, onLike);
|
|
58
|
+
assert.strictEqual(impl.onLike, onLike);
|
|
59
|
+
function onUnlike(_session, _like) {}
|
|
60
|
+
bot.onUnlike = onUnlike;
|
|
61
|
+
assert.strictEqual(bot.onUnlike, onUnlike);
|
|
62
|
+
assert.strictEqual(impl.onUnlike, onUnlike);
|
|
63
|
+
const response = await bot.fetch(new Request("https://example.com/.well-known/webfinger?resource=acct:bot@example.com"));
|
|
64
|
+
assert.strictEqual(response.status, 200);
|
|
65
|
+
assert.deepStrictEqual(await response.json(), {
|
|
66
|
+
aliases: ["https://example.com/ap/actor/bot-id"],
|
|
67
|
+
links: [{
|
|
68
|
+
href: "https://example.com/ap/actor/bot-id",
|
|
69
|
+
rel: "self",
|
|
70
|
+
type: "application/activity+json"
|
|
71
|
+
}, {
|
|
72
|
+
href: "https://example.com/",
|
|
73
|
+
rel: "http://webfinger.net/rel/profile-page"
|
|
74
|
+
}],
|
|
75
|
+
subject: "acct:bot@example.com"
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//# sourceMappingURL=bot.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.test.js","names":["_session: Session<void>","_followRequest: FollowRequest","_follower: Actor","_accepter: Actor","_rejecter: Actor","_message: Message<MessageClass, void>","_message: SharedMessage<MessageClass, void>","_like: Like<void>"],"sources":["../src/bot.test.ts"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport { MemoryKvStore } from \"@fedify/fedify/federation\";\nimport type { Actor } from \"@fedify/fedify/vocab\";\nimport assert from \"node:assert\";\nimport { test } from \"node:test\";\nimport type { BotImpl } from \"./bot-impl.ts\";\nimport { createBot } from \"./bot.ts\";\nimport type { FollowRequest } from \"./follow.ts\";\nimport type { Message, MessageClass, SharedMessage } from \"./message.ts\";\nimport type { Like } from \"./reaction.ts\";\nimport type { Session } from \"./session.ts\";\n\ntest(\"createBot()\", async () => {\n const kv = new MemoryKvStore();\n const bot = createBot<void>({ kv, identifier: \"bot-id\", username: \"bot\" });\n const { impl } = bot as unknown as { impl: BotImpl<void> };\n const _federation = bot.federation;\n assert.strictEqual(bot.identifier, \"bot-id\");\n const session = bot.getSession(\"https://example.com\");\n assert.strictEqual(session.actorHandle, \"@bot@example.com\");\n\n function onFollow(_session: Session<void>, _followRequest: FollowRequest) {}\n bot.onFollow = onFollow;\n assert.strictEqual(bot.onFollow, onFollow);\n assert.strictEqual(impl.onFollow, onFollow);\n\n function onUnfollow(_session: Session<void>, _follower: Actor) {}\n bot.onUnfollow = onUnfollow;\n assert.strictEqual(bot.onUnfollow, onUnfollow);\n assert.strictEqual(impl.onUnfollow, onUnfollow);\n\n function onAcceptFollow(_session: Session<void>, _accepter: Actor) {}\n bot.onAcceptFollow = onAcceptFollow;\n assert.strictEqual(bot.onAcceptFollow, onAcceptFollow);\n assert.strictEqual(impl.onAcceptFollow, onAcceptFollow);\n\n function onRejectFollow(_session: Session<void>, _rejecter: Actor) {}\n bot.onRejectFollow = onRejectFollow;\n assert.strictEqual(bot.onRejectFollow, onRejectFollow);\n assert.strictEqual(impl.onRejectFollow, onRejectFollow);\n\n function onMention(\n _session: Session<void>,\n _message: Message<MessageClass, void>,\n ) {}\n bot.onMention = onMention;\n assert.strictEqual(bot.onMention, onMention);\n assert.strictEqual(impl.onMention, onMention);\n\n function onReply(\n _session: Session<void>,\n _message: Message<MessageClass, void>,\n ) {}\n bot.onReply = onReply;\n assert.strictEqual(bot.onReply, onReply);\n assert.strictEqual(impl.onReply, onReply);\n\n function onMessage(\n _session: Session<void>,\n _message: Message<MessageClass, void>,\n ) {}\n bot.onMessage = onMessage;\n assert.strictEqual(bot.onMessage, onMessage);\n assert.strictEqual(impl.onMessage, onMessage);\n\n function onSharedMessage(\n _session: Session<void>,\n _message: SharedMessage<MessageClass, void>,\n ) {}\n bot.onSharedMessage = onSharedMessage;\n assert.strictEqual(bot.onSharedMessage, onSharedMessage);\n assert.strictEqual(impl.onSharedMessage, onSharedMessage);\n\n function onLike(_session: Session<void>, _like: Like<void>) {}\n bot.onLike = onLike;\n assert.strictEqual(bot.onLike, onLike);\n assert.strictEqual(impl.onLike, onLike);\n\n function onUnlike(_session: Session<void>, _like: Like<void>) {}\n bot.onUnlike = onUnlike;\n assert.strictEqual(bot.onUnlike, onUnlike);\n assert.strictEqual(impl.onUnlike, onUnlike);\n\n const response = await bot.fetch(\n new Request(\n \"https://example.com/.well-known/webfinger?resource=acct:bot@example.com\",\n ),\n );\n assert.strictEqual(response.status, 200);\n assert.deepStrictEqual(await response.json(), {\n aliases: [\n \"https://example.com/ap/actor/bot-id\",\n ],\n links: [\n {\n href: \"https://example.com/ap/actor/bot-id\",\n rel: \"self\",\n type: \"application/activity+json\",\n },\n {\n href: \"https://example.com/\",\n rel: \"http://webfinger.net/rel/profile-page\",\n },\n ],\n subject: \"acct:bot@example.com\",\n });\n});\n"],"mappings":";;;;;;;;;;AA0BA,KAAK,eAAe,YAAY;CAC9B,MAAM,KAAK,IAAI;CACf,MAAM,MAAM,UAAgB;EAAE;EAAI,YAAY;EAAU,UAAU;CAAO,EAAC;CAC1E,MAAM,EAAE,MAAM,GAAG;CACjB,MAAM,cAAc,IAAI;AACxB,QAAO,YAAY,IAAI,YAAY,SAAS;CAC5C,MAAM,UAAU,IAAI,WAAW,sBAAsB;AACrD,QAAO,YAAY,QAAQ,aAAa,mBAAmB;CAE3D,SAAS,SAASA,UAAyBC,gBAA+B,CAAE;AAC5E,KAAI,WAAW;AACf,QAAO,YAAY,IAAI,UAAU,SAAS;AAC1C,QAAO,YAAY,KAAK,UAAU,SAAS;CAE3C,SAAS,WAAWD,UAAyBE,WAAkB,CAAE;AACjE,KAAI,aAAa;AACjB,QAAO,YAAY,IAAI,YAAY,WAAW;AAC9C,QAAO,YAAY,KAAK,YAAY,WAAW;CAE/C,SAAS,eAAeF,UAAyBG,WAAkB,CAAE;AACrE,KAAI,iBAAiB;AACrB,QAAO,YAAY,IAAI,gBAAgB,eAAe;AACtD,QAAO,YAAY,KAAK,gBAAgB,eAAe;CAEvD,SAAS,eAAeH,UAAyBI,WAAkB,CAAE;AACrE,KAAI,iBAAiB;AACrB,QAAO,YAAY,IAAI,gBAAgB,eAAe;AACtD,QAAO,YAAY,KAAK,gBAAgB,eAAe;CAEvD,SAAS,UACPJ,UACAK,UACA,CAAE;AACJ,KAAI,YAAY;AAChB,QAAO,YAAY,IAAI,WAAW,UAAU;AAC5C,QAAO,YAAY,KAAK,WAAW,UAAU;CAE7C,SAAS,QACPL,UACAK,UACA,CAAE;AACJ,KAAI,UAAU;AACd,QAAO,YAAY,IAAI,SAAS,QAAQ;AACxC,QAAO,YAAY,KAAK,SAAS,QAAQ;CAEzC,SAAS,UACPL,UACAK,UACA,CAAE;AACJ,KAAI,YAAY;AAChB,QAAO,YAAY,IAAI,WAAW,UAAU;AAC5C,QAAO,YAAY,KAAK,WAAW,UAAU;CAE7C,SAAS,gBACPL,UACAM,UACA,CAAE;AACJ,KAAI,kBAAkB;AACtB,QAAO,YAAY,IAAI,iBAAiB,gBAAgB;AACxD,QAAO,YAAY,KAAK,iBAAiB,gBAAgB;CAEzD,SAAS,OAAON,UAAyBO,OAAmB,CAAE;AAC9D,KAAI,SAAS;AACb,QAAO,YAAY,IAAI,QAAQ,OAAO;AACtC,QAAO,YAAY,KAAK,QAAQ,OAAO;CAEvC,SAAS,SAASP,UAAyBO,OAAmB,CAAE;AAChE,KAAI,WAAW;AACf,QAAO,YAAY,IAAI,UAAU,SAAS;AAC1C,QAAO,YAAY,KAAK,UAAU,SAAS;CAE3C,MAAM,WAAW,MAAM,IAAI,MACzB,IAAI,QACF,2EAEH;AACD,QAAO,YAAY,SAAS,QAAQ,IAAI;AACxC,QAAO,gBAAgB,MAAM,SAAS,MAAM,EAAE;EAC5C,SAAS,CACP,qCACD;EACD,OAAO,CACL;GACE,MAAM;GACN,KAAK;GACL,MAAM;EACP,GACD;GACE,MAAM;GACN,KAAK;EACN,CACF;EACD,SAAS;CACV,EAAC;AACH,EAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
2
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
3
|
+
import { BotImpl } from "../bot-impl.js";
|
|
4
|
+
import { JSX } from "hono/jsx/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/components/Layout.d.ts
|
|
7
|
+
interface LayoutProps extends JSX.ElementChildrenAttribute {
|
|
8
|
+
readonly bot: BotImpl<unknown>;
|
|
9
|
+
readonly host: string;
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
readonly activityLink?: string | URL;
|
|
12
|
+
readonly feedLink?: string | URL;
|
|
13
|
+
}
|
|
14
|
+
declare function Layout({
|
|
15
|
+
bot,
|
|
16
|
+
host,
|
|
17
|
+
title,
|
|
18
|
+
activityLink,
|
|
19
|
+
feedLink,
|
|
20
|
+
children
|
|
21
|
+
}: LayoutProps): JSX.Element;
|
|
22
|
+
//# sourceMappingURL=Layout.d.ts.map
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Layout, LayoutProps };
|
|
26
|
+
//# sourceMappingURL=Layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Layout.d.ts","names":[],"sources":["../../src/components/Layout.tsx"],"sourcesContent":[],"mappings":";;;;;;UAoBiB,WAAA,SAAoB,GAAA,CAAI;gBACzB;;;EADC,SAAA,YAAY,CAAA,EAAA,MAAA,GAIM,GAJN;EAAA,SAAA,QAAA,CAAA,EAAA,MAAA,GAKE,GALF;;AAIM,iBAInB,MAAA,CAJmB;EAAA,GAAA;EAAA,IAAA;EAAA,KAAA;EAAA,YAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAKuB,WALvB,CAAA,EAKkC,GAAA,CAAA,OALlC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/components/Layout.tsx
|
|
8
|
+
function Layout({ bot, host, title, activityLink, feedLink, children }) {
|
|
9
|
+
const handle = `@${bot.username}@${host}`;
|
|
10
|
+
const cssFilename = bot.pages.color === "azure" ? `pico.min.css` : `pico.${bot.pages.color}.min.css`;
|
|
11
|
+
return /* @__PURE__ */ jsxs("html", { children: [/* @__PURE__ */ jsxs("head", { children: [
|
|
12
|
+
/* @__PURE__ */ jsx("meta", { charset: "utf-8" }),
|
|
13
|
+
/* @__PURE__ */ jsxs("title", { children: [title != null && `${title} — `, bot.name == null ? handle : `${bot.name} (${handle})`] }),
|
|
14
|
+
activityLink && /* @__PURE__ */ jsx("link", {
|
|
15
|
+
rel: "alternate",
|
|
16
|
+
type: "application/activity+json",
|
|
17
|
+
href: activityLink.toString(),
|
|
18
|
+
title: "ActivityPub"
|
|
19
|
+
}),
|
|
20
|
+
feedLink && /* @__PURE__ */ jsx("link", {
|
|
21
|
+
rel: "alternate",
|
|
22
|
+
type: "application/atom+xml",
|
|
23
|
+
href: feedLink.toString(),
|
|
24
|
+
title: "Atom feed"
|
|
25
|
+
}),
|
|
26
|
+
/* @__PURE__ */ jsx("link", {
|
|
27
|
+
rel: "stylesheet",
|
|
28
|
+
href: `https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/${cssFilename}`
|
|
29
|
+
}),
|
|
30
|
+
/* @__PURE__ */ jsx("style", { children: bot.pages.css })
|
|
31
|
+
] }), /* @__PURE__ */ jsx("body", { children })] });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Layout };
|
|
36
|
+
//# sourceMappingURL=Layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Layout.js","names":[],"sources":["../../src/components/Layout.tsx"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n/** @jsx react-jsx */\n/** @jsxImportSource hono/jsx */\nimport type { JSX } from \"hono/jsx/jsx-runtime\";\nimport type { BotImpl } from \"../bot-impl.ts\";\n\nexport interface LayoutProps extends JSX.ElementChildrenAttribute {\n readonly bot: BotImpl<unknown>;\n readonly host: string;\n readonly title?: string;\n readonly activityLink?: string | URL;\n readonly feedLink?: string | URL;\n}\n\nexport function Layout(\n { bot, host, title, activityLink, feedLink, children }: LayoutProps,\n) {\n const handle = `@${bot.username}@${host}`;\n const cssFilename = bot.pages.color === \"azure\"\n ? `pico.min.css`\n : `pico.${bot.pages.color}.min.css`;\n return (\n <html>\n <head>\n <meta charset=\"utf-8\" />\n <title>\n {title != null && `${title} — `}\n {bot.name == null ? handle : `${bot.name} (${handle})`}\n </title>\n {activityLink &&\n (\n <link\n rel=\"alternate\"\n type=\"application/activity+json\"\n href={activityLink.toString()}\n title=\"ActivityPub\"\n />\n )}\n {feedLink && (\n <link\n rel=\"alternate\"\n type=\"application/atom+xml\"\n href={feedLink.toString()}\n title=\"Atom feed\"\n />\n )}\n <link\n rel=\"stylesheet\"\n href={`https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/${cssFilename}`}\n />\n <style>{bot.pages.css}</style>\n </head>\n <body>\n {children}\n </body>\n </html>\n );\n}\n"],"mappings":";;;;;;;AA4BA,SAAgB,OACd,EAAE,KAAK,MAAM,OAAO,cAAc,UAAU,UAAuB,EACnE;CACA,MAAM,UAAU,GAAG,IAAI,SAAS,GAAG,KAAK;CACxC,MAAM,cAAc,IAAI,MAAM,UAAU,WACnC,iBACA,OAAO,IAAI,MAAM,MAAM;AAC5B,wBACE,KAAC,qCACC,KAAC;kBACC,IAAC,UAAK,SAAQ,UAAU;kBACxB,KAAC,sBACE,SAAS,SAAS,EAAE,MAAM,MAC1B,IAAI,QAAQ,OAAO,UAAU,EAAE,IAAI,KAAK,IAAI,OAAO,MAC9C;EACP,gCAEG,IAAC;GACC,KAAI;GACJ,MAAK;GACL,MAAM,aAAa,UAAU;GAC7B,OAAM;IACN;EAEL,4BACC,IAAC;GACC,KAAI;GACJ,MAAK;GACL,MAAM,SAAS,UAAU;GACzB,OAAM;IACN;kBAEJ,IAAC;GACC,KAAI;GACJ,OAAO,mDAAmD,YAAY;IACtE;kBACF,IAAC,qBAAO,IAAI,MAAM,MAAY;KACzB,kBACP,IAAC,UACE,WACI,IACF;AAEV"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
2
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
3
|
+
import { MessageClass } from "../message.js";
|
|
4
|
+
import { Session } from "../session.js";
|
|
5
|
+
import * as hono_utils_html1 from "hono/utils/html";
|
|
6
|
+
|
|
7
|
+
//#region src/components/Message.d.ts
|
|
8
|
+
interface MessageProps {
|
|
9
|
+
readonly message: MessageClass;
|
|
10
|
+
readonly session: Session<unknown>;
|
|
11
|
+
}
|
|
12
|
+
declare function Message({
|
|
13
|
+
session,
|
|
14
|
+
message
|
|
15
|
+
}: MessageProps): Promise<hono_utils_html1.HtmlEscapedString>;
|
|
16
|
+
declare function renderCustomEmojis(html: string, emojis: Record<string, string>): string;
|
|
17
|
+
//# sourceMappingURL=Message.d.ts.map
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Message, MessageProps, renderCustomEmojis };
|
|
21
|
+
//# sourceMappingURL=Message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.d.ts","names":[],"sources":["../../src/components/Message.tsx"],"sourcesContent":[],"mappings":";;;;;;;UA4BiB,YAAA;oBACG;oBACA;;iBAGE,OAAA;;;GAA8B,eAAY,QAAA,gBAAA,CAAA,iBAAA;iBAwGhD,kBAAA,uBAEN"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
import { Document, Emoji, Image, Link, getActorHandle } from "@fedify/fedify/vocab";
|
|
6
|
+
import { LanguageString } from "@fedify/fedify/runtime";
|
|
7
|
+
import { jsx, jsxs } from "hono/jsx/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
//#region src/components/Message.tsx
|
|
10
|
+
async function Message({ session, message }) {
|
|
11
|
+
const { context } = session;
|
|
12
|
+
const author = message.attributionId?.href === session.actorId?.href ? await session.getActor() : await message.getAttribution({
|
|
13
|
+
documentLoader: context.documentLoader,
|
|
14
|
+
contextLoader: context.contextLoader,
|
|
15
|
+
suppressError: true
|
|
16
|
+
});
|
|
17
|
+
const authorIcon = await author?.getIcon({
|
|
18
|
+
documentLoader: context.documentLoader,
|
|
19
|
+
contextLoader: context.contextLoader,
|
|
20
|
+
suppressError: true
|
|
21
|
+
});
|
|
22
|
+
const authorHandle = author == null ? null : await getActorHandle(author);
|
|
23
|
+
const attachments = await Array.fromAsync(message.getAttachments());
|
|
24
|
+
const tags = await Array.fromAsync(message.getTags());
|
|
25
|
+
const customEmojis = {};
|
|
26
|
+
for (const tag of tags) {
|
|
27
|
+
if (!(tag instanceof Emoji) || tag.name == null) continue;
|
|
28
|
+
const icon = await tag.getIcon();
|
|
29
|
+
if (icon?.url == null) continue;
|
|
30
|
+
const url = icon.url instanceof Link ? icon.url.href?.href : icon.url.href;
|
|
31
|
+
if (url == null) continue;
|
|
32
|
+
customEmojis[tag.name.toString()] = url;
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsxs("article", { children: [
|
|
35
|
+
/* @__PURE__ */ jsx("header", { children: author?.id ? /* @__PURE__ */ jsxs("hgroup", { children: [
|
|
36
|
+
authorIcon?.url && /* @__PURE__ */ jsx("img", {
|
|
37
|
+
src: authorIcon.url instanceof Link ? authorIcon.url.href?.href : authorIcon.url.href,
|
|
38
|
+
width: authorIcon.width ?? void 0,
|
|
39
|
+
height: authorIcon.height ?? void 0,
|
|
40
|
+
alt: authorIcon.name?.toString() ?? void 0,
|
|
41
|
+
style: "float: left; margin-right: 1em; height: 64px;"
|
|
42
|
+
}),
|
|
43
|
+
/* @__PURE__ */ jsx("h3", { children: /* @__PURE__ */ jsx("a", {
|
|
44
|
+
href: author.url?.href?.toString() ?? author.id.href,
|
|
45
|
+
children: author.name
|
|
46
|
+
}) }),
|
|
47
|
+
" ",
|
|
48
|
+
/* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx("span", {
|
|
49
|
+
style: "user-select: all;",
|
|
50
|
+
children: authorHandle
|
|
51
|
+
}) })
|
|
52
|
+
] }) : /* @__PURE__ */ jsx("em", { children: "(Deleted account)" }) }),
|
|
53
|
+
/* @__PURE__ */ jsx("div", {
|
|
54
|
+
dangerouslySetInnerHTML: { __html: renderCustomEmojis(`${message.content}`, customEmojis) },
|
|
55
|
+
lang: message.content instanceof LanguageString ? message.content.language.compact() : void 0
|
|
56
|
+
}),
|
|
57
|
+
attachments.length > 0 && /* @__PURE__ */ jsx("div", { children: attachments.filter((a) => a instanceof Image || a instanceof Document).filter((a) => a.mediaType?.startsWith("image/") && a.url != null).map((a) => /* @__PURE__ */ jsxs("figure", { children: [/* @__PURE__ */ jsx("img", {
|
|
58
|
+
src: a.url instanceof Link ? a.url.href?.href : a.url.href,
|
|
59
|
+
width: a.width ?? void 0,
|
|
60
|
+
height: a.height ?? void 0,
|
|
61
|
+
alt: a.name?.toString() ?? void 0,
|
|
62
|
+
style: "max-width: 75%;"
|
|
63
|
+
}), /* @__PURE__ */ jsx("figcaption", { children: a.name?.toString() })] })) }),
|
|
64
|
+
/* @__PURE__ */ jsx("footer", { children: message.published && /* @__PURE__ */ jsx("a", {
|
|
65
|
+
href: message.url?.href?.toString() ?? message.id?.href,
|
|
66
|
+
children: /* @__PURE__ */ jsx("small", { children: /* @__PURE__ */ jsx("time", {
|
|
67
|
+
dateTime: message.published.toString(),
|
|
68
|
+
children: message.published.toLocaleString("en", {
|
|
69
|
+
dateStyle: "full",
|
|
70
|
+
timeStyle: "short"
|
|
71
|
+
})
|
|
72
|
+
}) })
|
|
73
|
+
}) })
|
|
74
|
+
] });
|
|
75
|
+
}
|
|
76
|
+
const HTML_ELEMENT_REGEXP = /<\/?[^>]+>/g;
|
|
77
|
+
const CUSTOM_EMOJI_REGEXP = /:([a-z0-9_-]+):/gi;
|
|
78
|
+
function renderCustomEmojis(html, emojis) {
|
|
79
|
+
let result = "";
|
|
80
|
+
let index = 0;
|
|
81
|
+
for (const match of html.matchAll(HTML_ELEMENT_REGEXP)) {
|
|
82
|
+
result += replaceEmojis(html.substring(index, match.index));
|
|
83
|
+
result += match[0];
|
|
84
|
+
index = match.index + match[0].length;
|
|
85
|
+
}
|
|
86
|
+
result += replaceEmojis(html.substring(index));
|
|
87
|
+
return result;
|
|
88
|
+
function replaceEmojis(html$1) {
|
|
89
|
+
return html$1.replaceAll(CUSTOM_EMOJI_REGEXP, (match) => {
|
|
90
|
+
const emoji = emojis[match] ?? emojis[match.replace(/^:|:$/g, "")];
|
|
91
|
+
if (emoji == null) return match;
|
|
92
|
+
return `<img src="${emoji}" alt="${match}" style="height: 1em">`;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { Message, renderCustomEmojis };
|
|
99
|
+
//# sourceMappingURL=Message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.js","names":["customEmojis: Record<string, string>","html: string","emojis: Record<string, string>"],"sources":["../../src/components/Message.tsx"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n/** @jsx react-jsx */\n/** @jsxImportSource hono/jsx */\nimport { LanguageString } from \"@fedify/fedify/runtime\";\nimport {\n Document,\n Emoji,\n getActorHandle,\n Image,\n Link,\n} from \"@fedify/fedify/vocab\";\nimport type { MessageClass } from \"../message.ts\";\nimport type { Session } from \"../session.ts\";\n\nexport interface MessageProps {\n readonly message: MessageClass;\n readonly session: Session<unknown>;\n}\n\nexport async function Message({ session, message }: MessageProps) {\n const { context } = session;\n const author = message.attributionId?.href === session.actorId?.href\n ? await session.getActor()\n : await message.getAttribution({\n documentLoader: context.documentLoader,\n contextLoader: context.contextLoader,\n suppressError: true,\n });\n const authorIcon = await author?.getIcon({\n documentLoader: context.documentLoader,\n contextLoader: context.contextLoader,\n suppressError: true,\n });\n const authorHandle = author == null ? null : await getActorHandle(author);\n const attachments = await Array.fromAsync(message.getAttachments());\n const tags = await Array.fromAsync(message.getTags());\n const customEmojis: Record<string, string> = {};\n for (const tag of tags) {\n if (!(tag instanceof Emoji) || tag.name == null) continue;\n const icon = await tag.getIcon();\n if (icon?.url == null) continue;\n const url = icon.url instanceof Link ? icon.url.href?.href : icon.url.href;\n if (url == null) continue;\n customEmojis[tag.name.toString()] = url;\n }\n return (\n <article>\n <header>\n {author?.id\n ? (\n <hgroup>\n {authorIcon?.url && (\n <img\n src={authorIcon.url instanceof Link\n ? authorIcon.url.href?.href\n : authorIcon.url.href}\n width={authorIcon.width ?? undefined}\n height={authorIcon.height ?? undefined}\n alt={authorIcon.name?.toString() ?? undefined}\n style=\"float: left; margin-right: 1em; height: 64px;\"\n />\n )}\n <h3>\n <a href={author.url?.href?.toString() ?? author.id.href}>\n {author.name}\n </a>\n </h3>{\" \"}\n <p>\n <span style=\"user-select: all;\">{authorHandle}</span>\n </p>\n </hgroup>\n )\n : <em>(Deleted account)</em>}\n </header>\n <div\n dangerouslySetInnerHTML={{\n __html: renderCustomEmojis(`${message.content}`, customEmojis),\n }}\n lang={message.content instanceof LanguageString\n ? message.content.language.compact()\n : undefined}\n />\n {attachments.length > 0 && (\n <div>\n {attachments.filter((a) =>\n a instanceof Image || a instanceof Document\n ).filter((a) => a.mediaType?.startsWith(\"image/\") && a.url != null)\n .map((a) => (\n <figure>\n <img\n src={a.url instanceof Link ? a.url.href?.href : a.url!.href}\n width={a.width ?? undefined}\n height={a.height ?? undefined}\n alt={a.name?.toString() ?? undefined}\n style=\"max-width: 75%;\"\n />\n <figcaption>{a.name?.toString()}</figcaption>\n </figure>\n ))}\n </div>\n )}\n <footer>\n {message.published &&\n (\n <a href={message.url?.href?.toString() ?? message.id?.href}>\n <small>\n <time dateTime={message.published.toString()}>\n {message.published.toLocaleString(\"en\", {\n dateStyle: \"full\",\n timeStyle: \"short\",\n })}\n </time>\n </small>\n </a>\n )}\n </footer>\n </article>\n );\n}\n\nconst HTML_ELEMENT_REGEXP = /<\\/?[^>]+>/g;\nconst CUSTOM_EMOJI_REGEXP = /:([a-z0-9_-]+):/gi;\n\nexport function renderCustomEmojis(\n html: string,\n emojis: Record<string, string>,\n): string {\n let result = \"\";\n let index = 0;\n for (const match of html.matchAll(HTML_ELEMENT_REGEXP)) {\n result += replaceEmojis(html.substring(index, match.index));\n result += match[0];\n index = match.index + match[0].length;\n }\n result += replaceEmojis(html.substring(index));\n return result;\n\n function replaceEmojis(html: string): string {\n return html.replaceAll(CUSTOM_EMOJI_REGEXP, (match) => {\n const emoji = emojis[match] ?? emojis[match.replace(/^:|:$/g, \"\")];\n if (emoji == null) return match;\n return `<img src=\"${emoji}\" alt=\"${match}\" style=\"height: 1em\">`;\n });\n }\n}\n"],"mappings":";;;;;;;;;AAiCA,eAAsB,QAAQ,EAAE,SAAS,SAAuB,EAAE;CAChE,MAAM,EAAE,SAAS,GAAG;CACpB,MAAM,SAAS,QAAQ,eAAe,SAAS,QAAQ,SAAS,OAC5D,MAAM,QAAQ,UAAU,GACxB,MAAM,QAAQ,eAAe;EAC7B,gBAAgB,QAAQ;EACxB,eAAe,QAAQ;EACvB,eAAe;CAChB,EAAC;CACJ,MAAM,aAAa,MAAM,QAAQ,QAAQ;EACvC,gBAAgB,QAAQ;EACxB,eAAe,QAAQ;EACvB,eAAe;CAChB,EAAC;CACF,MAAM,eAAe,UAAU,OAAO,OAAO,MAAM,eAAe,OAAO;CACzE,MAAM,cAAc,MAAM,MAAM,UAAU,QAAQ,gBAAgB,CAAC;CACnE,MAAM,OAAO,MAAM,MAAM,UAAU,QAAQ,SAAS,CAAC;CACrD,MAAMA,eAAuC,CAAE;AAC/C,MAAK,MAAM,OAAO,MAAM;AACtB,QAAM,eAAe,UAAU,IAAI,QAAQ,KAAM;EACjD,MAAM,OAAO,MAAM,IAAI,SAAS;AAChC,MAAI,MAAM,OAAO,KAAM;EACvB,MAAM,MAAM,KAAK,eAAe,OAAO,KAAK,IAAI,MAAM,OAAO,KAAK,IAAI;AACtE,MAAI,OAAO,KAAM;AACjB,eAAa,IAAI,KAAK,UAAU,IAAI;CACrC;AACD,wBACE,KAAC;kBACC,IAAC,sBACE,QAAQ,qBAEL,KAAC;GACE,YAAY,uBACX,IAAC;IACC,KAAK,WAAW,eAAe,OAC3B,WAAW,IAAI,MAAM,OACrB,WAAW,IAAI;IACnB,OAAO,WAAW;IAClB,QAAQ,WAAW;IACnB,KAAK,WAAW,MAAM,UAAU;IAChC,OAAM;KACN;mBAEJ,IAAC,kCACC,IAAC;IAAE,MAAM,OAAO,KAAK,MAAM,UAAU,IAAI,OAAO,GAAG;cAChD,OAAO;KACN,GACD;GAAC;mBACN,IAAC,iCACC,IAAC;IAAK,OAAM;cAAqB;KAAoB,GACnD;MACG,mBAET,IAAC,kBAAG,sBAAsB,GACvB;kBACT,IAAC;GACC,yBAAyB,EACvB,QAAQ,oBAAoB,EAAE,QAAQ,QAAQ,GAAG,aAAa,CAC/D;GACD,MAAM,QAAQ,mBAAmB,iBAC7B,QAAQ,QAAQ,SAAS,SAAS;IAEtC;EACD,YAAY,SAAS,qBACpB,IAAC,mBACE,YAAY,OAAO,CAAC,MACnB,aAAa,SAAS,aAAa,SACpC,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,WAAW,SAAS,IAAI,EAAE,OAAO,KAAK,CAChE,IAAI,CAAC,sBACJ,KAAC,uCACC,IAAC;GACC,KAAK,EAAE,eAAe,OAAO,EAAE,IAAI,MAAM,OAAO,EAAE,IAAK;GACvD,OAAO,EAAE;GACT,QAAQ,EAAE;GACV,KAAK,EAAE,MAAM,UAAU;GACvB,OAAM;IACN,kBACF,IAAC,0BAAY,EAAE,MAAM,UAAU,GAAc,IACtC,CACT,GACA;kBAER,IAAC,sBACE,QAAQ,6BAEL,IAAC;GAAE,MAAM,QAAQ,KAAK,MAAM,UAAU,IAAI,QAAQ,IAAI;6BACpD,IAAC,qCACC,IAAC;IAAK,UAAU,QAAQ,UAAU,UAAU;cACzC,QAAQ,UAAU,eAAe,MAAM;KACtC,WAAW;KACX,WAAW;IACZ,EAAC;KACG,GACD;IACN,GAED;KACD;AAEb;AAED,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAE5B,SAAgB,mBACdC,MACAC,QACQ;CACR,IAAI,SAAS;CACb,IAAI,QAAQ;AACZ,MAAK,MAAM,SAAS,KAAK,SAAS,oBAAoB,EAAE;AACtD,YAAU,cAAc,KAAK,UAAU,OAAO,MAAM,MAAM,CAAC;AAC3D,YAAU,MAAM;AAChB,UAAQ,MAAM,QAAQ,MAAM,GAAG;CAChC;AACD,WAAU,cAAc,KAAK,UAAU,MAAM,CAAC;AAC9C,QAAO;CAEP,SAAS,cAAcD,QAAsB;AAC3C,SAAO,OAAK,WAAW,qBAAqB,CAAC,UAAU;GACrD,MAAM,QAAQ,OAAO,UAAU,OAAO,MAAM,QAAQ,UAAU,GAAG;AACjE,OAAI,SAAS,KAAM,QAAO;AAC1B,WAAQ,YAAY,MAAM,SAAS,MAAM;EAC1C,EAAC;CACH;AACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
import { renderCustomEmojis } from "./Message.js";
|
|
6
|
+
import assert from "node:assert";
|
|
7
|
+
import { test } from "node:test";
|
|
8
|
+
|
|
9
|
+
//#region src/components/Message.test.tsx
|
|
10
|
+
test("renderCustomEmojis()", () => {
|
|
11
|
+
const emojis = {
|
|
12
|
+
":smile:": "https://example.com/smile.png",
|
|
13
|
+
":SmIlE:": "https://example.com/smile2.png",
|
|
14
|
+
":laughing:": "https://example.com/laughing.gif",
|
|
15
|
+
":thumbs_up:": "https://example.com/thumb.webp"
|
|
16
|
+
};
|
|
17
|
+
assert.equal(renderCustomEmojis("Hello :smile: world!", emojis), "Hello <img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"> world!");
|
|
18
|
+
assert.equal(renderCustomEmojis("Good morning :smile: :laughing:", emojis), "Good morning <img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"> <img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">");
|
|
19
|
+
assert.equal(renderCustomEmojis("Hi:smile:! How are you:laughing:?", emojis), "Hi<img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\">! How are you<img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">?");
|
|
20
|
+
assert.equal(renderCustomEmojis("This is an :unknown: emoji.", emojis), "This is an :unknown: emoji.");
|
|
21
|
+
assert.equal(renderCustomEmojis("<p>Hello <b>:smile:</b> world!</p>", emojis), "<p>Hello <b><img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"></b> world!</p>");
|
|
22
|
+
assert.equal(renderCustomEmojis("Check <a href=\"#\">this :thumbs_up:</a> link.", emojis), "Check <a href=\"#\">this <img src=\"https://example.com/thumb.webp\" alt=\":thumbs_up:\" style=\"height: 1em\"></a> link.");
|
|
23
|
+
assert.equal(renderCustomEmojis("<img alt=\":smile:\" src=\"pic.jpg\">", emojis), "<img alt=\":smile:\" src=\"pic.jpg\">");
|
|
24
|
+
assert.equal(renderCustomEmojis("Case :SmIlE: test", emojis), "Case <img src=\"https://example.com/smile2.png\" alt=\":SmIlE:\" style=\"height: 1em\"> test");
|
|
25
|
+
assert.equal(renderCustomEmojis("Great job :thumbs_up:", emojis), "Great job <img src=\"https://example.com/thumb.webp\" alt=\":thumbs_up:\" style=\"height: 1em\">");
|
|
26
|
+
assert.equal(renderCustomEmojis("", emojis), "");
|
|
27
|
+
assert.equal(renderCustomEmojis("<p><b>Hi</b></p>", emojis), "<p><b>Hi</b></p>");
|
|
28
|
+
assert.equal(renderCustomEmojis(":smile::laughing:", emojis), "<img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"><img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//# sourceMappingURL=Message.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.test.js","names":[],"sources":["../../src/components/Message.test.tsx"],"sourcesContent":["// BotKit by Fedify: A framework for creating ActivityPub bots\n// Copyright (C) 2025 Hong Minhee <https://hongminhee.org/>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as\n// published by the Free Software Foundation, either version 3 of the\n// License, or (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\nimport assert from \"node:assert\";\nimport { test } from \"node:test\";\nimport { renderCustomEmojis } from \"./Message.tsx\";\n\ntest(\"renderCustomEmojis()\", () => {\n const emojis = {\n \":smile:\": \"https://example.com/smile.png\",\n \":SmIlE:\": \"https://example.com/smile2.png\",\n \":laughing:\": \"https://example.com/laughing.gif\",\n \":thumbs_up:\": \"https://example.com/thumb.webp\",\n };\n\n // Test basic replacement\n assert.equal(\n renderCustomEmojis(\"Hello :smile: world!\", emojis),\n 'Hello <img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"> world!',\n );\n\n // Test multiple emojis\n assert.equal(\n renderCustomEmojis(\"Good morning :smile: :laughing:\", emojis),\n 'Good morning <img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"> <img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">',\n );\n\n // Test emojis adjacent to text\n assert.equal(\n renderCustomEmojis(\"Hi:smile:! How are you:laughing:?\", emojis),\n 'Hi<img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\">! How are you<img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">?',\n );\n\n // Test unknown emojis (should not be replaced)\n assert.equal(\n renderCustomEmojis(\"This is an :unknown: emoji.\", emojis),\n \"This is an :unknown: emoji.\",\n );\n\n // Test emojis mixed with HTML tags\n assert.equal(\n renderCustomEmojis(\"<p>Hello <b>:smile:</b> world!</p>\", emojis),\n '<p>Hello <b><img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"></b> world!</p>',\n );\n assert.equal(\n renderCustomEmojis(\n 'Check <a href=\"#\">this :thumbs_up:</a> link.',\n emojis,\n ),\n 'Check <a href=\"#\">this <img src=\"https://example.com/thumb.webp\" alt=\":thumbs_up:\" style=\"height: 1em\"></a> link.',\n );\n\n // Test emojis inside HTML attributes (should not be replaced)\n assert.equal(\n renderCustomEmojis('<img alt=\":smile:\" src=\"pic.jpg\">', emojis),\n '<img alt=\":smile:\" src=\"pic.jpg\">',\n );\n\n // Test case sensitivity\n assert.equal(\n renderCustomEmojis(\"Case :SmIlE: test\", emojis),\n 'Case <img src=\"https://example.com/smile2.png\" alt=\":SmIlE:\" style=\"height: 1em\"> test',\n );\n\n // Test emojis with underscores\n assert.equal(\n renderCustomEmojis(\"Great job :thumbs_up:\", emojis),\n 'Great job <img src=\"https://example.com/thumb.webp\" alt=\":thumbs_up:\" style=\"height: 1em\">',\n );\n\n // Test empty input\n assert.equal(renderCustomEmojis(\"\", emojis), \"\");\n\n // Test input with only HTML\n assert.equal(\n renderCustomEmojis(\"<p><b>Hi</b></p>\", emojis),\n \"<p><b>Hi</b></p>\",\n );\n\n // Test input with only emojis\n assert.equal(\n renderCustomEmojis(\":smile::laughing:\", emojis),\n '<img src=\"https://example.com/smile.png\" alt=\":smile:\" style=\"height: 1em\"><img src=\"https://example.com/laughing.gif\" alt=\":laughing:\" style=\"height: 1em\">',\n );\n});\n"],"mappings":";;;;;;;;;AAmBA,KAAK,wBAAwB,MAAM;CACjC,MAAM,SAAS;EACb,WAAW;EACX,WAAW;EACX,cAAc;EACd,eAAe;CAChB;AAGD,QAAO,MACL,mBAAmB,wBAAwB,OAAO,EAClD,iGACD;AAGD,QAAO,MACL,mBAAmB,mCAAmC,OAAO,EAC7D,yLACD;AAGD,QAAO,MACL,mBAAmB,qCAAqC,OAAO,EAC/D,2LACD;AAGD,QAAO,MACL,mBAAmB,+BAA+B,OAAO,EACzD,8BACD;AAGD,QAAO,MACL,mBAAmB,sCAAsC,OAAO,EAChE,+GACD;AACD,QAAO,MACL,mBACE,kDACA,OACD,EACD,4HACD;AAGD,QAAO,MACL,mBAAmB,yCAAqC,OAAO,EAC/D,wCACD;AAGD,QAAO,MACL,mBAAmB,qBAAqB,OAAO,EAC/C,+FACD;AAGD,QAAO,MACL,mBAAmB,yBAAyB,OAAO,EACnD,mGACD;AAGD,QAAO,MAAM,mBAAmB,IAAI,OAAO,EAAE,GAAG;AAGhD,QAAO,MACL,mBAAmB,oBAAoB,OAAO,EAC9C,mBACD;AAGD,QAAO,MACL,mBAAmB,qBAAqB,OAAO,EAC/C,2KACD;AACF,EAAC"}
|
package/dist/deno.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal, toTemporalInstant } from "@js-temporal/polyfill";
|
|
3
|
+
Date.prototype.toTemporalInstant = toTemporalInstant;
|
|
4
|
+
|
|
5
|
+
//#region deno.json
|
|
6
|
+
var name = "@fedify/botkit";
|
|
7
|
+
var version = "0.3.0-dev.108+5ff4003a";
|
|
8
|
+
var license = "AGPL-3.0-only";
|
|
9
|
+
var unstable = ["kv", "temporal"];
|
|
10
|
+
var exports = {
|
|
11
|
+
".": "./src/mod.ts",
|
|
12
|
+
"./bot": "./src/bot.ts",
|
|
13
|
+
"./emoji": "./src/emoji.ts",
|
|
14
|
+
"./events": "./src/events.ts",
|
|
15
|
+
"./follow": "./src/follow.ts",
|
|
16
|
+
"./message": "./src/message.ts",
|
|
17
|
+
"./reaction": "./src/reaction.ts",
|
|
18
|
+
"./session": "./src/session.ts",
|
|
19
|
+
"./text": "./src/text.ts"
|
|
20
|
+
};
|
|
21
|
+
var imports = {
|
|
22
|
+
"@fedify/fedify": "jsr:@fedify/fedify@^1.6.1",
|
|
23
|
+
"@fedify/markdown-it-hashtag": "jsr:@fedify/markdown-it-hashtag@^0.3.0",
|
|
24
|
+
"@fedify/markdown-it-mention": "jsr:@fedify/markdown-it-mention@^0.3.0",
|
|
25
|
+
"@logtape/logtape": "jsr:@logtape/logtape@^1.0.0",
|
|
26
|
+
"@phensley/language-tag": "npm:@phensley/language-tag@^1.12.2",
|
|
27
|
+
"hono": "jsr:@hono/hono@^4.8.2",
|
|
28
|
+
"html-entities": "npm:html-entities@^2.6.0",
|
|
29
|
+
"markdown-it": "npm:markdown-it@^14.1.0",
|
|
30
|
+
"mime-db": "npm:mime-db@^1.54.0",
|
|
31
|
+
"tsdown": "npm:tsdown@^0.12.8",
|
|
32
|
+
"uuid": "npm:uuid@^11.1.0",
|
|
33
|
+
"x-forwarded-fetch": "jsr:@hongminhee/x-forwarded-fetch@^0.2.0",
|
|
34
|
+
"xss": "npm:xss@^1.0.15"
|
|
35
|
+
};
|
|
36
|
+
var nodeModulesDir = "none";
|
|
37
|
+
var exclude = [
|
|
38
|
+
".github",
|
|
39
|
+
".vscode",
|
|
40
|
+
"dist",
|
|
41
|
+
"docs",
|
|
42
|
+
"src/css"
|
|
43
|
+
];
|
|
44
|
+
var fmt = { "exclude": [
|
|
45
|
+
"*.md",
|
|
46
|
+
"*.yaml",
|
|
47
|
+
"*.yml",
|
|
48
|
+
"src/static/*.ts"
|
|
49
|
+
] };
|
|
50
|
+
var tasks = {
|
|
51
|
+
"check": "deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty && deno run scripts/check_versions.ts",
|
|
52
|
+
"test": "deno test --allow-env=NODE_V8_COVERAGE,JEST_WORKER_ID --allow-net=hollo.social --parallel",
|
|
53
|
+
"test-all": "deno task check && deno task test",
|
|
54
|
+
"coverage": "deno task test --coverage --clean && deno coverage --html",
|
|
55
|
+
"hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks",
|
|
56
|
+
"hooks:pre-commit": "deno task check"
|
|
57
|
+
};
|
|
58
|
+
var deno_default = {
|
|
59
|
+
name,
|
|
60
|
+
version,
|
|
61
|
+
license,
|
|
62
|
+
unstable,
|
|
63
|
+
exports,
|
|
64
|
+
imports,
|
|
65
|
+
nodeModulesDir,
|
|
66
|
+
exclude,
|
|
67
|
+
fmt,
|
|
68
|
+
tasks
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { deno_default as default };
|
|
73
|
+
//# sourceMappingURL=deno.js.map
|
package/dist/deno.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno.js","names":[],"sources":["../deno.json"],"sourcesContent":["{\n \"name\": \"@fedify/botkit\",\n \"version\": \"0.3.0-dev.108+5ff4003a\",\n \"license\": \"AGPL-3.0-only\",\n \"unstable\": [\n \"kv\",\n \"temporal\"\n ],\n \"exports\": {\n \".\": \"./src/mod.ts\",\n \"./bot\": \"./src/bot.ts\",\n \"./emoji\": \"./src/emoji.ts\",\n \"./events\": \"./src/events.ts\",\n \"./follow\": \"./src/follow.ts\",\n \"./message\": \"./src/message.ts\",\n \"./reaction\": \"./src/reaction.ts\",\n \"./session\": \"./src/session.ts\",\n \"./text\": \"./src/text.ts\"\n },\n \"imports\": {\n \"@fedify/fedify\": \"jsr:@fedify/fedify@^1.6.1\",\n \"@fedify/markdown-it-hashtag\": \"jsr:@fedify/markdown-it-hashtag@^0.3.0\",\n \"@fedify/markdown-it-mention\": \"jsr:@fedify/markdown-it-mention@^0.3.0\",\n \"@logtape/logtape\": \"jsr:@logtape/logtape@^1.0.0\",\n \"@phensley/language-tag\": \"npm:@phensley/language-tag@^1.12.2\",\n \"hono\": \"jsr:@hono/hono@^4.8.2\",\n \"html-entities\": \"npm:html-entities@^2.6.0\",\n \"markdown-it\": \"npm:markdown-it@^14.1.0\",\n \"mime-db\": \"npm:mime-db@^1.54.0\",\n \"tsdown\": \"npm:tsdown@^0.12.8\",\n \"uuid\": \"npm:uuid@^11.1.0\",\n \"x-forwarded-fetch\": \"jsr:@hongminhee/x-forwarded-fetch@^0.2.0\",\n \"xss\": \"npm:xss@^1.0.15\"\n },\n \"nodeModulesDir\": \"none\",\n \"exclude\": [\n \".github\",\n \".vscode\",\n \"dist\",\n \"docs\",\n \"src/css\"\n ],\n \"fmt\": {\n \"exclude\": [\n \"*.md\",\n \"*.yaml\",\n \"*.yml\",\n \"src/static/*.ts\"\n ]\n },\n \"tasks\": {\n \"check\": \"deno check src/ && deno lint && deno fmt --check && deno publish --dry-run --allow-dirty && deno run scripts/check_versions.ts\",\n \"test\": \"deno test --allow-env=NODE_V8_COVERAGE,JEST_WORKER_ID --allow-net=hollo.social --parallel\",\n \"test-all\": \"deno task check && deno task test\",\n \"coverage\": \"deno task test --coverage --clean && deno coverage --html\",\n \"hooks:install\": \"deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks\",\n \"hooks:pre-commit\": \"deno task check\"\n }\n}\n"],"mappings":";;;;;WACU;cACG;cACA;eACC,CACV,MACA,UACD;cACU;CACT,KAAK;CACL,SAAS;CACT,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,aAAa;CACb,cAAc;CACd,aAAa;CACb,UAAU;AACX;cACU;CACT,kBAAkB;CAClB,+BAA+B;CAC/B,+BAA+B;CAC/B,oBAAoB;CACpB,0BAA0B;CAC1B,QAAQ;CACR,iBAAiB;CACjB,eAAe;CACf,WAAW;CACX,UAAU;CACV,QAAQ;CACR,qBAAqB;CACrB,OAAO;AACR;qBACiB;cACP;CACT;CACA;CACA;CACA;CACA;AACD;UACM,EACL,WAAW;CACT;CACA;CACA;CACA;AACD,EACF;YACQ;CACP,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,YAAY;CACZ,iBAAiB;CACjB,oBAAoB;AACrB;mBAzDH;;;;;;;;;;;AA0DC"}
|