-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (68 loc) · 2.98 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const Discord = require('discord.js');
const { RTMClient, WebClient } = require('@slack/client');
const slack_client = new RTMClient(process.env.SLACK_TOKEN_BOT);
const web = new WebClient(process.env.SLACK_TOKEN_API);
slack_client.start();
slack_client.on('message', (message) => {
// For structure of `message`, see https://api.slack.com/events/message
// Skip messages that are from a bot or my own user ID
if ( (message.subtype && message.subtype === 'bot_message') ||
(!message.subtype && message.user === slack_client.activeUserId) ) {
return;
}
// Log the message
console.log(`(channel:${message.channel}) ${message.user} says: ${message.text}`);
});
const disc_client = new Discord.Client();
disc_client.on('ready', () => {
console.log("Connected as " + disc_client.user.tag)
// List servers the bot is connected to
console.log("Servers:")
disc_client.guilds.forEach((guild) => {
console.log(" - " + guild.name)
// List all channels
guild.channels.forEach((channel) => {
console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`)
})
})
var testChannel = disc_client.channels.get("557035649786445826")
//testChannel.send("Hello, World Test!")
// const localFileAttachment = new Discord.Attachment('./assets/images/disneyCastle.jpg')
// testChannel.send(localFileAttachment)
// const webAttachment = new Discord.Attachment('https://www.devdungeon.com/sites/all/themes/devdungeon2/logo.png')
// testChannel.send(webAttachment)
disc_client.user.setActivity("testing.")
})
disc_client.on('message', (recievedMessage) => {
if (recievedMessage.author == disc_client.user) {
return
}
if (recievedMessage.content.startsWith("!")) {
processCommand(recievedMessage)
}
sendMessageToSlack(recievedMessage)
//recievedMessage.channel.send("Messaged recieved from " + recievedMessage.author.toString() + ": " + recievedMessage.content)
})
// Discord to Slack sendMessage 'CGZDLT1A4' is the channel id for test-bot-channel in Mozilla Club Slack
function sendMessageToSlack(recievedMessage) {
slack_client.sendMessage(recievedMessage.content, 'CGZDLT1A4')
}
// Function for processing '!' commands on the discord side
function processCommand(recievedMessage) {
let fullCommand = recievedMessage.content.substr(1)
let splitCommand = fullCommand.split(" ")
let primaryCommand = splitCommand[0]
let arguments = splitCommand.slice(1)
console.log("Command Recieved: " + primaryCommand)
console.log("Arguments: " + arguments)
if (primaryCommand == "help") {
helpCommand(arguments, recievedMessage)
} else {
recievedMessage.channel.send("I don't understand the command. Try `!help`")
}
}
// Discord Command
function helpCommand(arguments, recievedMessage) {
recievedMessage.channel.send("If you have a question about the bot message @sin90.")
}
disc_client.login(process.env.DISCORD_TOKEN_BOT)