Skip to content

Commit

Permalink
fix(lark): quote command args from input
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 9, 2025
1 parent cea115a commit 1858596
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions adapters/lark/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,31 @@ export async function adaptSession<C extends Context>(bot: LarkBot<C>, body: Eve
if (body.event.action.value?._satori_type === 'command') {
session.type = 'interaction/command'
let content = body.event.action.value.content
const args = [], options = Object.create(null)
const args: any[] = [], options = Object.create(null)
for (const [key, value] of Object.entries(body.event.action.form_value ?? {})) {
if (+key * 0 === 0) {
args[+key] = value
} else {
options[key] = value
}
}
for (let i = 0; i < args.length; ++i) {
if (i in args) {
content += ` ${args[i]}`
const toArg = (value: any) => {
if (typeof value === 'string') {
return `'${value}'`
} else if (typeof value === 'number') {
return value
} else {
content += ` ''`
return `''`
}
}
for (let i = 0; i < args.length; ++i) {
content += ` ${toArg(args[i])}`
}
for (const [key, value] of Object.entries(options)) {
content += ` --${key} ${value}`
content += ` --${key} ${toArg(value)}`
}
if (body.event.action.input_value) {
content += ` ${body.event.action.input_value}`
content += ` ${toArg(body.event.action.input_value)}`
}
session.content = content
session.messageId = body.event.context.open_message_id
Expand Down

0 comments on commit 1858596

Please sign in to comment.