Lint project

This commit is contained in:
Kurt Hutten
2022-01-19 20:01:46 +11:00
parent 31ffeab4e6
commit c32023c629
13 changed files with 173 additions and 140 deletions

View File

@@ -1,7 +1,7 @@
import { createGraphQLHandler } from '@redwoodjs/graphql-server'
import { createSentryApolloPlugin } from 'src/lib/sentry'
import { logger } from 'src/lib/logger'
import "discord.js"
import 'discord.js'
import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'

View File

@@ -1,34 +1,40 @@
import {Client, Intents, MessageAttachment} 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 sendDiscordMessage(text: string, url?: string) {
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 {
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID);
const channel = await client.channels.fetch(process.env.DISCORD_CHANNEL_ID)
if (url) {
channel.send({ embeds: [{
title: text,
image: {
url: 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}`)
})
if (!process.env.DISCORD_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
console.warn("Discord bot not configured - please set process.env.DISCORD_TOKEN and process.env.DISCORD_CHANNEL_ID to send discord chats");
console.warn(
'Discord bot not configured - please set process.env.DISCORD_TOKEN and process.env.DISCORD_CHANNEL_ID to send discord chats'
)
} else {
console.log(`Discord: logging in (token ${process.env.DISCORD_TOKEN})`);
client.login(process.env.DISCORD_TOKEN);
console.log(`Discord: logging in (token ${process.env.DISCORD_TOKEN})`)
client.login(process.env.DISCORD_TOKEN)
}

View File

@@ -14,7 +14,6 @@ import { requireAuth } from 'src/lib/auth'
import { requireOwnership, requireProjectOwnership } from 'src/lib/owner'
import { sendDiscordMessage } from 'src/lib/discord'
export const projects = ({ userName }) => {
if (!userName) {
return db.project.findMany({ where: { deleted: false } })
@@ -249,13 +248,16 @@ export const updateProjectImages = async ({
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}`)
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