-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ==Extension== | ||
// @name Interactions | ||
// @version 1.0.0 | ||
// @description 允许大模型在聊群内进行交互 | ||
// @author HydroGest | ||
// ==/Extension== | ||
|
||
import { Description, Extension, Name, Param } from "./base"; | ||
|
||
@Name("reaction-create") | ||
@Description(` | ||
在当前频道对一个或多个消息进行表态。表态编号是数字,这里是一个简略的参考:惊讶(0),不适(1),无语(27),震惊(110),滑稽(178), 点赞(76) | ||
`) | ||
@Param("message", "消息 ID") | ||
@Param("emoji_id", "表态编号") | ||
export class Reaction extends Extension { | ||
async apply(message: number, emoji_id: number) { | ||
try { | ||
// @ts-ignore | ||
await this.session.onebot._request("set_msg_emoji_like", { message_id: message, emoji_id: emoji_id}); | ||
this.ctx.logger.info(`Bot[${this.session.selfId}]对消息 ${message} 进行了表态: ${emoji_id}`); | ||
} catch (e) { | ||
this.ctx.logger.error(`Bot[${this.session.selfId}]执行表态失败: ${message}, ${emoji_id} - `, e.message); | ||
} | ||
} | ||
} | ||
|
||
@Name("essence-create") | ||
@Description(` | ||
在当前频道将一个消息设置为精华消息。常在你认为某个消息十分重要或过于典型时使用。 | ||
`) | ||
@Param("message", "消息 ID") | ||
export class Essence extends Extension { | ||
async apply(message: number) { | ||
try { | ||
// @ts-ignore | ||
await this.session.onebot._request("set_essence_msg", { message_id: message}) | ||
this.ctx.logger.info(`Bot[${this.session.selfId}]将消息 ${message} 设置为精华`); | ||
} catch (e) { | ||
this.ctx.logger.error(`Bot[${this.session.selfId}]设置精华消息失败: ${message} - `, e.message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
/** | ||
* 从指定的 TypeScript 文件中读取元数据。 | ||
* | ||
* 该函数读取文件内容,查找以 `// ==Extension==` 开始和 `// ==/Extension==` 结束的部分,并提取其中以 `// @` 开头的元数据信息。 | ||
* 元数据信息存储在一个对象中,键是 `@` 后面的标识符,值是标识符后面的描述信息。 | ||
* | ||
* @param filePath - 要读取元数据的 TypeScript 文件的路径。 | ||
* @returns 一个包含元数据的对象,键是元数据标识符(如 `name`、`version`、`description` 等),值是相应的元数据信息。如果不是预期格式则返回空对象。 | ||
* | ||
*/ | ||
export function readMetadata(filePath: string): { [key: string]: string } { | ||
try { | ||
const content = fs.readFileSync(path.resolve(filePath), 'utf-8'); | ||
const metadata: { [key: string]: string } = {}; | ||
const lines = content.split('\n'); | ||
let capturing = false; | ||
for (const line of lines) { | ||
if (line.trim() === '// ==Extension==') { | ||
capturing = true; | ||
continue; | ||
} | ||
if (line.trim() === '// ==/Extension==') { | ||
capturing = false; | ||
continue; | ||
} | ||
if (capturing) { | ||
if (line.trim().startsWith('// @')) { | ||
const parts = line.trim().substring(3).split(' '); | ||
const key = parts[0]; | ||
const value = parts.slice(1).join(' '); | ||
metadata[key] = value; | ||
} | ||
} | ||
} | ||
return metadata; | ||
} catch (error) { | ||
console.error(`Error reading file: ${error}`); | ||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters