mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
attachments revolt->discord
This commit is contained in:
parent
077b46fde7
commit
249fc99c13
|
@ -1,6 +1,9 @@
|
|||
import { Client } from '@janderedev/revolt.js';
|
||||
import axios from 'axios';
|
||||
import { logger } from '..';
|
||||
|
||||
let AUTUMN_URL = `http://autumnUrl`;
|
||||
|
||||
const client = new Client({
|
||||
messageTimeoutFix: true,
|
||||
autoReconnect: true,
|
||||
|
@ -9,12 +12,16 @@ const client = new Client({
|
|||
|
||||
const login = () => new Promise((resolve: (value: Client) => void) => {
|
||||
client.loginBot(process.env['REVOLT_TOKEN']!);
|
||||
client.once('ready', () => {
|
||||
client.once('ready', async () => {
|
||||
logger.info(`Revolt: ${client.user?.username} ready - ${client.servers.size} servers`);
|
||||
|
||||
const apiConfig = await axios.get(client.apiURL);
|
||||
AUTUMN_URL = apiConfig.data?.features?.autumn?.url;
|
||||
|
||||
resolve(client);
|
||||
});
|
||||
});
|
||||
|
||||
import('./events');
|
||||
|
||||
export { client, login }
|
||||
export { client, login, AUTUMN_URL }
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import axios from "axios";
|
||||
import { BRIDGED_MESSAGES, BRIDGE_CONFIG, logger } from "..";
|
||||
import { client } from "./client";
|
||||
import { AUTUMN_URL, client } from "./client";
|
||||
import { client as discordClient } from "../discord/client";
|
||||
import { MessageEmbed, WebhookClient } from "discord.js";
|
||||
import { MessageEmbed, MessagePayload, Webhook, WebhookClient, WebhookMessageOptions } from "discord.js";
|
||||
import GenericEmbed from "../types/GenericEmbed";
|
||||
import { SendableEmbed } from "revolt-api";
|
||||
import { clipText, discordFetchMessage, discordFetchUser, revoltFetchMessage, revoltFetchUser } from "../util";
|
||||
|
||||
client.on('message', async message => {
|
||||
try {
|
||||
if (!message.content || typeof message.content != 'string') return;
|
||||
if (message.content && typeof message.content != 'string') return;
|
||||
logger.debug(`[M] Revolt: ${message.content}`);
|
||||
|
||||
const [ bridgeCfg, bridgedMsg, ...repliedMessages ] = await Promise.all([
|
||||
|
@ -47,8 +47,8 @@ client.on('message', async message => {
|
|||
token: bridgeCfg.discordWebhook.token,
|
||||
});
|
||||
|
||||
const payload = {
|
||||
content: `${message.content}`,
|
||||
const payload: MessagePayload|WebhookMessageOptions = {
|
||||
content: message.content || undefined,
|
||||
username: message.author?.username ?? 'Unknown user',
|
||||
avatarURL: message.author?.generateAvatarURL({ max_side: 128 }),
|
||||
embeds: message.embeds?.length
|
||||
|
@ -93,6 +93,17 @@ client.on('message', async message => {
|
|||
else payload.embeds = [ embed ];
|
||||
}
|
||||
|
||||
if (message.attachments?.length) {
|
||||
payload.files = [];
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
payload.files.push({
|
||||
attachment: `${AUTUMN_URL}/attachments/${attachment._id}/${attachment.filename}`,
|
||||
name: attachment.filename,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
client.send(payload)
|
||||
.then(async res => {
|
||||
await BRIDGED_MESSAGES.update({
|
||||
|
|
Loading…
Reference in a new issue