-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintbot.js
192 lines (181 loc) · 8.08 KB
/
printbot.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Get dependencies and set up some variables
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const dirPath = 'categories/';
var ver = '0.00.03.16'
var listcat = '!listcat'
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
// Lists the version and other information
if (msg.content === '!ver') {
// Version information
var verMenuEmbed = new Discord.RichEmbed()
.setColor('777575')
.setTitle('Printbot Version Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('_ _', '_ _')
.addField('Version ' + ver, '_ _')
.addField('Created by SparrDrem, 2019-30-08 10:19:25:00', '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(verMenuEmbed);
}
// Help menu for commands
if (msg.content.startsWith('!help')) {
// Get arugments
const args = msg.content.slice('!help'.length).split(' ');
const command = args.shift().toLowerCase();
// Set 1st argument
var helpcmd = args[0]
// If the 1st argument is listcat...
if (helpcmd=='listcat') {
// Send the help menu for listcat.
var HelpMenuListcatEmbed = new Discord.RichEmbed()
.setColor('777575')
.setTitle('!listcat Command Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('_ _', '_ _')
.addField('!listcat = show all categories', '_ _')
.addField('!listcat [category] = show all models within the category', '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(HelpMenuListcatEmbed);
// Else, if the 1st argument is info...
} else if (helpcmd=='info') {
// Send the help menu for info
var HelpMenuInfoEmbed = new Discord.RichEmbed()
.setColor('777575')
.setTitle('!info Command Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('_ _', '_ _')
.addField('Usage: !info [category] [model]', '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(HelpMenuInfoEmbed);
} else {
// Else, send the default help menu.
var HelpMenuEmbed = new Discord.RichEmbed()
.setColor('777575') // Sets border color to a nice gray color
.setTitle('Printbot available commands')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('Commands:', '_ _')
.addField('_ _', '_ _')
.addField('!help', 'show this menu')
.addField('!ver', 'list current version')
.addField('!listcat', 'list all categories \(use `!help listcat` for more detailed view\)')
.addField('!info', 'get the link to a 3D model, as well as info about it \(use `!help info` for more detailed view\)')
.addField('READY.', '_ _')
msg.channel.send(HelpMenuEmbed);
}
}
// List all categories
if (msg.content.startsWith('!listcat')) {
// Get arguments
const args = msg.content.slice('!listcat'.length).split(' ');
const command = args.shift().toLowerCase();
// Set the first argument as the category.
var cat = args[0]
// List all categories
function compileList(cat) {
if (fs.existsSync(dirPath + cat)) {
var categories = fs.readdirSync(dirPath + cat);
} else {
var categories = fs.readdirSync(dirPath);
}
var cvar = 1;
var compiledList = " ";
while (cvar<=categories.length) {
var compiledList = compiledList.concat(cvar + ".) " + categories[cvar-1] + "\n");
cvar++;
}
var categoryList = new Discord.RichEmbed()
.setColor('777575')
.setTitle('Printbot Categories')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField(compiledList, '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(categoryList);
}
compileList(cat);
}
// Get information on models
if (msg.content.startsWith('!info')) {
// Get first (category) argument and 2nd (model name) category
const args = msg.content.slice('!info'.length).split(' ');
const command = args.shift().toLowerCase();
// Set arguments as variables
const cat = args[0]
const model = args[1]
// Check if the model exists in the category
if (fs.existsSync(dirPath + cat + "/" + model)) {
var modelInfo = fs.readFileSync(dirPath + cat + "/" +model, "utf8");
var embedModelInfo = new Discord.RichEmbed()
.setColor('777575')
.setTitle('Model Information')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField(modelInfo, '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(embedModelInfo);
} else {
// If it doesn't, display an error
var errorFileNotFound = new Discord.RichEmbed()
.setColor('777575')
.setTitle('ERROR')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('Error: That 3D Model or category was not found.', '_ _')
.addField('_ _', '_ _')
.addField('READY.', '_ _')
msg.channel.send(errorFileNotFound);
}
}
// Spin..?
if (msg.content === 'LOAD"*",8,1') {
var loadedGifFlag=1
var spinLoad = new Discord.RichEmbed()
.setColor('777575')
.setTitle('**** PRINTBOT 64 BASIC V2 ****')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('64K RAM SYSTEM, 38911 BASIC BYTES FREE', '_ _')
.addField('_ _', '_ _')
.addField('SEARCHING FOR *', '_ _')
.addField('LOADING', '_ _')
.addField('READY.','_ _')
msg.channel.send(spinLoad);
}
if (msg.content === 'RUN') {
/*if (loadedGifFlag===1) {
var loadedGifFlag=0*/
var spinRun = new Discord.RichEmbed()
.setColor('777575')
.setTitle('SPIN.PRG')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setImage('https://raw.githubusercontent.com/sparrdrem/DremJS/master/spin.gif')
.addField('READY.', '_ _')
msg.channel.send(spinRun);
/*} else {
var spinRunError = new Discord.RichEmbed()
.setColor('777575')
.setTitle('**** PRINTBOT 64 BASIC V2 ****')
.setAuthor('Printbot', 'https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.setThumbnail('https://raw.githubusercontent.com/sparrdrem/printbot/master/_previmg.png')
.addField('64K RAM SYSTEM, 38911 BASIC BYTES FREE', '_ _')
.addField('READY.', '_ _')
msg.channel.send(spinRunError);
}*/
}
});
client.login('$dummy_key$');