From 8f68c0ac6fbb782c64eaed98be45f983a07aba46 Mon Sep 17 00:00:00 2001 From: tuanddd Date: Mon, 11 Sep 2023 13:13:24 +0700 Subject: [PATCH 1/6] fix(sup): change /sup to /changelog and only show latest --- src/commands/{sup => changelog}/index.ts | 8 ++++---- src/commands/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/commands/{sup => changelog}/index.ts (91%) diff --git a/src/commands/sup/index.ts b/src/commands/changelog/index.ts similarity index 91% rename from src/commands/sup/index.ts rename to src/commands/changelog/index.ts index c0106737e..73b6a32f7 100644 --- a/src/commands/sup/index.ts +++ b/src/commands/changelog/index.ts @@ -7,11 +7,11 @@ import UI, { Platform } from "@consolelabs/mochi-ui" import Discord from "discord.js" const slashCmd: SlashCommand = { - name: "sup", + name: "changelog", category: "Community", prepare: () => { const data = new SlashCommandBuilder() - .setName("sup") + .setName("changelog") .setDescription("Check what's new with Mochi") return data }, @@ -22,7 +22,7 @@ const slashCmd: SlashCommand = { if (!ok) return { messageOptions: { - content: "Cannot show changelogs", + content: "Cannot show latest changelog", }, } const { changelog, markRead } = await api.getLatestChangelog(profile.id) @@ -41,7 +41,7 @@ const slashCmd: SlashCommand = { await i.editReply({ embeds: [ composeEmbedMessage2(i, { - author: ["Changelog", thumbnails.MOCHI], + author: ["", thumbnails.MOCHI], description: text, }), ], diff --git a/src/commands/index.ts b/src/commands/index.ts index 7d6bd8d00..41fd19e36 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -92,7 +92,7 @@ import ecocalView from "./ecocal/view/slash" import chotot from "./chotot" import proposal from "./proposal" import guess from "./guess" -import sup from "./sup" +import changelog from "./changelog" import v from "./v" CacheManager.init({ @@ -167,7 +167,7 @@ export const slashCommands: Record = { chotot: chotot.slashCmd, proposal: proposal.slashCmd, guess: guess.slashCmd, - sup: sup.slashCmd, + changelog: changelog.slashCmd, v: v.slashCmd, } From ffcf61ee042c0cb9a45bb950d7882c5cbd2df82c Mon Sep 17 00:00:00 2001 From: Ngo Trong Khoi <39881166+trkhoi@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:44:18 +0700 Subject: [PATCH 2/6] feat(tip): show moniker (if any) + message when tipping --- src/commands/tip/index/processor.ts | 57 +++++++++++++++++++++++------ src/types/transfer.ts | 1 + 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/commands/tip/index/processor.ts b/src/commands/tip/index/processor.ts index 3e01101a1..69f121187 100644 --- a/src/commands/tip/index/processor.ts +++ b/src/commands/tip/index/processor.ts @@ -57,8 +57,17 @@ export async function tip( const onchain = equalIgnoreCase(args.at(-1), "--onchain") args = args.slice(0, onchain ? -1 : undefined) // remove --onchain if any - const { targets, amount, symbol, each, all, message, image, moniker } = - await parseTipArgs(msgOrInteraction, args) + const { + targets, + amount, + symbol, + each, + all, + message, + image, + moniker, + originalAmount, + } = await parseTipArgs(msgOrInteraction, args) // get sender balances const balances = await getBalances({ msgOrInteraction, token: symbol }) @@ -97,6 +106,7 @@ export async function tip( chain_id: "", moniker: "", platform: "discord", + original_amount: originalAmount, } if (moniker !== undefined) { @@ -233,21 +243,36 @@ function showSuccesfulResponse( }` } - const amount = `${formatDigit({ + const unitCurrency = payload.moniker ? payload.moniker : payload.token + const amountToken = `${getEmojiToken(payload.token)} ${formatDigit({ value: res.amount_each.toString(), fractionDigits: payload.decimal, })} ${payload.token}` - - const amountApprox = `(${APPROX} $${roundFloatNumber( + const amountApproxMoniker = payload.moniker ? `${amountToken} ` : "" + const amount = payload.moniker + ? payload.original_amount + : `${formatDigit({ + value: res.amount_each.toString(), + fractionDigits: payload.decimal, + })}` + const emojiAmountWithCurrency = payload.moniker + ? "" + : getEmojiToken(payload.token) + let amountWithCurrency = `${emojiAmountWithCurrency} ${amount} ${unitCurrency}` + amountWithCurrency = amountWithCurrency.trim() + + const amountApprox = `(${amountApproxMoniker}${APPROX} $${roundFloatNumber( res.amount_each * payload.token_price, 4, )})` + let contentMsg = `` + let description = `${getEmoji("PROPOSAL")}\`Tx ID. ${ res.tx_id ?? "N/A" }\`\n${getEmoji("NFT2")}\`Amount. \`${getEmojiToken( payload.token, - )} **${amount}** ${amountApprox} ${ + )} **${amountWithCurrency}** ${amountApprox} ${ payload.recipients.length > 1 ? "each" : "" }\n${getEmoji("ANIMATED_MONEY", true)}\`Sender. \`${userMention( payload.sender, @@ -256,6 +281,7 @@ function showSuccesfulResponse( description += `\n${getEmoji("ANIMATED_ROBOT", true)}\`Message. \`${ payload.message }` + contentMsg += `\n${getEmoji("CHAT", true)}\` Message. \`${payload.message}` } const embed = composeEmbedMessage(null, { author: [ @@ -273,13 +299,11 @@ function showSuccesfulResponse( messageOptions: { content: `${userMention( payload.sender, - )} has sent ${recipientDescription} ${getEmojiToken( - payload.token, - )} **${amount}** ${amountApprox}${ + )} sent ${recipientDescription} **${amountWithCurrency}** ${amountApprox}${ payload.recipients.length > 1 ? " each" : "" }! .[${res.external_id.slice(0, 5)}](${HOMEPAGE_URL}/transfer/${ res.external_id - })`, + })${contentMsg}`, components: [], }, } @@ -297,6 +321,7 @@ export async function parseTipArgs( each: boolean all: boolean moniker: any + originalAmount: number }> { const { valid, targets, lastIdx: lastTargetIdx } = getTargets(args) if (!valid) { @@ -353,7 +378,17 @@ export async function parseTipArgs( const { message: msg } = isMessage(msgOrInteraction) const image = msg ? msg.attachments.first()?.url ?? "" : "" - return { targets, amount, symbol, each, message, all, image, moniker } + return { + targets, + amount, + symbol, + each, + message, + all, + image, + moniker, + originalAmount: parsedAmount, + } } export async function validateAndTransfer( diff --git a/src/types/transfer.ts b/src/types/transfer.ts index 978ba5e70..c6ed76d4e 100644 --- a/src/types/transfer.ts +++ b/src/types/transfer.ts @@ -19,6 +19,7 @@ export type TransferPayload = { token_price?: number decimal?: number moniker?: string + original_amount?: number } export type AirdropOptions = { From 71f39d897567e23b316f6a7f9204008dd429f8b5 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 12 Sep 2023 02:55:42 +0000 Subject: [PATCH 3/6] chore(release): 6.31.0-rc.1 [skip ci] # [6.31.0-rc.1](https://github.com/consolelabs/mochi-discord/compare/v6.30.1...v6.31.0-rc.1) (2023-09-12) ### Bug Fixes * **sup:** change /sup to /changelog and only show latest ([8f68c0a](https://github.com/consolelabs/mochi-discord/commit/8f68c0ac6fbb782c64eaed98be45f983a07aba46)) ### Features * **tip:** show moniker (if any) + message when tipping ([ffcf61e](https://github.com/consolelabs/mochi-discord/commit/ffcf61ee042c0cb9a45bb950d7882c5cbd2df82c)) --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88b7ccabb..3fd6a6338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# [6.31.0-rc.1](https://github.com/consolelabs/mochi-discord/compare/v6.30.1...v6.31.0-rc.1) (2023-09-12) + + +### Bug Fixes + +* **sup:** change /sup to /changelog and only show latest ([8f68c0a](https://github.com/consolelabs/mochi-discord/commit/8f68c0ac6fbb782c64eaed98be45f983a07aba46)) + + +### Features + +* **tip:** show moniker (if any) + message when tipping ([ffcf61e](https://github.com/consolelabs/mochi-discord/commit/ffcf61ee042c0cb9a45bb950d7882c5cbd2df82c)) + ## [6.30.1](https://github.com/consolelabs/mochi-discord/compare/v6.30.0...v6.30.1) (2023-09-11) diff --git a/package.json b/package.json index 114cad040..932425efb 100644 --- a/package.json +++ b/package.json @@ -113,5 +113,5 @@ "node": "18.x" }, "name": "mochi-discord", - "version": "6.30.1" + "version": "6.31.0-rc.1" } From 46c6d7ae6d5a7436f6555c1dda8df138fff33734 Mon Sep 17 00:00:00 2001 From: tuanddd Date: Tue, 12 Sep 2023 10:03:58 +0700 Subject: [PATCH 4/6] fix(general): re-sync emojis: SPELL, BTC, SOL, ... --- src/utils/common.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index 389a8a573..e4b112a69 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -58,23 +58,23 @@ export const tokenEmojis = { TOMB: "967285237904179211", REAPER: "967285238306857063", BOO: "967285238042599434", - SPELL: "967285238063587358", - BTC: "1113114845752070144", + SPELL: "1150806619920273428", + BTC: "1150601628559360010", ETH: "1113120035783856209", WETH: "1052849700019109889", - BNB: "1113114859794599977", + BNB: "1150601624461508688", CAKE: "1113114867361120287", OP: "1113120107107987568", - USDT: "1113120155568971786", - USDC: "1005010675342520382", + USDT: "1150601617629003858", + USDC: "1150601614676197417", ADA: "1005010608443359272", XRP: "1005010559856554086", BUSD: "1005010097535197264", DOT: "1005009972716908554", DOGE: "1004962950756454441", DAI: "1005009904433647646", - MATIC: "1037985931816349746", - WMATIC: "1037985931816349746", + MATIC: "1150601602835685456", + WMATIC: "1150806619920273428", AVAX: "1113114813455937579", UNI: "1005012087967334443", SHIB: "1005009723277463703", @@ -92,7 +92,7 @@ export const tokenEmojis = { XLM: "1113115466727170208", XMR: "1005008819866312724", BCH: "1121653562326397012", - APE: "1005008782486675536", + APE: "1150805766178078780", DFG: "1007157463256145970", ICY: "1049620715374133288", CARROT: "1113154879779786773", @@ -108,22 +108,22 @@ export const tokenEmojis = { MKR: "1037985596964081696", ANC: "1037985575334051901", BRUSH: "1113120008684441631", - SOL: "1006838270862295080", - SOLANA: "1006838270862295080", + SOL: "1150803875884978216", + SOLANA: "1150803875884978216", APT: "1047707078183096320", - APTOS: "1047707078183096320", + APTOS: "1150803860827426839", RON: "1047707529884483614", WRON: "1047707529884483614", - ARB: "1056772215477112862", + ARB: "1150809015434104884", OKC: "1006838263165767681", ONUS: "1077203550075093053", - SUI: "1113115401132462172", + SUI: "1150601612440633424", FBOMB: "1113114920360353824", MCLB: "1113114976350122005", POL: "1037985931816349746", SAMO: "1095714152221261905", BONK: "1095714104108388362", - STG: "1097786444057169941", + STG: "1150989167992508508", ASTAR: "1113114810012422245", LUNC: "1113114970239017031", ETHW: "1113114916757446718", @@ -155,6 +155,7 @@ export const tokenEmojis = { BAY: "1113114831755673712", THE: "1113115413270769715", BASED: "1115120132289724476", + BASE: "1150810490012958800", KAS: "1113114949342994543", AIDOGE: "1113114778001481869", SOLID: "1113115381184331929", @@ -188,7 +189,7 @@ export const tokenEmojis = { HOOK: "1113120062979715122", PERP: "1113120116171866182", AHE: "1113115806302224414", - ICP: "1006838249676873758", + ICP: "1150803870080057359", XCAL: "1113120173214416906", WGMI: "1113120161621344346", SKULL: "1113115377153613877", @@ -201,7 +202,7 @@ export const tokenEmojis = { ALGO: "1006838257843179520", BSGG: "1113120013155586158", FUSD: "1113120058600857682", - AXS: "1006838225899368478", + AXS: "1150803865948651560", FCTR: "1113120040657625159", UNIDX: "1113120144793800754", KAI: "1113120080151199824", From 5f8228d3d511b241cb52ec97295e0f1bf8a3ed22 Mon Sep 17 00:00:00 2001 From: tuanddd Date: Tue, 12 Sep 2023 10:25:22 +0700 Subject: [PATCH 5/6] fix(general): remove what's new footer, /changelog always show latest --- package.json | 10 +++++----- pnpm-lock.yaml | 20 ++++++++++---------- src/commands/changelog/index.ts | 13 +------------ src/index.ts | 33 +-------------------------------- 4 files changed, 17 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index b54e13aa0..5bc311ce3 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ }, "dependencies": { "@bonfida/spl-name-service": "^1.0.11", - "@consolelabs/mochi-rest": "^2.0.0", - "@consolelabs/mochi-ui": "^9.0.2", + "@consolelabs/mochi-rest": "^2.0.5", + "@consolelabs/mochi-ui": "^9.1.8", "@discordjs/builders": "^0.12.0", "@discordjs/rest": "^0.5.0", "@haileybot/captcha-generator": "^1.7.0", @@ -65,6 +65,7 @@ "dotenv": "^10.0.0", "emoji-regex": "^10.2.1", "ethers": "^5.4.7", + "fetch-to-curl": "^0.5.2", "fuzzyset": "^1.0.7", "ioredis": "^5.3.2", "kafkajs": "^2.2.3", @@ -89,11 +90,10 @@ "type-fest": "^3.12.0", "vite": "^4.3.9", "vite-node": "^0.32.4", - "vite-tsconfig-paths": "^4.2.0", "vite-plugin-checker": "^0.6.1", + "vite-tsconfig-paths": "^4.2.0", "ws": "^8.12.0", - "xstate": "^4.37.2", - "fetch-to-curl": "^0.5.2" + "xstate": "^4.37.2" }, "lint-staged": { "*.{js,ts}": "eslint --cache --fix", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7eef71b3..4f938fd59 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,11 +12,11 @@ dependencies: specifier: ^1.0.11 version: 1.0.11(@solana/web3.js@1.73.2) '@consolelabs/mochi-rest': - specifier: ^2.0.0 - version: 2.0.0 + specifier: ^2.0.5 + version: 2.0.5 '@consolelabs/mochi-ui': - specifier: ^9.0.2 - version: 9.0.2(@consolelabs/mochi-rest@2.0.0)(ioredis@5.3.2) + specifier: ^9.1.8 + version: 9.1.8(@consolelabs/mochi-rest@2.0.5)(ioredis@5.3.2) '@discordjs/builders': specifier: ^0.12.0 version: 0.12.0 @@ -734,8 +734,8 @@ packages: dev: true optional: true - /@consolelabs/mochi-rest@2.0.0: - resolution: {integrity: sha512-HR9FJgFkGhlQ7mXwsKPu1BIMhCknsvEZW/7ErgUocPsR5C+uGKqS+VRfqBuT1IIU2N8MVQDugzsKuOg1NvShfg==} + /@consolelabs/mochi-rest@2.0.5: + resolution: {integrity: sha512-7dIZadPksX+h68mIlQtWjh8vTHMMmh6ULBge7LKXyash5AXTJ9IVbksHlNFxZYf69AuiHvTHAnqyV1Zdjd+LSA==} dependencies: deepmerge: 4.3.1 lodash.snakecase: 4.1.1 @@ -747,14 +747,14 @@ packages: zod: 3.22.2 dev: false - /@consolelabs/mochi-ui@9.0.2(@consolelabs/mochi-rest@2.0.0)(ioredis@5.3.2): - resolution: {integrity: sha512-GM8ICIjll7noPQu9RHDR8RRlOogmSn2HJMfd+Wtf7LkVYn3j0IQhIHQIRpYHkndUcccw/zi3joaSPsVtt1SmTQ==} + /@consolelabs/mochi-ui@9.1.8(@consolelabs/mochi-rest@2.0.5)(ioredis@5.3.2): + resolution: {integrity: sha512-xPmPkbyNeFsApBO10NWCay2JUSzkzAR2KdaIW3Vj8e8LV+m0ABHmsYhFsrj5qFKQDYAG8kvOZ3+9Og2EoUtrzg==} peerDependencies: - '@consolelabs/mochi-rest': ^2.0.0 + '@consolelabs/mochi-rest': ^2.0.5 ioredis: ^5.x.x dependencies: '@bonfida/spl-name-service': 1.0.11(@solana/web3.js@1.78.4) - '@consolelabs/mochi-rest': 2.0.0 + '@consolelabs/mochi-rest': 2.0.5 '@solana/web3.js': 1.78.4 change-case: 4.1.2 ethers: 6.7.1 diff --git a/src/commands/changelog/index.ts b/src/commands/changelog/index.ts index 73b6a32f7..6af6c5c8c 100644 --- a/src/commands/changelog/index.ts +++ b/src/commands/changelog/index.ts @@ -16,16 +16,7 @@ const slashCmd: SlashCommand = { return data }, run: async function (i) { - const { ok, data: profile } = await api.profile.discord.getById({ - discordId: i.user.id, - }) - if (!ok) - return { - messageOptions: { - content: "Cannot show latest changelog", - }, - } - const { changelog, markRead } = await api.getLatestChangelog(profile.id) + const changelog = api.getLatestChangelog() if (!changelog) { return { messageOptions: { @@ -55,8 +46,6 @@ const slashCmd: SlashCommand = { } } - markRead() - return null }, help: async () => ({ diff --git a/src/index.ts b/src/index.ts index 8a8ad33dd..2bae2947a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import Discord, { CommandInteraction } from "discord.js" +import Discord from "discord.js" import { APPLICATION_ID, DISCORD_TOKEN, @@ -20,8 +20,6 @@ import Redis from "ioredis" import events from "listeners/discord" import { getTipsAndFacts } from "cache/tip-fact-cache" import api from "api" -import { DOT } from "utils/constants" -import { getEmbedFooter } from "ui/discord/embed" let server: Server | null = null @@ -120,35 +118,6 @@ function runHttpServer() { }) } -// monkeypatch -const editReply = CommandInteraction.prototype.editReply -CommandInteraction.prototype.editReply = async function ( - ...args: Parameters -) { - const [payload] = args - if (typeof payload === "string" || !("embeds" in payload)) - return editReply.apply(this, args) - - const { ok: okProfile, data: profile } = await api.profile.discord.getById({ - discordId: this.user.id, - }) - if (okProfile) { - const { changelog } = await api.getLatestChangelog(profile.id) - if (changelog) { - const embed = payload.embeds?.at(0) - if (embed) { - const parts = embed.footer?.text?.split(` ${DOT} `) - if (parts?.length) { - parts[0] = "🌈 Mochi has a new update, check out /sup" - embed.footer!.text = getEmbedFooter(parts) - } - } - } - } - - return editReply.apply(this, args) -} - // cleanup // @ts-ignore if (import.meta.hot) { From a696d1a9162eca85254586158e5c10337ebc76d6 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 12 Sep 2023 07:15:16 +0000 Subject: [PATCH 6/6] chore(release): 6.31.0-rc.2 [skip ci] # [6.31.0-rc.2](https://github.com/consolelabs/mochi-discord/compare/v6.31.0-rc.1...v6.31.0-rc.2) (2023-09-12) ### Bug Fixes * **general:** re-sync emojis: SPELL, BTC, SOL, ... ([46c6d7a](https://github.com/consolelabs/mochi-discord/commit/46c6d7ae6d5a7436f6555c1dda8df138fff33734)) * **general:** remove what's new footer, /changelog always show latest ([5f8228d](https://github.com/consolelabs/mochi-discord/commit/5f8228d3d511b241cb52ec97295e0f1bf8a3ed22)) --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd6a6338..9d77410c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# [6.31.0-rc.2](https://github.com/consolelabs/mochi-discord/compare/v6.31.0-rc.1...v6.31.0-rc.2) (2023-09-12) + + +### Bug Fixes + +* **general:** re-sync emojis: SPELL, BTC, SOL, ... ([46c6d7a](https://github.com/consolelabs/mochi-discord/commit/46c6d7ae6d5a7436f6555c1dda8df138fff33734)) +* **general:** remove what's new footer, /changelog always show latest ([5f8228d](https://github.com/consolelabs/mochi-discord/commit/5f8228d3d511b241cb52ec97295e0f1bf8a3ed22)) + # [6.31.0-rc.1](https://github.com/consolelabs/mochi-discord/compare/v6.30.1...v6.31.0-rc.1) (2023-09-12) diff --git a/package.json b/package.json index 8eee985bf..afd2707fd 100644 --- a/package.json +++ b/package.json @@ -113,5 +113,5 @@ "node": "18.x" }, "name": "mochi-discord", - "version": "6.31.0-rc.1" + "version": "6.31.0-rc.2" }