This commit is contained in:
Kalidou Diagne
2023-09-28 15:29:41 +02:00
parent 6b35ad26e0
commit 3a59de8988
3 changed files with 70 additions and 8 deletions

View File

@@ -1,16 +1,21 @@
import { sql } from '@vercel/postgres';
import { NextResponse } from 'next/server';
// /api/new-announce?id=123&type=info&url=https://example.com&short=Example&description=Learnings from the KZG Ceremony
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const id = searchParams.get('id') ?? new Date().getTime().toString(); // use timestamp as id if not provided
const type = searchParams.get('type');
const url = searchParams.get('url');
const short = searchParams.get('short');
const description = searchParams.get('description');
console.table({ id, type, url, short, description })
try {
if (!type || !url || !short || !description) throw new Error('Missing parameters');
await sql`INSERT INTO Announcements (type, short, url, description) VALUES (${type}, ${short}, ${url}, ${description});`;
if (!type || !url || !short || !description || !id) throw new Error('Missing parameters');
await sql`INSERT INTO Announcements (id, type, short, url, description) VALUES (${id},${type}, ${short}, ${url}, ${description});`;
} catch (error) {
console.log(error)
return NextResponse.json({ error }, { status: 500 });

59
common/discord.js Normal file
View File

@@ -0,0 +1,59 @@
const { Client, Routes } = require("discord.js")
const { config } = require("dotenv")
const { REST } = require("@discordjs/rest")
config()
const TOKEN = process.env.DISCORD_TOKEN
const CLIENT_ID = process.env.DISCORD_CLIENT_ID
const GUILD_ID = process.env.DISCORD_GUILD_ID
const client = new Client({
intents: ["Guilds", "GuildMessages", "MessageContent"],
})
const rest = new REST({ version: "10" }).setToken(TOKEN)
client.on("ready", () => {
console.log("Bot is ready", client.user.tag)
})
client.on("messageCreate", (message) => {
// todo: check if message is a command
})
client.login(TOKEN)
const commands = [
{
name: "learn",
description: "Create a new lear post",
},
{
name: "news",
description: "Create a news post",
},
{
name: "blog",
description: "Create a blog post",
},
]
async function main() {
try {
console.log("Registering slash commands...")
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), {
body: commands,
})
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error)
}
}
main()

View File

@@ -37,9 +37,8 @@ const showMove = {
const NewsPlaceholder = () => {
return (
<div className="bg-white">
<div
className="group block h-fit w-full cursor-pointer gap-3 border-b border-t-0 border-slate-950/70 px-6 py-6 transition-all first:border-t xl:px-20"
className="block h-fit w-full gap-3 px-6 py-6 xl:px-20 border-b border-t-0 border-slate-950/70"
>
<div className="h-full w-full items-center justify-between lg:flex">
<div className="flex lg:flex lg:gap-12 xl:gap-56">
@@ -50,8 +49,7 @@ const NewsPlaceholder = () => {
<span className="bg-slate-200 animate-pulse h-6 w-96"></span>
</div>
</div>
</div>
</div>
</div>
)
}
@@ -84,10 +82,10 @@ const News = () => {
if (loading) {
return (
<>
<div className="bg-white border-t border-slate-950/70">
<NewsPlaceholder />
<NewsPlaceholder />
</>
</div>
)
}