revoltwebhook/index.ts

63 lines
2.7 KiB
TypeScript

import { Client } from 'revolt.js';
const express = require( 'express' );
const app = express();
app.use( express.json() );
// will separate everyhting after
const fs = require("fs")
let client = new Client({
apiURL: "https://api.revolt.chat"
});
client.on('ready', async () => {
console.info(`Logged in as ${client.user!.username}!`),
(await client.channels.fetch("01FE124PG3PJQ2A4ZPFRDGX1N8")).sendMessage(`\`\`\`js\n{\n"auth-date": "${Date.now()}",\n"type": "bot",\n"debug": "${client.debug}",\n"x-debug": "${client.debug.valueOf}",\n"x-webhooks-enabled": "unknown",\n"x-heartbeat": "${client.heartbeat}",\n"x-session": "${client.session}"\n}`)
});
app.post( '/', async ( req, res ) => {
console.log( 'received webhook', req.body );
(await client.channels.fetch("01FE139SQHRFBG5TR8022BECRW")).sendMessage(`${JSON.stringify(req.body)}`)
res.sendStatus( 200 );
} );
app.post( '/github/', async ( req, res ) => {
console.log( 'received webhook', req.body );
if (req.body.issue.url =! undefined) {
(await client.channels.fetch("01FE139SQHRFBG5TR8022BECRW")).sendMessage(`**${req.body.sender.login} :**\n> __[${req.body.repository.full_name} - Issue ${req.body.issue.title} was Updated](${req.body.issue.url})`)
}
res.sendStatus( 200 );
} );
// client.on('packet', async () => {
// (await client.channels.fetch("01FE139SQHRFBG5TR8022BECRW")).sendMessage(`Why am I even logging this? Idk\n\`\`\`js\n{\n"date": "${Date.now()}",\n"a": "${client.users.name_}"\n}`)
//});
client.on('message', async message => {
if (message.content === '!test') {
message.channel!.sendMessage('sus!');
} else if (message.content === '!settings public on') {
if (message.author_id === '01FDWYS13WWB69H1GD7NA8TFJD') {
await client.req('PATCH', `/bots/01FE0T7C5GS2RYEZPNY86M3TMJ` as '/bots/id',
{ public: true });
message.channel!.sendMessage("Successfully changed the bot privacy settings.")
} else {
message.channel!.sendMessage("You don't have permission to do that.")
}
}
else if (message.content === '!settings public off') {
if (message.author_id === '01FDWYS13WWB69H1GD7NA8TFJD') {
await client.req('PATCH', `/bots/01FE0T7C5GS2RYEZPNY86M3TMJ` as '/bots/id',
{ public: false });
message.channel!.sendMessage("Successfully changed the bot privacy settings.")
} else {
message.channel!.sendMessage("You don't have permission to do that.")
}
}
});
client.loginBot('m54okrgPs5OuW88Kjs6lr1KiTFXFRP7PZgfUYbuWJ5AziPrt8lO1Ik0GhvLY3BPC');
app.listen( 9000, () => console.log( 'Node.js server started on port 9000.' ) );