mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-30 11:14:05 -04:00
Send message to Discord when reaching 50, 100, ..., users
This commit is contained in:
@@ -13,7 +13,7 @@ import {createSupabaseDirectClient} from 'shared/supabase/init'
|
||||
import {insert} from 'shared/supabase/utils'
|
||||
import {convertPrivateUser, convertUser} from 'common/supabase/users'
|
||||
import {getBucket} from "shared/firebase-utils";
|
||||
import {sendDiscordNewUser} from "common/discord/core";
|
||||
import {sendDiscordMessage} from "common/discord/core";
|
||||
|
||||
export const createUser: APIHandler<'create-user'> = async (
|
||||
props,
|
||||
@@ -130,10 +130,36 @@ export const createUser: APIHandler<'create-user'> = async (
|
||||
console.log('Failed to track create profile', e)
|
||||
}
|
||||
try {
|
||||
await sendDiscordNewUser(user)
|
||||
await sendDiscordMessage(
|
||||
`**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`,
|
||||
'members',
|
||||
)
|
||||
} catch (e) {
|
||||
console.log('Failed to send discord new user', e)
|
||||
}
|
||||
try {
|
||||
const nProfiles = await pg.one<number>(
|
||||
`SELECT count(*) FROM users`,
|
||||
[],
|
||||
(r) => Number(r.count)
|
||||
)
|
||||
|
||||
const isMilestone = (n: number) => {
|
||||
return (
|
||||
[15, 20, 30, 40].includes(n) || // early milestones
|
||||
n % 50 === 0
|
||||
)
|
||||
}
|
||||
if (isMilestone(nProfiles)) {
|
||||
await sendDiscordMessage(
|
||||
`We just reached **${nProfiles}** total profiles! 🎉`,
|
||||
'general',
|
||||
)
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.log('Failed to send discord user milestone', e)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import {User} from "common/user";
|
||||
|
||||
export const sendDiscordNewUser = async (user: User) => {
|
||||
const webhookUrl = process.env.DISCORD_WEBHOOK_NEW_USERS
|
||||
export const sendDiscordMessage = async (content: string, channel: string) => {
|
||||
const webhookUrl = {
|
||||
members: process.env.DISCORD_WEBHOOK_MEMBERS,
|
||||
general: process.env.DISCORD_WEBHOOK_GENERAL,
|
||||
}[channel]
|
||||
|
||||
if (!webhookUrl) return
|
||||
|
||||
const response = await fetch(webhookUrl!, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({content: `**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`}),
|
||||
body: JSON.stringify({content}),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -18,7 +18,8 @@ export const secrets = (
|
||||
'RESEND_KEY',
|
||||
'COMPASS_API_KEY',
|
||||
'NEXT_PUBLIC_FIREBASE_API_KEY',
|
||||
'DISCORD_WEBHOOK_NEW_USERS',
|
||||
'DISCORD_WEBHOOK_MEMBERS',
|
||||
'DISCORD_WEBHOOK_GENERAL',
|
||||
// Some typescript voodoo to keep the string literal types while being not readonly.
|
||||
] as const
|
||||
).concat()
|
||||
|
||||
Reference in New Issue
Block a user