Skip to content

Commit

Permalink
Merge branch 'develop' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
phucledien committed Oct 3, 2023
2 parents a0549a9 + a871d25 commit 5391f72
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
42 changes: 41 additions & 1 deletion src/listeners/discord/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import webhook from "adapters/webhook"
import { handlePrefixedCommand } from "commands"
import { Message } from "discord.js"
import tagme from "handlers/tagme"
import { textCommandAsyncStore } from "utils/async-storages"
import { PREFIX } from "utils/constants"
import {
MOCHI_PROFILE_API_BASE_URL,
PREFIX,
VALID_BOOST_MESSAGE_TYPES,
} from "utils/constants"
import { wrapError } from "utils/wrap-error"
import { DiscordEvent } from "./index"
import fetch from "node-fetch"

export const handleNormalMessage = async (message: Message) => {
try {
if (message.channel.type === "DM") return

const messageType = VALID_BOOST_MESSAGE_TYPES.includes(message.type) ? 9 : 1

const stickers = Array.from(message.stickers.values())

const profileRes = await fetch(
`${MOCHI_PROFILE_API_BASE_URL}/profiles/get-by-discord/${message.author.id}?no_fetch_amount=true`,
)
const profileId = (await profileRes.json())?.id
const body = {
author: {
id: message.author.id,
avatar: message.author.avatarURL(),
username: message.author.username,
},
guild_id: message.guildId,
channel_id: message.channelId,
timestamp: message.createdAt.toISOString(),
content: message.content,
sticker_items: stickers,
type: messageType,
}

await webhook.pushDiscordWebhook("messageCreate", body, profileId)
} catch (e) {
// swallow, intentional
}
}

const events: DiscordEvent<"messageCreate"> = {
name: "messageCreate",
Expand Down Expand Up @@ -34,6 +73,7 @@ const events: DiscordEvent<"messageCreate"> = {
return
}
tagme.handle(message)
await handleNormalMessage(message)
})
},
)
Expand Down
15 changes: 12 additions & 3 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ export interface RequestOffchainTransferRequest {
platform?: string
recipients?: string[]
sender?: string

/** AmountString string `json:"amount_string"` */
token?: string
transfer_type?: string
Expand Down Expand Up @@ -1062,9 +1063,7 @@ export interface ResponseCoinMarketItemData {
price_change_percentage_24h?: number
price_change_percentage_24h_in_currency?: number
price_change_percentage_7d_in_currency?: number
sparkline_in_7d?: {
price?: number[]
}
sparkline_in_7d?: { price?: number[] }
symbol?: string
}

Expand Down Expand Up @@ -1148,17 +1147,21 @@ export interface ResponseCreateUserTokenSupportRequest {

export interface ResponseDataFilterConfigByReaction {
data?: ResponseRoleReactionResponse

/** page index */
page?: number

/** page size */
size?: number
total?: number
}

export interface ResponseDataListRoleReactionResponse {
data?: ResponseListRoleReactionResponse

/** page index */
page?: number

/** page size */
size?: number
total?: number
Expand Down Expand Up @@ -1217,6 +1220,7 @@ export interface ResponseDiscordGuildResponse {
id?: string
name?: string
owner?: boolean

/** @example 0 */
permissions?: string
}
Expand Down Expand Up @@ -1437,8 +1441,10 @@ export interface ResponseGetInvestListResponse {

export interface ResponseGetLevelRoleConfigsResponse {
data?: ModelGuildConfigLevelRole[]

/** page index */
page?: number

/** page size */
size?: number
total?: number
Expand Down Expand Up @@ -1556,6 +1562,7 @@ export interface ResponseGetTrackingWalletsResponse {

export interface ResponseGetTrendingSearch {
coins?: ResponseGetTrendingSearchCoin[]

/** this field coingecko return empty */
exchanges?: any
}
Expand Down Expand Up @@ -2074,6 +2081,7 @@ export interface ResponseOnchainInvestDataResponse {
export interface ResponsePaginationResponse {
/** page index */
page?: number

/** page size */
size?: number
total?: number
Expand Down Expand Up @@ -2321,6 +2329,7 @@ export interface UtilPagination {

export interface UuidNullUUID {
uuid?: string

/** Valid is true if UUID is not NULL */
valid?: boolean
}
10 changes: 10 additions & 0 deletions src/utils/wrap-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ChannelLogger from "../logger/channel"
import { getCommandMetadata } from "./commands"
import { kafkaQueue } from "queue/kafka/queue"
import { Sentry } from "sentry"
import { version } from "../../package.json"

function catchAll(e: any) {
logger.error(e)
Expand Down Expand Up @@ -72,6 +73,9 @@ export async function wrapError(
raw: commandStr,
args,
},
app: {
app_version: `v${version}`,
},
},
})
}
Expand Down Expand Up @@ -104,6 +108,9 @@ export async function wrapError(
.map((option) => option.value)
.join(" "),
},
app: {
app_version: `v${version}`,
},
},
})
}
Expand All @@ -122,6 +129,9 @@ export async function wrapError(
raw: commandStr,
args,
},
app: {
app_version: `v${version}`,
},
},
})
}
Expand Down

0 comments on commit 5391f72

Please sign in to comment.