-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
172 lines (151 loc) · 5.5 KB
/
server.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
const Discord = require("discord.js");
const client = new Discord.Client();
const Markov = require('js-markov');
const salad = require('caesar-salad');
const fetch = require('node-fetch');
client.login(process.env.discord);
client.on("ready", () => {
client.user.setActivity("Fake News", { type: "WATCHING"});
anonymous = client.channels.get('656126149381849089');
bin2text = client.channels.get('757012300849872946');
})
const EmojiWhitelist = /[^\s|\n|\u{200b}|\u{180B}-\u{180D}\u{FE00}-\u{FE0F}|\u{DB40}|\u{DD00}-\u{DDEF}|\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/u
const FormatingOnly = /[^\s|\n|\u00A0|\u1CBB|\u1CBA|\u2000-\u2009|\u2028|\u202A-\u202f|\u205F|\uFEFF|\uFEEC-\uFEEF|\uFEF0-\uFEF5|\u200-\u200f|\u180B-\u180D\uFE00-\uFE0F|\uDB40|\uDD00-\uDDEF]/;
const seed = ":chestnut:";
replaces = new Map();
client.on('messageUpdate', (old, message) => {
switch(message.channel.id) {
case "652643622356910090": // Remove edited message that are not in EmojiWhitelist
EmojiOnly(message);
};
});
function sendMessage(webhook, content = "", username = "NoobBot [User]") {
fetch(webhook, {
method: 'post',
body: JSON.stringify({
content: content,
username: username
}),
headers: { 'Content-Type': 'application/json' },
});
}
function EmojiOnly(message) {
if(NotEmoji(message.content)) message.delete();
message.channel.fetchMessages({limit: 35}).then(messages => {
messages.forEach(msg => {
if(NotEmoji(msg.content)) msg.delete();
});
});
}
client.on("message", (message) => {
if(message.author.bot) return;
if(message.channel.type === "dm") {
return anonymous.send(message.content);
}
switch(message.channel.id) {
case "652623066677116948": // Apply Typoz to message
message.delete();
sendMessage(process.env.typo, Typoifier(message.content), message.author.username);
break;
case "652854590911414283": // Reverse message
message.delete();
sendMessage(process.env.revese, reverseString(message.content), message.author.username);
break;
case "652857164850790400": // Apply markov chain using message
message.delete();
sendMessage(process.env.markov, MarkovRandom(message.content), message.author.username);
break;
case "652885633047461920": // Apply replaces
message.delete();
Replaces(message);
break;
case "653315179756519434": // ROT47
message.delete();
sendMessage(process.env.rot47, salad.ROT47.Cipher().crypt(message.content), message.author.username);
break;
case "757012300849872946": // Binary to Text
message.delete();
bin2text.send(Bin2Text(message.content));
break;
case "653320664274436140": // Text to Binary
message.delete();
sendMessage(process.env.binary, Text2Bin(message.content), message.author.username);
break;
case "653329639477084160": // Seeds
message.delete();
let result = Text2Seed(message.content);
if(result.includes(seed)) sendMessage(process.env.seeds, result, message.author.username);
break;
case "652643622356910090": // Remove message that are not in EmojiWhitelist
EmojiOnly(message);
};
});
function Text2Bin(input) {
return Array.from(input).map((each) => each.codePointAt(0).toString(2)).join(" ");
}
function Bin2Text(input) {
return input.split(' ').map((bin) => String.fromCharCode(parseInt(bin, 2))).join('');
}
function Text2Seed(input) {
return input.replace(/\w/g, seed).replace(" ", " ");
}
function NotEmoji(string) {
if(EmojiWhitelist.test(string)) return true;
return (!FormatingOnly.test(string))
}
function Replaces(message) {
if(!message.content.startsWith("/")) return ReplaceMessage(message);
let command = message.content.split(" ")[0];
switch(command) {
case "/reset":
return replaces.clear();
case "/replace":
var data = message.content.substr(9).split(/@@@(.+)/);
if(data.length === 3) {
return replaces.set(data[0], data[1]);
}
}
return ReplaceMessage(message);
}
function ReplaceMessage(message) {
var content = message.content;
replaces.forEach((value, key) => {
content = content.replace(key, value);
});
sendMessage(process.env.replaces, content, message.author.username);
}
function MarkovRandom(input) {
var m = new Markov();
m.addStates(input);
m.train();
return m.generateRandom();
}
function reverseString(str) {
var splitString = str.split("");
var reverseArray = splitString.reverse();
var joinArray = reverseArray.join("");
return joinArray;
}
function getRandom(max) {
// This is insecure
return Math.floor((Math.random() * 10) % max)
}
function AtPos(str, position, newStr) {
return str.slice(0, position) + newStr + str.slice(position);
}
function Typoifier(str) {
if (str.length === 0) return
let words = str.split(" ");
words.forEach((word, index) => {
if (word.length === 0) return
if (getRandom(2)) words[index] = Typo(word);
})
return words.join(" ");
}
function Typo(word) {
let index = getRandom(word.length);
let letter = word[index];
let newString = AtPos(word, index, letter);
if (getRandom(2)) newString = AtPos(newString, index, letter);
return newString;
}