Skip to content

其他工具函数

substitudeMacros

替换字符串中的 SillyTavern 宏。

typescript
async function substitudeMacros(text: string): Promise<string>;

参数

text

  • 类型: string
  • 描述: 需要替换的字符串

返回值

  • 替换结果: string

示例

typescript
const text = substitudeMacros("{{char}} speaks in {{lastMessageId}}");
text == "少女歌剧 speaks in 5";

registerMacroLike

注册一个新的助手宏。

typescript
function registerMacroLike(
  regex: RegExp,
  replace: (context: Context, substring: string, ...args: any[]) => string,
): void;

参数

regex

  • 类型: RegExp
  • 描述: 匹配的正则表达式

replace

  • 类型: (context: Context, substring: string, ...args: any[]) => string
  • 描述: 针对匹配到的文本所要进行的替换

示例

typescript
registerMacroLike(
  /<checkbox>(.*?)<checkbox>/gi,
  (context: Context, substring: string, content: string) => { return content; });

getIframeName 🚫TavernHelper

获取 iframe 的名称。

typescript
function getIframeName(): string;

返回值

  • iframe 名称: string
    • 对于楼层消息是 message-iframe-楼层id-是该楼层第几个iframe
    • 对于全局脚本是 script-iframe-脚本名称

getMessageId 🚫TavernHelper

从消息楼层 iframe 的 iframe_name 获取它所在楼层的楼层 id。

只能对楼层消息 iframe 使用

typescript
function getMessageId(iframe_name: string): number;

参数

iframe_name

  • 类型: string
  • 描述: 消息楼层 iframe 的名称

返回值

  • 楼层 id: number

getCurrentMessageId 🚫TavernHelper

获取本消息楼层 iframe 所在楼层的楼层 id。

只能对楼层消息 iframe 使用

typescript
function getCurrentMessageId(): number;

返回值

  • 楼层 id: number

getLastMessageId

获取最新楼层 id。

typescript
async function getLastMessageId(): Promise<number>;

返回值

  • 最新楼层 id: number

getScriptId 🚫TavernHelper

获取脚本库的脚本 id。

typescript
function getScriptId(): string;

返回值

  • 脚本 id: string

toastr

导出了 toastr 库, 你现在可以用 toastr.error('内容', '标题') 而不是 triggerSlash('/echo severity=error title=标题 内容') 来进行酒馆提示了

  • toastr.info
  • toastr.success
  • toastr.warning
  • toastr.error

作者:KAKAA, 青空莉想做舞台少女的狗