-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
134 lines (113 loc) · 3.79 KB
/
index.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const Commando = require('discord.js-commando');
const Discord = require('discord.js');
const fs = require('fs');
const bot = new Commando.Client();
const KEY = process.env.yt_api_key;
const TOKEN = process.env.token;
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM();
const { document } = (new JSDOM('')).window;
global.document = document;
const $ = jQuery = require('jquery')(window);
const botConfig = require(__dirname + '/botConfig.json');
global.bot = bot;
global.currentTeamMembers = [];
global.servers = {};
bot.registry.registerGroup('simple', 'Simple');
bot.registry.registerGroup('music', 'Music');
bot.registry.registerGroup('team', 'Team');
bot.registry.registerGroup('game', 'Game');
bot.registry.registerGroup('admin', 'Admin');
bot.registry.registerGroup('pvt', 'PvT');
bot.registry.registerDefaults();
bot.registry.registerCommandsIn(__dirname + '/commands');
/*
Functions that can be accessed from any file.
*/
global.globalFunctions = {
stringifyFile: function(fileName, requiredFile, logBool, logString, prettyPrint)
{
let indentNum = 0;
if(prettyPrint == true) indentNum = 2;
fs.writeFile(fileName, JSON.stringify(requiredFile, null, indentNum), function(err){
if(err) throw err;
if(logBool == true) console.log(logString);
});
},
getChannelData: function (channel)
{
var ytApiUrl = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=' + channel + '&key=' + KEY;
var subsVar;
$.ajaxSetup({
async: false
});
$.getJSON(ytApiUrl, function(result){
subsVar = +result['items'][0]['statistics'].subscriberCount;
});
return subsVar;
}
}
/*
Function to pick a random faction out of the three and
give that role to a member.
*/
function setMemberFaction(member)
{
let factionOne = member.guild.roles.find(role => role.name === botConfig["roles"].faction_one);
let factionTwo = member.guild.roles.find(role => role.name === botConfig["roles"].faction_two);
let factionThree = member.guild.roles.find(role => role.name === botConfig["roles"].faction_three);
let chance = Math.floor(Math.random() * 3);
//Change channel name for the default channel!
let defaultChannel = member.guild.channels.find(channel => channel.name === botConfig["channels"].welcome);
if(chance == 0)
{
member.addRole(factionOne);
member.send("You are a \"Time Lord\".");
defaultChannel.send(member + " is the newest member of the Time Lords!");
}
else if (chance == 1)
{
member.addRole(factionTwo);
member.send("You are a \"Dalek\".");
defaultChannel.send(member + " is the newest member of the Daleks!");
}
else
{
member.addRole(factionThree);
member.send("You are a \"Mondasian\".");
defaultChannel.send(member + " is the newest member of the Mondasians!");
}
}
/*
Triggered when a new member joins.
*/
bot.on('guildMemberAdd', function(member)
{
member.send("Welcome to the server! Hope you enjoy your stay!");
let memberRole = member.guild.roles.find(role => role.name === botConfig["roles"].default);
member.addRole(memberRole);
setMemberFaction(member);
});
/*
Triggered when a member says a specific message.
*/
bot.on('message', function(message)
{
if(message.content == 'Hello')
{
message.channel.sendMessage('Hello ' + message.author + ', how are you?');
}
if(message.content == 'Faction')
{
setMemberFaction(message.member);
}
});
/*
Triggered when the bot is on and ready.
*/
bot.on('ready', function(){
console.log("Ready");
bot.user.setActivity("The Server", {type: 'WATCHING'});
})
bot.login(TOKEN);