Merge pull request #1 from Irev-Dev/kurt/discord_bot
Tweak discord bot message.
This commit is contained in:
@@ -1,19 +1,29 @@
|
|||||||
import {Client, Intents} from "discord.js"
|
import {Client, Intents, MessageAttachment} from "discord.js"
|
||||||
|
|
||||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
|
||||||
|
|
||||||
export async function sendChat(text: string) {
|
export async function sendDiscordMessage(text: string, url?: string) {
|
||||||
if (!client.isReady()) {
|
if (!client.isReady()) {
|
||||||
console.error(`Discord: client is not ready to send message ("${text}")`);
|
console.error(`Discord: client is not ready to send message ("${text}")`);
|
||||||
} else {
|
} else {
|
||||||
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID);
|
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID);
|
||||||
channel.send(text);
|
if (url) {
|
||||||
|
channel.send({ embeds: [{
|
||||||
|
title: text,
|
||||||
|
image: {
|
||||||
|
url: url,
|
||||||
|
},
|
||||||
|
}] });
|
||||||
|
|
||||||
|
} else {
|
||||||
|
channel.send(text)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on("ready", async () => {
|
client.on("ready", async () => {
|
||||||
console.log(`Discord: logged in as ${client.user.tag}`)
|
console.log(`Discord: logged in as ${client.user.tag}`)
|
||||||
await sendChat("started");
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
|
if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import {
|
|||||||
} from 'src/services/helpers'
|
} from 'src/services/helpers'
|
||||||
import { requireAuth } from 'src/lib/auth'
|
import { requireAuth } from 'src/lib/auth'
|
||||||
import { requireOwnership, requireProjectOwnership } from 'src/lib/owner'
|
import { requireOwnership, requireProjectOwnership } from 'src/lib/owner'
|
||||||
import { sendChat } from 'src/lib/discord'
|
import { sendDiscordMessage } from 'src/lib/discord'
|
||||||
|
|
||||||
|
|
||||||
export const projects = ({ userName }) => {
|
export const projects = ({ userName }) => {
|
||||||
if (!userName) {
|
if (!userName) {
|
||||||
@@ -244,7 +245,19 @@ export const updateProjectImages = async ({
|
|||||||
const [updatedProject] = await Promise.all([
|
const [updatedProject] = await Promise.all([
|
||||||
projectPromise,
|
projectPromise,
|
||||||
imageDestroyPromise,
|
imageDestroyPromise,
|
||||||
]).then(() => sendChat(`project image updated: ${id}`));
|
]).then(async (result) => {
|
||||||
|
const { userName } = await db.user.findUnique({
|
||||||
|
where: { id: project.userId },
|
||||||
|
})
|
||||||
|
sendDiscordMessage([
|
||||||
|
`${userName} just added an image to their ${project.cadPackage} project:`,
|
||||||
|
` => ${project.title}`,
|
||||||
|
``,
|
||||||
|
`Check it out, leave a comment, make them feel welcome!`,
|
||||||
|
`https://cadhub.xyz/u/${userName}/${project.title}`
|
||||||
|
].join('\n'), `https://res.cloudinary.com/irevdev/image/upload/c_scale,w_700/v1/${mainImage}`)
|
||||||
|
return result
|
||||||
|
})
|
||||||
return updatedProject
|
return updatedProject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
'SENTRY_ORG',
|
'SENTRY_ORG',
|
||||||
'SENTRY_PROJECT',
|
'SENTRY_PROJECT',
|
||||||
'EMAIL_PASSWORD',
|
'EMAIL_PASSWORD',
|
||||||
'DISCORD_TOKEN',
|
|
||||||
'DISCORD_CHANNEL_ID',
|
|
||||||
]
|
]
|
||||||
# experimentalFastRefresh = true # this seems to break cascadeStudio
|
# experimentalFastRefresh = true # this seems to break cascadeStudio
|
||||||
[api]
|
[api]
|
||||||
|
|||||||
Reference in New Issue
Block a user