Repository navigation
Expand file tree
/
Copy pathbot.js
More file actions
155 lines (130 loc) · 4.29 KB
/
Copy pathbot.js
File metadata and controls
155 lines (130 loc) · 4.29 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
const Discord = require("discord.js");
const checkWord = require("check-word");
const emojiStrip = require("emoji-strip");
const stripChar = require("stripchar").StripChar;
require("dotenv").config();
const words = checkWord("en");
const client = new Discord.Client();
const token = process.env.TOKEN;
const prefix = "j!";
const jasonID = "135329505207123969";
var retarded = false;
var twoWords = true;
var silenced = true;
client.on("ready", () => {
console.log("I am online!");
});
client.on("message", (msg) => {
if (silenced && msg.content === `${prefix}unsilence`) {
silenced = false;
return msg.channel.send("I am back!");
}
if (silenced || msg.author.bot) return;
// must not be silenced and not from a bot
if (msg.author.id.toString() === jasonID) {
msg.delete();
}
var arr = emojiStrip(msg.content).split(" ");
if (arr.length === 1 && arr[0].substring(0, 2) === `${prefix}`) {
// check prefix only
var restStr = arr[0].substring(2);
if (restStr === `silence`) {
silenced = true;
return msg.channel.send(`SHUTUP JASON`);
}
if (restStr === `retarded`) {
retarded = !retarded;
return retarded
? msg.channel.send(`I am now jason 🥴`)
: msg.channel.send(`I am now YASON 💪`);
}
if (restStr === `twoWords`) {
twoWords = !twoWords;
return twoWords
? msg.channel.send(`scanning only 2 words`)
: msg.channel.send(`scanning >2 words`);
}
}
arr = removeEmoteMentionLink(arr);
if (!twoWords && arr.length > 2) {
// need scan all words
arr = find1_2Longest(arr);
}
if (arr.length === 2) {
// msg must be 2 words
if (retarded && arr[0] !== arr[1]) {
// switches first letter of the 2 words
let newFirstWord = arr[1].charAt(0) + arr[0].substring(1);
let newSecondWord = arr[0].charAt(0) + arr[1].substring(1);
if (!twoWords) {
let newSentence = msg.content
.replace(arr[1], newSecondWord)
.replace(arr[0], newFirstWord);
return msg.channel.send(newSentence);
}
return msg.channel.send(`${newFirstWord} ${newSecondWord}`);
}
if (!retarded) {
var firstWord = arr[0].toLowerCase();
var secondWord = arr[1].toLowerCase();
if (firstWord !== secondWord) {
// they must not be equal words
var minLength = Math.min(firstWord.length, secondWord.length);
for (var i = 1; i <= minLength; i++) {
var newFirstWord =
secondWord.substring(0, i) + firstWord.substring(i);
var newSecondWord =
firstWord.substring(0, i) + secondWord.substring(i);
console.log(
`${firstWord}, ${newFirstWord}, ${secondWord}, ${newSecondWord}`
);
if (
(words.check(newFirstWord) || words.check(newSecondWord)) &&
secondWord.substring(0, i) !== firstWord.substring(0, i) &&
firstWord !== newSecondWord &&
secondWord !== newFirstWord
) {
// found an actual word after mixmatching
console.log(
`ARR0:${arr[0]}, NEWFIRSTWORD:${newFirstWord} ARR1:${arr[1]} NEWSECONDWORD:${newSecondWord}`
);
if (!twoWords) {
let newSentence = msg.content
.replace(arr[1], newSecondWord)
.replace(arr[0], newFirstWord);
return msg.channel.send(newSentence);
}
return msg.channel.send(`${newFirstWord} ${newSecondWord}`);
}
}
}
}
}
});
function emoteMentionLinkChecker(str) {
let length = str.length;
let firstCharLastChar = str.charAt(0) + str.charAt(length - 1);
if (firstCharLastChar === "<>") return true;
return str.substring(0, 4) === "http" || str === "";
}
function removeEmoteMentionLink(arr) {
let num = arr.length;
console.log("BEFORE: " + arr);
let newArr = [];
for (var i = 0; i < num; i++) {
if (!emoteMentionLinkChecker(arr[i])) {
arr[i] = stripChar.RSExceptAlpha(arr[i]);
newArr.push(arr[i]);
}
}
var filtered = newArr.filter(Boolean);
console.log(`AFTER: ${newArr} FILTER: ${filtered}`);
return filtered;
}
function find1_2Longest(arr) {
var sorted = arr.sort(function (a, b) {
return b.length - a.length;
});
return [sorted[0], sorted[1]];
}
client.login(token);