Skip to content

Commit

Permalink
Merge branch 'preview'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanddd committed Sep 12, 2023
2 parents 6c83041 + a696d1a commit 97f72f4
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 92 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# [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)


### 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)


Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -113,5 +113,5 @@
"node": "18.x"
},
"name": "mochi-discord",
"version": "6.30.1"
"version": "6.31.0-rc.2"
}
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions src/commands/sup/index.ts → src/commands/changelog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ 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
},
run: async function (i) {
const { ok, data: profile } = await api.profile.discord.getById({
discordId: i.user.id,
})
if (!ok)
return {
messageOptions: {
content: "Cannot show changelogs",
},
}
const { changelog, markRead } = await api.getLatestChangelog(profile.id)
const changelog = api.getLatestChangelog()
if (!changelog) {
return {
messageOptions: {
Expand All @@ -41,7 +32,7 @@ const slashCmd: SlashCommand = {
await i.editReply({
embeds: [
composeEmbedMessage2(i, {
author: ["Changelog", thumbnails.MOCHI],
author: ["", thumbnails.MOCHI],
description: text,
}),
],
Expand All @@ -55,8 +46,6 @@ const slashCmd: SlashCommand = {
}
}

markRead()

return null
},
help: async () => ({
Expand Down
4 changes: 2 additions & 2 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -167,7 +167,7 @@ export const slashCommands: Record<string, SlashCommand> = {
chotot: chotot.slashCmd,
proposal: proposal.slashCmd,
guess: guess.slashCmd,
sup: sup.slashCmd,
changelog: changelog.slashCmd,
v: v.slashCmd,
}

Expand Down
57 changes: 46 additions & 11 deletions src/commands/tip/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -97,6 +106,7 @@ export async function tip(
chain_id: "",
moniker: "",
platform: "discord",
original_amount: originalAmount,
}

if (moniker !== undefined) {
Expand Down Expand Up @@ -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,
Expand All @@ -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: [
Expand All @@ -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: [],
},
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
33 changes: 1 addition & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -120,35 +118,6 @@ function runHttpServer() {
})
}

// monkeypatch
const editReply = CommandInteraction.prototype.editReply
CommandInteraction.prototype.editReply = async function (
...args: Parameters<typeof editReply>
) {
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) {
Expand Down
1 change: 1 addition & 0 deletions src/types/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type TransferPayload = {
token_price?: number
decimal?: number
moniker?: string
original_amount?: number
}

export type AirdropOptions = {
Expand Down
Loading

0 comments on commit 97f72f4

Please sign in to comment.