This commit is contained in:
Evgeny @ SimpleX Chat
2026-09-25 11:16:29 +00:00
parent 9f0ed3ac65
commit 57aea5963f
3 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ Each user who connects via the bot's business address receives a calculator mess
- Tap `C` to clear the number, and `C` again to clear the calculation.
- Numbers are shown without exponent, up to 15 digits; larger results are shown as `Error`.
- You can also send numbers and keys like `+`, `=`, `add` or `c`. Expressions like `(2 + 3) × 4` are entered as one number, and the bot replies to them with the result.
- The bot deletes tapped keys and sends each calculation after `=`.
- The bot deletes keys and numbers, tapped or sent, and sends each calculation after `=`.
- After 10 minutes without input, the bot turns the calculator off and discards the calculation; tap any key to turn it on.
- The bot sends keys like `/+` to apps with chat protocol version 21 or later, and keys like `/add` to older apps.
@@ -44,6 +44,8 @@ test("calculator in business chat", async () => {
await alice.startChat()
await useSmpServer(alice)
const receives = (check: ItemCheck) => alice.wait("newChatItems", ({chatItems}) => chatItems.some(check), 30000)
const deletes = (text: string) =>
alice.wait("chatItemsDeleted", ({chatItemDeletions}) => chatItemDeletions.some(({deletedChatItem}) => hasText(text)(deletedChatItem)), 30000)
try {
const [_plan, link] = await alice.apiConnectPlan(aliceUser.userId, util.contactAddressStr(address!.connLinkContact))
const firstCalculator = receives(calculatorShows("0"))
@@ -51,14 +53,13 @@ test("calculator in business chat", async () => {
const calculatorItem = (await firstCalculator)?.chatItems.find(calculatorShows("0"))
expect(calculatorItem?.chatInfo.type).toBe(T.ChatType.Group)
const groupId = (calculatorItem!.chatInfo as T.ChatInfo.Group).groupInfo.groupId
const send = async (texts: string[], ...checks: ItemCheck[]) => {
const received = checks.map(receives)
const send = async (texts: string[], ...events: Promise<unknown>[]) => {
for (const text of texts) await alice.apiSendTextMessage([T.ChatType.Group, groupId], text)
for (const event of received) expect(await event).toBeDefined()
for (const event of events) expect(await event).toBeDefined()
}
await send(["/2", "/+", "/2", "/="], hasText("2 + 2 = 4"), calculatorShows("4"))
await send(["2 × (3 + 4) - 1"], repliesTo("2 × (3 + 4) - 1", "= 13"), calculatorShows("13"))
await send(["25", "+", "25", "="], hasText("25 + 25 = 50"), calculatorShows("50"))
await send(["/2", "/+", "/2", "/="], receives(hasText("2 + 2 = 4")), receives(calculatorShows("4")), deletes("/+"))
await send(["2 × (3 + 4) - 1"], receives(repliesTo("2 × (3 + 4) - 1", "13")), receives(calculatorShows("13")))
await send(["25", "+", "25", "="], receives(hasText("25 + 25 = 50")), receives(calculatorShows("50")), deletes("+"))
} finally {
await alice.close()
await calculator.close()
@@ -73,7 +73,8 @@ async function onMessage(ci: T.AChatItem, content: T.MsgContent, chat: api.ChatA
await chat.apiSendTextReply(ci, hint)
return
}
if (input.result) await chat.apiSendTextReply(ci, `= ${input.result}`)
if (input.result) await chat.apiSendTextReply(ci, input.result)
else await chat.apiDeleteMemberChatItem(sender.groupId, [ci.chatItem.meta.itemId])
await updateCalculator(chat, sender, input.update)
}