-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
169 lines (146 loc) · 4.69 KB
/
Copy pathbot.js
File metadata and controls
169 lines (146 loc) · 4.69 KB
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
//Shit needed for Discord
const Discord = require("discord.js");
const config = require("./configs/config.json");
const client = new Discord.Client();
//Shit needed for text commands
const TextCommand = require("./modules/commands.js");
const PicCommand = require("./modules/pics.js");
const pastas = require("./commands/pastas.json");
const including = require("./commands/including.json");
const responses = require("./commands/responses.json");
const prefix = config.prefix;
const shit = config.shit;
var i;
var talk;
//Shit needed for pics
var fs = require('fs');
var pics = fs.readdirSync('./pics/');
//Initialize flag
let done = false;
//Function responsible for generating help message
function generateHelp(textHelp, picsHelp, message, flag){
if (message.content === (prefix + "help") && !(message.author.bot) && !(message.content.includes("powiedz"))) {
let string = "";
let pictures = "";
textHelp.forEach(
function addString(value) {string += value.name + "\n";}
);
picsHelp.forEach(
function addString(value) {pictures += value.name + "\n";}
);
message.channel.send("**Text Commands:** \n");
message.channel.send(string);
message.channel.send("**Pics Commands:** \n");
message.channel.send(pictures);
return true;
}
else{
return flag;
}
}
//Function responsible for >implying
function generateImplying(message, flag){
if(message.content.startsWith(">") && !(message.author.bot) && flag == false){
message.channel.send("```css\n >"+message.content.substring(message.content.indexOf(">")+1,message.content.lenght)+"\n```");
message.delete(0);
return true;
}
else{
return flag;
}
}
//Function responsible for saying shit
function talkWithMe(message, shit, flag){
if (message.content.includes(shit) && !(message.author.bot) && flag == false && message.content.startsWith(prefix) == false){
talk = message.content.split(shit,2);
actualmessage = talk[1].substring(talk[1].indexOf(" ")+1);
console.log(actualmessage);
message.channel.send(actualmessage);
return true;
}
else{
return flag;
}
}
//Function responsible for dice rolls
function rollDice(message, flag){
if (message.content.startsWith(prefix + "d") && !(message.author.bot) && !(message.content.includes(shit)) && flag == false) {
let dots = parseInt(message.content.split("d",2)[1]);
console.log(dots);
if(!(isNaN(dots))){
message.channel.send((Math.floor((Math.random()*parseInt(dots))+1)));
}
else{
message.channel.send("Not an integer, fuck you.");
}
}
else{
return flag;
}
}
//Brian's fortune telling
function askBrian(message, responses, flag){
if(message.content.toLowerCase().startsWith("brian,") && message.content.endsWith("?") && !(message.author.bot) && !(message.content.includes(shit)) && flag == false){
message.channel.send("Uh...");
setTimeout(function(){
message.channel.send(responses.responses[(Math.floor((Math.random()*responses.responses.length)+1))]);
}
, 1750);
return true;
}
else{
return flag;
}
}
//All text actions with prefix.
let allActions = [];
for (i = 0; i < pastas.pasta.length; i++) {
allActions.push(new TextCommand(pastas.pasta[i].command, pastas.pasta[i].fulltext));
//console.log(pastas.pasta[i]);
}
//All pics actions with prefix
let allPics = [];
for (i = 0; i < pics.length; i++){
allPics.push(new PicCommand(pics[i].split(".")[0],pics[i]))
}
//All inclide and chances
let allInclude = [];
for (i = 0; i < including.include.length; i++) {
allInclude.push(new TextCommand(including.include[i].what, including.include[i].answer, including.include[i].chance));
//console.log(including.include[i].what);
}
//Confirming that client IS actualy ready.
client.on("ready", () => {
console.log("I am ready");
});
//What should happen once message is sent
client.on("message", (message) => {
//done flag to stop evaluating message
done = false;
//List of all comands for prefix
done = generateHelp(allActions,allPics,message,done);
//Message starting with > is going to be green because implying and original message will be removed
done = generateImplying(message,done);
//Checking if bot is supposed to talk shit
done = talkWithMe(message,shit,done);
//Rolling the dice
done = rollDice(message, done);
//Brian fortune telling
done = askBrian(message, responses, done)
//Checks all prefix pastass
allActions.forEach(
function(value){ if(done == false){value.generateAction(prefix,message)}}
);
//Checks for all pics
allPics.forEach(
function(value){ if(done == false){value.generateAction(prefix,message)}}
);
//Checks for all including
allInclude.forEach(
function(value){ if(done == false){done = value.generateInclude(message)}}
);
});
//Error "handling"
client.on("error", console.error);
//Loging in
client.login(config.token);