-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (82 loc) · 2.71 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
/* This is violet, a simple Discord bot that beginner bot makers can use to build upon */
/* imports */
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
/* import code from app folder */
var yourserverMessage = require('./app/yourserver.js');
var standardMessage = require('./app/standard.js');
/* global variables */
const botID = 'enter your bot user id here';
/* basic async request */
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function asyncAJAX(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onload = () => resolve(xhr.responseText);
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
})
}
/* Configure logger settings */
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
/* Initialize Discord Bot */
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
bot.setPresence( {game: {name:"with my tail"}} );
/* the following code will set violet's presence (playing a game status) */
var actions = [
"with my tail",
"with my frens",
"being petted",
"Super Mario Galaxy",
"sleeping"
];
var i = 0;
setInterval(function () {
if (i > actions.length) {
i = 0;
}
bot.setPresence( {game: {name:actions[i]}} );
i++
}, 50000);
});
/* violet can greet new members when they enter your server */
bot.on('guildMemberAdd', function (member) {
switch (member.guild_id) {
/* check for a server/guild id */
case "Place your server/guild id here":
bot.sendMessage({
to: 'channel id',
message: 'Henlo, <@'+member.id+'>! Welcome to this server! I am <@'+botID+'>. I am a smol kitty. Meow!'
});
break;
/* default action */
default:
break;
}
});
/* violet can send messages too! violet will run server-specific code */
bot.on('message', function (user, userID, channelID, message, evt) {
switch (bot.channels[channelID].guild_id) {
/* check for a server/guild id */
case "":
yourserverMessage(bot, user, userID, channelID, message, evt, asyncAJAX, botID);
break;
/* default server/guild */
default:
standardMessage(bot, user, userID, channelID, message, evt, asyncAJAX, botID);
break;
}
});