Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tip): show channel url in tip notification message #1494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/commands/airdrop/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { RunResult } from "../../../types/common"
import { AirdropOptions, TransferPayload } from "../../../types/transfer"
import { composeDiscordSelectionRow } from "../../../ui/discord/select-menu"
import { formatDigit } from "../../../utils/defi"
import { reply } from "../../../utils/discord"
import { getChannelInviteUrl, reply } from "../../../utils/discord"
import { confirmationHandler, tokenSelectionHandler } from "./handler"
import * as processor from "./processor"

Expand Down Expand Up @@ -66,6 +66,7 @@ export async function airdrop(i: CommandInteraction) {
}
const guildName = i.guild?.name ?? ""
const channelName = i.channel instanceof TextChannel ? i.channel.name : ""
const channel_url = await getChannelInviteUrl(i)

const payload: TransferPayload = {
sender: i.user.id,
Expand All @@ -79,6 +80,7 @@ export async function airdrop(i: CommandInteraction) {
transfer_type: "airdrop",
chain_id: "",
channel_name: `${guildName}:${channelName}`,
channel_url,
}

// only one matching token -> proceed to send tip
Expand Down
4 changes: 3 additions & 1 deletion src/commands/tip/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getEmojiURL,
roundFloatNumber,
} from "utils/common"
import { isMessage, reply } from "utils/discord"
import { getChannelInviteUrl, isMessage, reply } from "utils/discord"
import {
getBalances,
getTargets,
Expand Down Expand Up @@ -98,6 +98,7 @@ export async function tip(
msgOrInteraction.channel instanceof TextChannel
? msgOrInteraction.channel.name
: ""
const channel_url = await getChannelInviteUrl(msgOrInteraction)

const payload: TransferPayload = {
sender: author.id,
Expand All @@ -106,6 +107,7 @@ export async function tip(
guild_id: msgOrInteraction.guildId ?? "",
channel_id: msgOrInteraction.channelId,
channel_name: `${guildName}:${channelName}`,
channel_url,
amount,
token: symbol,
each,
Expand Down
1 change: 1 addition & 0 deletions src/commands/v/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SlashCommandBuilder } from "@discordjs/builders"
import { SlashCommand } from "types/common"
import { version } from "../../../package.json"
import { DMChannel, TextChannel } from "discord.js"

const slashCmd: SlashCommand = {
name: "v",
Expand Down
16 changes: 9 additions & 7 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ export interface RequestTransferV2Request {
amount?: number
chain_id?: string
channel_id?: string
channel_name?: string
each?: boolean
guild_id?: string
message?: string
Expand Down Expand Up @@ -1243,18 +1244,19 @@ export interface ResponseFindTokenByContractAddressResponse {

export interface ResponseFriendTechKey {
address?: string
createdAt?: string
created_at?: string
holders?: number
id?: number
price?: number
profileChecked?: boolean
price_change_percentage?: number
profile_checked?: boolean
supply?: number
twitterPfpUrl?: string
twitterUsername?: string
updatedAt?: string
twitter_pfp_url?: string
twitter_username?: string
updated_at?: string
}

export interface ResponseFriendTechKeyWatchlistItemRespose {
export interface ResponseFriendTechKeyWatchlistItemResponse {
created_at?: string
decrease_alert_at?: number
id?: number
Expand Down Expand Up @@ -2267,7 +2269,7 @@ export interface ResponseTopUser {
}

export interface ResponseTrackFriendTechKeyResponse {
data?: ResponseFriendTechKeyWatchlistItemRespose
data?: ResponseFriendTechKeyWatchlistItemResponse
}

export interface ResponseTransferTokenV2Data {
Expand Down
1 change: 1 addition & 0 deletions src/types/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type TransferPayload = {
moniker?: string
original_amount?: number
channel_name: string
channel_url?: string
}

export type AirdropOptions = {
Expand Down
24 changes: 23 additions & 1 deletion src/utils/discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { CommandInteraction, Message, MessageOptions, User } from "discord.js"
import {
CommandInteraction,
Message,
MessageOptions,
TextChannel,
User,
} from "discord.js"
import _ from "lodash"
import { RunResult } from "types/common"
import { authorFilter, getAuthor } from "./common"
Expand Down Expand Up @@ -97,3 +103,19 @@ function getMessageReplyPayload(result: RunResult<MessageOptions>) {
"flags",
)
}

export async function getChannelInviteUrl(
msgOrInteraction: Message | CommandInteraction,
) {
let inviteUrl = ""
const channel = msgOrInteraction.channel
if (channel instanceof TextChannel) {
try {
const invite = await channel.createInvite({
maxAge: 0,
})
inviteUrl = invite.url
} catch {}
}
return inviteUrl
}