-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdiscord.js
56 lines (45 loc) · 1.9 KB
/
discord.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Eris = require("eris");
class DiscordToGuildedBridge {
constructor(bridge, settings) {
this.bridge = bridge;
this.settings = settings;
this.client = new Eris(`Bot ${this.settings.botToken}`, {
intents: [
"guilds",
"guildMessages"
]
})
this.client.on('ready', () => {
console.log(`[Discord] Logged in as ${this.client.user.username}/${this.client.user.id}`);
this.guild = this.client.guilds.get(this.settings.guildId);
if (!this.guild) return console.log("[Discord] Invalid guild ID provided.")
console.log(`[Discord] Forwarding to guild ${this.guild.name}`)
})
this.client.on("messageCreate", message => {
this.translateToGuilded(message);
})
}
async connect() {
this.client.connect();
}
async translateToGuilded(message) {
if (message.webhookID) return;
this.bridge.guilded.sendToWebhook(message.channel, `<${message.author.username}>: ${message.content}`)
}
findEmoteByName(emoteName) {
return this.guild.emojis.find(emoji => emoji.name == emoteName);
}
async sendToWebhook(gChannel, message) {
let channel = this.guild.channels.filter(channel => channel.name == gChannel.name);
if (channel.length > 1) {
channel = channels.filter(channel => channel.parentID &&
this.guild.channels.get(channel.parentID).name == gChannel.categoryName);
}
channel = channel[0] || this.guild.channels.get(this.settings.mainChannel);
const webhook = (await channel.getWebhooks()).find(w => w.application_id == this.client.user.id) || (await channel.createWebhook({
name: "Guilded Bridge"
}));
this.client.executeWebhook(webhook.id, webhook.token, message);
}
}
module.exports = DiscordToGuildedBridge