-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
231 lines (214 loc) · 7.89 KB
/
bot.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
* Fuck you lemon bot
*
* version 0.1
*
* Please add JSDoc documentation to any added functions
*
* ***FOR IF YOU ARE HOSTING THIS FOR TESTING***
* install node and npm and run the following command in the folder with the bot.js file:
*
* npm install discord.js
*
* add a file called ".env" and add the following line in it:
*
* TOKEN=(insert bot token here)
* https://discord.com/oauth2/authorize?client_id=806330256893673523&scope=bot
*/
require("dotenv").config(); // import .env so we can get the token
const videoshow = require("videoshow");
const text2png = require('text2png');
const Discord = require("discord.js");
const client = new Discord.Client();
const fs = require('fs');
const serverId = 728297305312329862; // this is so jank but the better way is much harder
const specialChannelIds = [
728297305329106951, // #information
728322720386777170, // #hibye
728298426558840922, // #trigger-potentials
728297305551405156, // #ranting-venting
744135238103597097, // #m
];
const logChannel = 806680464022175774; // #dick-kicking-zone
var isKlaxonOn = true;
var klaxonBoard;
var currentKlaxon = "";
var lastKlaxon;
var waitingForKlaxon = false;
var timer;
fs.readFile("klaxon.txt", "utf-8", (err, data) => {
klaxonBoard = data.split("\n");
currentKlaxon = klaxonBoard[0];
lastKlaxon = klaxonBoard[1];
klaxonBoard.splice(0, 2);
});
client.on("ready", () => {
console.log("Lemon Bot v.0.1");
console.log("meme mode: activated");
console.log("LOL ONIONS!");
console.log("Initializing...");
// ANCHOR: init code here if needed
setStatus();
console.log("Initialization Complete.");
});
client.on("message", (message) => {
if (message.author.bot) return;
if (message.guild === null) {
if (waitingForKlaxon) {
setKlaxon(message)
}
} else processMessage(message);
// replace regex just removes non-alphanumeric and _
if (message.content.toLowerCase().replace(/[\W_]+/g, ' ').split(' ').includes("cum")) {
message.react("😋").catch();
}
});
client.on("error", () => {
setStatus();
});
/**
* processMessage() - Processes the messages being sent by users.
* @param {object} message - message being processed
*/
function processMessage(message) {
// wheeeeeeeeeeeeee ctrl c ctrl v go brrrr
if (/^\~/g.test(message.content)) {
processCommand(message.content.substr(1)); // remove the leading character (the ">")
} else if (message.channel.id === specialChannelIds[5]) {
//mAnageMEnt(message) TODO
} else {
console.log("message read as pot claxon \n" + message)
klaxon(message);
}
}
/**
* processCommand() - determines which command to run
* @param {string} message - command without the prefix
*/
function processCommand(message) {
// TODO: literally everything here
}
/**
* klaxon() - checks if the message matches the klaxon
* @param {object} message
*/
function klaxon(message) {
if (klaxonCheck(message.content)) {
if (specialChannelIds.includes(message.channel.id)) return; //is it in a no-no channel?
console.log("got here")
//TODO: klaxon code
if (message.author.bot || !isKlaxonOn) return;
message.channel.send("> `" + message.content + "`\nKLAXON WORD: " + currentKlaxon + "\n" + message.member.user.username + " -10 Points LOL!", {
files:[{
attachment: "klaxon.mp4",
name: "klaxon.mp4"
}]
});
isKlaxonOn = false;
dmKlaxon(message);
} else console.log("bruh how")
}
/**
* klaxonCheck() - checks if the string contains the klaxon
* @param {string} message - message to be checked
*/
function klaxonCheck(message) {
let active = false;
console.log("a")
let splitMessage = message.split(" ");
console.log("b")
splitMessage.forEach(element => {
console.log("c " + (element === currentKlaxon) + " " + element + " " +currentKlaxon)
if (element.toLowerCase().replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ") === currentKlaxon.toLowerCase().replace(/[^\w\s]|_/g, "").replace(/\s+/g, " ")) active = true; // strips all punctuation and makes the word lowercase on both sides
});
if (active) return true;
else return false;
}
/**
* dmKlaxon() - DMs the user and recieves the new klaxon.
* @param {object} message - the message of the klaxon.
*/
function dmKlaxon(message) {
client.users.cache.get(message.author.id).send("Set the new klaxon by DMing me back. If you do not set it in 10 minutes it defaults to \"test\" \nAs a common courtesy for others, keep the klaxon reasonable. Remember, you are trying to get others to trigger it!");
waitingForKlaxon = message.author.id;
timer = setTimeout( () => {
client.users.cache.get(waitingForKlaxon).send("Welp, you ran out of time. LOL!");
waitingForKlaxon = false;
isKlaxonOn = true;
currentKlaxon = "test"
fs.writeFile("klaxon.txt", currentKlaxon, function (err) {
if (err) {
console.log("lmao");
}
});
}, 600000);
}
/**
* setStatus() - Starts the status loop
*/
function setStatus() {
client.user.setActivity("Blan's Birthday!", { type: 'COMPETING' });
}
/**
* setKlaxon() - sets the new klaxon.
* @param {object} message - the message containing the new klaxon
*/
function setKlaxon(message) {
if (message.author.id = waitingForKlaxon) {
if (/^\~/g.test(message.content)) {
client.users.cache.get(message.author.id).send("Invalid string: Contains the bot's prefix.");
return;
} else if (!/^[a-zA-Z]*$/.test(message.content)) {
client.users.cache.get(message.author.id).send("Invalid string: a-Z characters allowed only.");
return;
} else {
clearTimeout(timer);
currentKlaxon = message.content;
waitingForKlaxon = false;
console.log("lol!");
fs.writeFile("klaxon.txt", message.content, function (err) {
if (err) {
console.log("lmao");
}
});
fs.writeFileSync("klaxon.png", text2png(currentKlaxon.toUpperCase(), {
textAlign: "center",
color: "white",
bgColor: "black",
font: "200px Franklin Gothic",
padding: 460
}));
fs.writeFileSync("klaxonblack.png", text2png(currentKlaxon.toUpperCase(), {
textAlign: "center",
color: "black",
bgColor: "black",
font: "200px Franklin Gothic",
padding: 460
}));
videoshow(["klaxon.png","klaxonblack.png","klaxon.png","klaxonblack.png","klaxon.png","klaxonblack.png","klaxon.png","klaxonblack.png","klaxon.png","klaxonblack.png","klaxon.png"],{
fps: 30,
loop: 0.5, // seconds
transition: false,
videoBitrate: 1024,
videoCodec: 'libx264',
size: '640x?',
audioBitrate: '128k',
disableFadeIn: true,
disableFadeOut: true,
audioChannels: 2,
format: 'mp4'
}).audio("klaxon.ogg", {
fade: false
}).save("klaxon.mp4").on('start', function (command) {
client.users.cache.get(message.author.id).send(`Preparing new klaxon`);
}).on('error', function (err, stdout, stderr) {
client.users.cache.get(message.author.id).send("Error: failed to generate video for your word");
}).on('end', function (output) {
isKlaxonOn = true;
client.users.cache.get(message.author.id).send(`Klaxon: ACTIVE (${output})`);
});
}
}
}
// login stuffs (idk how this works but it hides the bot token so :shrug:)
client.login(process.env.TOKEN);