@HazTheWaz/

GreetbyChip-1

Nodejs

Greets a discord user by sending "Hello/Hi, [user]" and chipflake.cf/s/hello (public build)

fork
loading
Files
  • index.js
  • info.json
  • package-lock.json
  • remove.js
  • server.js
index.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
let fs = require('fs');
let discord = require('discord.js');
//let info = require('./info.json');
let info = JSON.parse(fs.readFileSync('info.json'));
let keepAlive = require('./server');
let remove = require('./remove');
let bot = new discord.Client();
let talkedRecently = new Set();
let prefix = `c!`;
let greetings = [`Hi, `,`Hey, `,`Hello, `,`Welcome, `];
let array = JSON.parse(fs.readFileSync('info.json')).attacc;
info.embedColor = eval('('+info.embedColor+')');


bot.on('ready', () => {
 console.log(`Logged in as ${bot.user.tag} !`);
 bot.user.setActivity("Greeting");
});

/*
---THIS IS THE PUBLIC BUILD---
THIS BUILD GETS UPDATES LESS FREQUENTLY, BUT IS MORE RELIABLE THAN THE TEST BUILD
---END OF BLOCK---

To anyone reviewing this: 

- please allow the bot to be in the oof-topic channel
- the bot works on users who have opted-in (currently working on a command that does that for me)
- It's code works in a separate repl with the same code because I started developing it in a Private one, and can't unlock it.

and Yes I know it shouldn't be triggered by not-commands

checks if theres a new message, then checks if it's from a user in the given list (json)
If the message is from a user in json, send the hello message with the matching user and put's them on a 24h cooldown. Users are added on request by them.
Yes, Nognise and Zave gave perms to be greeted.
Yes, that is a defence system.
Yes, it can be triggered without a prefix (every 24h on message by a specified user, or when variable `attacc` is in a message).
Yes, it is under development

Currently trying to implement:
	optin -- not working, rolling back to manual
	optout -- not working, rolling back to manual
  resettimeout -- done
  expansion of attacc -- Thanks, H!
*/

bot.on('message', msg => {
  var i = 0
  var cGreet = greetings[Math.floor(Math.random()*greetings.length)];

  if (msg.content === prefix + `help`) {
    msg.author.send({embed: {
        title: `Currently Working commands:`,
        color: info.embedColor,
        fields: [{
            name: "c!help",
            value: "Displays this message in DMs."
          }, { 
            name: "c!info", 
            value: "Returns information about the contributors to the bot."
          }, { 
            name: "c!db", 
            value: "Displays the database in DM. (This command can only be used by Haziallat)"
          }, { 
            name: "c!resettimeout", 
            value: "Resets your timeout, so you can be greeted again at the very next message!"
          }, { 
            name: `The "attacc array"`, 
            value: ":smirk:"
          }, { 
            name: "c!sh", 
            value: "Emergency Shutdown  (This command can only be used by Haziallat)"
          }]
        }
      });
    return;
    }
  
  if (msg.content === prefix + `optin`) {
    if (msg.author.bot) return;
    if (info.id.indexOf(msg.author.id)) {
      msg.reply(`You're already opted in.`);
      return;
      } else {
    info.id.push(msg.author.id);
    info.uname.push(msg.author.username + `! `);
    msg.reply(`You opted in to being greeted.`);
    return;
    }
  }

  // if (msg.content === prefix + `optout`) {
    // if (msg.author.bot) return;
    // info.id.remove(msg.author.id);
    // info.uname.remove(msg.author.username);
    // msg.reply(`You opted out of being greeted.`);
    // return;
  // }

  if (msg.content === prefix + `resettimeout`) {
    if (msg.author.bot) return;
    talkedRecently.delete(msg.author.id);
    console.log("removed " + msg.author.tag + " (id:" + msg.author.id + ") from the waiting list");
    msg.reply("Reset your timeout.");
    return;
  }

  if (msg.content === prefix + `sh`) {
    if (msg.author.id != 162502976521371648) {
      return;
    } else {
      message.channel.send("Aw, Snap!");
      //yes i know
    }
  }
  
  if (msg.content === prefix + `db`) {
    if (msg.author.bot) return;
    if (msg.author.id != 162502976521371648) {
      return;
    } else {
      msg.author.send({embed: {
        title: `Current "Database"`,
        color: info.embedColor,
        fields: [{
            name: "Usernames",
            value: String(info.uname)
          }, { 
            name: "Description", 
            value: String(info.id)
          }]
        }
    });
    }
    return;
  }

  if (msg.content === prefix + `info`) {
    if (msg.author.bot) return;
    msg.channel.send({embed: {
      tilte: `Information:`,
      color: info.embedColor,
      fields: [{
          name: "Created by",
          value: "Haziallat"
      }, {
          name: "Fixed by",
          value: "Edwin"
      }, {
          name: "Special thanks to",
          value: "H, Kpasta"
      }]
    }
  });
    return;
  }

  array.forEach(thing => {
    if(msg.content.toLowerCase().indexOf(thing.toLowerCase()) > -1) {
        msg.reply(`Wrong`);
        return;
    }
  });

  // if (msg.content.toLowerCase() == attacc.toLowerCase()) {
    // if (msg.author.bot) return;
    // msg.reply(`Wrong`);
    // return;
   // }
   
  if (talkedRecently.has(msg.author.id)) {
    return;
  } else {
  for(var i = 0; i < 1; i++) {
    if (msg.author.bot) return;
    let user = msg.author;
    if (user.id === info.id[0] ) {
      msg.channel.send(cGreet + info.uname[0] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[1] ) {
      msg.channel.send(cGreet + info.uname[1] + `! :3` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[2] ) {
      console.log("gamma foo");
      msg.channel.send(cGreet + info.uname[2] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[3] ) {
      msg.channel.send(cGreet + info.uname[3] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[4] ) {
      msg.channel.send(cGreet + info.uname[4] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[5] ) {
      msg.channel.send(cGreet + info.uname[5] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[6] ) {
      msg.channel.send(cGreet + info.uname[6] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[7] ) {
      msg.channel.send(cGreet + info.uname[7] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[8] ) {
      msg.channel.send(cGreet + info.uname[8] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[9] ) {
      msg.channel.send(cGreet + info.uname[9] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[10] ) {
      msg.channel.send(cGreet + info.uname[10] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[11] ) {
      msg.channel.send(cGreet + info.uname[11] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[12] ) {
      msg.channel.send(cGreet + info.uname[12] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[13] ) {
      msg.channel.send(cGreet + info.uname[13] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[14] ) {
      msg.channel.send(cGreet + info.uname[14] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[15] ) {
      msg.channel.send(cGreet + info.uname[15] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[16] ) {
      msg.channel.send(cGreet + info.uname[16] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[17] ) {
      msg.channel.send(cGreet + info.uname[17] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[18] ) {
      msg.channel.send(cGreet + info.uname[18] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[19] ) {
      msg.channel.send(cGreet + info.uname[19] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else if (user.id === info.id[20] ) {
      msg.channel.send(cGreet + info.uname[20] + `!` + ` https://chipflake.cf/s/hello`);	 
      var i = i+1
    }

    else {
      return;
    }
   }
   talkedRecently.add(msg.author.id);
   console.log(`added ` + msg.author.tag + ` (id: ` + msg.author.id + `)` + ` to the waiting list`)
        setTimeout(() => {
          // Removes the user from the set after a day
          talkedRecently.delete(msg.author.id);
        }, 86400000);
    }
});
keepAlive();
bot.login(process.env.TOKEN);
node v10.16.0