This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
forked from zekro-archive/tutorialJSBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
110 lines (79 loc) · 2.83 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const Discord = require('discord.js')
const fs = require('fs')
const Embeds = require('./embed')
const config = JSON.parse(fs.readFileSync('config.json', 'utf8'))
var client = new Discord.Client()
client.on('ready', () => {
console.log(`Logged in as ${client.user.username}...`)
})
var cmdmap = {
say: cmd_say,
test: cmd_test
}
function cmd_say(msg, args) {
msg.channel.send(args.join(' '))
}
function cmd_test(msg, args) {
//Embeds.error(msg.channel, 'This is actuially not an error', 'Not an error')
Embeds.info(msg.channel, "this is a content lel")
}
client.on('message', (msg) => {
var cont = msg.content,
author = msg.member,
chan = msg.channel,
guild = msg.guild
if (msg.channel.type == "text" && author.id != client.user.id && cont.startsWith(config.prefix)) {
// ::say hello world!
var invoke = cont.split(' ')[0].substr(config.prefix.length),
args = cont.split(' ').slice(1)
if (invoke in cmdmap) {
cmdmap[invoke](msg, args)
}
}
})
// https://discord.gg/uPsQQn
const AUTOROLEID = "332164463186673666"
client.on('guildMemberAdd', (memb) => {
var role = memb.guild.roles.find(r => r.id == AUTOROLEID)
if (role) {
memb.addRole(role).then(() => {
memb.send('', new Discord.RichEmbed().setColor(0x29B6F6).setDescription(`You got automatically assigned the role ${role.name}!`))
})
}
})
const PRES = {
"289901406985388033": "[MOD]",
"289901361951277056": "[ADMIN]"
}
client.on('guildMemberUpdate', (mold, mnew) => {
var guild = mnew.guild
if (mold.roles.array().length < mnew.roles.array().length) {
var role = mnew.roles.find(r => mold.roles.find(rold => rold.id == r.id) == null)
if (role.id in PRES) {
mnew.setNickname(`${PRES[role.id]} ${mnew.displayName}`)
}
}
else if (mold.roles.array().length > mnew.roles.array().length) {
var role = mold.roles.find(r => mnew.roles.find(rold => rold.id == r.id) == null)
if (role.id in PRES) {
mnew.setNickname(mnew.displayName.substr(PRES[role.id].length + 1))
}
}
})
const pres = {
"289901406985388033": "[MOD]"
}
client.on('guildMemberUpdate', (mold, mnew) => {
var guild = mnew.guild
if (mold.roles.array().length < mnew.roles.array().length) {
var role = mnew.roles.find(r => mold.roles.find(r2 => r2.id == r.id) == null)
if (role.id in pres)
mnew.setNickname(`${pres[role.id]} ${mnew.displayName}`)
}
else if (mold.roles.array().length > mnew.roles.array().length) {
var role = mold.roles.find(r => mnew.roles.find(r2 => r2.id == r.id) == null)
if (role.id in pres)
mnew.setNickname(mnew.displayName.substr(pres[role.id].length + 1))
}
})
client.login(config.token)