-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
271 lines (231 loc) · 7.89 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//Glitch.com nice discord.js bot
//https://nice-discordjs-bot.glitch.me/
//https://uptimerobot.com/dashboard
// server.js
// where your node app starts
// init project
const express = require('express');
const app = express();
const http = require('http');
const deepai = require('deepai'); // OR include deepai.min.js as a script tag in your HTML
deepai.setApiKey(process.env.DEEPAIAPIKEY);
app.use(express.static('public'));
app.get("/", (request, response) => {
response.sendFile(__dirname + '/views/index.html')
})
//ping self every 5 mins
app.get("/", (request, response) => {
console.log(Date.now() + " Ping Received");
response.sendStatus(200);
});
// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
console.log(`Your app is listening on port ${listener.address().port}`);
})
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000); //4m40s
//Discord.js bot part
function wrapperSend(message,s){
message.channel.send(s);
}
function wrapperReact(message,s){
message.react(s);
}
function toFatText(s1){
//missing: f k r
var replacements = [["a","🅰","🔼","4⃣"],["b","🅱","8⃣"],["c","↪","©","🌜","☪"],["d","↩","🌛"],["e","3⃣"],["g","6⃣"],["h","♓"],
["i","ℹ","1⃣"],["j","🎷"],["l","👢"],["m","Ⓜ","♏","♍","〽"],["n","♑"],["o","🅾","⭕","0⃣"],["p","🅿"],["q","🍳"],
["s","💲","5⃣"],["t","✝","7⃣"],["u","⛎"],["v","♈","✅","🔽"],["w","🐍","➿"],["x","❎","❌"],["y","💹"],["z","💤","2⃣"],
["!","❗","❕"],["?","❓","❔"]];
//,["r","®"]];
//,["",""]
var s=s1.toLowerCase();
s=sanitize(s);
var fatText=[];
for (var i = 0; i < s.length && fatText.length < 40; i++) {
var c = s.charAt(i);
var fatChar=toFatChar(c)
if(!fatText.includes(fatChar)){
fatText.push(fatChar);
}else{
var replacementFound = false;
for (var k = 0; k < replacements.length; k++) {
if(replacements[k][0]==c){
for (var j = 1; j < replacements[k].length; j++) {
if(!fatText.includes(replacements[k][j])){
fatText.push(replacements[k][j]);
replacementFound=true;
break;
}
}
break;
}
}
}
}
console.log(fatText);
return fatText;
}
function toFatChar(c1){//from ASCII code to Unicode
var c = c1.charCodeAt(0); //"0".charCodeAt(0)=48
if(48<=c && c<=57){
var digits = ["0⃣","1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
return digits[c-48];
}else if(c1=="!"){
return "❗"
}else if(c1=="?"){
return "❓"
}else{
return String.fromCodePoint(c-97+0x1F1E6);
}
}
//could be rewritten to confirm when the last emoji was recieved before sending the next one
function reactWithEmojiList(message,lst){
for (var i = 0; i < lst.length; i++) {
setTimeout(wrapperReact, i*500,message,lst[i]);
}
}
function reactWithText(message,text){
reactWithEmojiList(message,toFatText(text));
}
function sanitize(s){
//sanitize string to plain ascii
var cleanS="";
for(var i=0;i<s.length;i++){
var c=s.charAt(i);
if("abcdefghijklmonpqrstuvwxyz1234567890!?".includes(c)){
cleanS+=c;
}
}
return cleanS;
}
//get n random elements from array
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len){
n = len;
}
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
function thonk(lastmessage,nThonks){
//get list of custom emojis
const emojiList = client.emojis.array();
var thonkList=["🤔"];
for(var i=0;i<emojiList.length;i++){
var nm=emojiList[i].name.toLowerCase();
if(nm.includes("thonk") || nm.includes("think")){
thonkList.push(emojiList[i]);
}
}
//react with list containing think
reactWithEmojiList(lastmessage,getRandom(thonkList,nThonks));
//reactWithEmojiList(lastmessage,thonkList); //react with all thonks
}
const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
console.log("I am ready!");
client.user.setActivity('nice-discordjs-bot.glitch.me');
//client.user.setActivity('nice-discordjs-bot.glitch.me', { type: 'WATCHING' });
});
var reBigText = /\+\+[^\+]+\+\+/g;
function formatBigText(sIn) {
var s = sIn.substring(2,sIn.length-2).toLowerCase();
var returnStr="";
for(var i=0;i<s.length;i++){
var c=s.charAt(i);
if("abcdefghijklmonpqrstuvwxyz0123456789!?".includes(c)){
if("apob".includes(c)){
returnStr+=toFatText(c+c)[1];
}else{
returnStr+=toFatText(c);
}
returnStr+=" ";//add sspace after each emoji to stop combining into flags
}else if(c==" "){
returnStr+=" ";
}else{
returnStr+=c;
}
}
return returnStr;
}
client.on("message", (message) => {
console.log(message.content);
if(message.content.match(reBigText)){
let formattedStr = message.content.replace(reBigText, formatBigText);
message.delete();
message.channel.send(`${message.author.username}: ${formattedStr}`);
}else if (message.content.match(/^d\d+$/)) {
var range = parseInt(message.content.slice(1));
var result = Math.floor(Math.random() * range) + 1;
result = result.toString();
if(result=="11"){result="1I";}
else if(result=="22"){result="2Z";}
else if(result=="33"){result="3E";}
reactWithText(message,result);
}else if (message.content.startsWith("^")) {
var hatCount = ((message.content).match(/\^/g) || []).length;
message.channel.fetchMessages({ limit: 1+hatCount })
.then((messages) => {
var lastmessage=messages.array()[hatCount];
var command = message.content.slice(1);
if(command!=""){
if(command.startsWith("thonk")){
var nThonks = 5;
if(command.length>"thonk".length){ //specify number of emojis
nThonks = parseInt(command.slice("thonk".length+1));
}
thonk(lastmessage,nThonks);
}else{
var s = message.content.substring(1).toLowerCase();
reactWithText(lastmessage,s);
}
message.delete();
}
})
.catch(console.error);
}else if (message.content.startsWith("<@"+client.user.id)) {
console.log(message.content);
if(message.content.includes("?")){
//var replies = ["It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","Most likely","Yes","Signs point to yes","Ask again later","My reply is no","My sources say no","Very doubtful"];
var replies = ["yes","no","maybe"];
var result = Math.floor(Math.random() * replies.length);
//,"As I see it, yes.", "Outlook good.","Reply hazy, try again.","Better not tell you now.","Concentrate and ask again.","Cannot predict now.""Don't count on it.","Outlook not so good.",
reactWithText(message,replies[result]);
}else{
reactWithText(message,"nice");
}
}else if (message.content.toLowerCase().includes("<dreamify")) {
/*var resp = await deepai.callStandardApi("deepdream", {
content: "YOUR_IMAGE_URL",
});
console.log(resp);*/
}else if (message.content.toLowerCase().includes("thanos car")) {
reactWithText(message,"thanos car");
}else if (message.content.toLowerCase().includes("nice")) {
reactWithText(message,"nice");
}else if(Math.random()<1/100){
wrapperReact(message,"🤔");
}
});
client.login(process.env.TOKEN);
/*
client.on('messageReactionAdd', (reaction, user) => {
console.log(reaction.emoji.name);
});
//*/
//0x1F1E6 A
//send list of custom emojis
//const emojiList = message.guild.emojis.map(e=>e.toString()).join(" ");
//message.channel.send(emojiList);
//https://discordapp.com/oauth2/authorize?client_id=465959927119085569&scope=bot
//BLOCKHEAD
//DEMONICAL