· 6 years ago · Oct 02, 2019, 11:26 AM
1const http = require('http');
2const express = require('express');
3const app = express();
4
5app.get("/", (request, response) => {
6 console.log(Date.now() + " Ping Received");
7 response.sendStatus(200);
8});
9app.listen(process.env.PORT);
10setInterval(() => {
11 http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
12}, 280000);
13
14const Discord = require("discord.js");
15const bot = new Discord.Client({ disableEveryone: true});
16const config = require("./config.json");
17
18bot.on("ready", async () => {
19 console.log(`${bot.user.username} sudah online!`);
20});
21
22bot.on('message', async message => {
23 let prefix = "k!";
24 // let messageArray = message.content.split(" ");
25 let cmd = message.content.slice(prefix.length).split(' ')[0]; //messageArray[0];
26 let args = message.content.split(' ');
27
28 if (!message.content.startsWith(prefix)) return;
29
30 try {
31 let commandFile = require(`./cmds/${cmd}.js`);
32 commandFile.run(bot, message, args, prefix);
33} catch (e) {
34 console.log(e.message)
35} finally {
36 console.log(`${message.author.username} menggunakan perintah ${cmd}`);
37}
38
39 if (message.content == 'k!ping') {
40 let embed = new Discord.RichEmbed()
41 .setColor('RANDOM')
42 .setDescription(`:ping_pong: Pong! \`${Date.now() - message.createdAt}ms\``)
43 message.channel.send(embed);
44 }
45
46 if(message.content.startsWith("k!say")) {
47 let text = args.slice(1).join(' ');
48 if (!text) return message.channel.send('What can i say?');
49 return message.channel.send(text);
50 }
51
52 if (message.content.startsWith ('k!hug')) {
53 let hug = [
54 "https://media.giphy.com/media/iviBUyNqP46Aw/giphy.gif",
55 "https://i.imgur.com/r9aU2xv.gif",
56 "https://i.imgur.com/v47M1S4.gif",
57 "https://i.imgur.com/BPLqSJC.gif",
58 "https://i.imgur.com/4oLIrwj.gif",
59 "https://i.imgur.com/82xVqUg.gif",
60 "https://media1.tenor.com/images/9ca25e9e87ed4fc099b5f4199b0fb436/tenor.gif",
61 "https://media1.tenor.com/images/d7529f6003b20f3b21f1c992dffb8617/tenor.gif",
62 "https://media.tenor.com/images/934adba8e5516096e526f955458ec94a/tenor.gif",
63 "https://media.tenor.com/images/c3e8378979ac16800ebcae3922c90090/tenor.gif",
64 "https://media.tenor.com/images/807a4616f1208ad3dad7b584050d0f25/tenor.gif",
65 "https://media1.tenor.com/images/94c44a9898927f22dff399c2c248f433/tenor.gif",
66 "https://media.tenor.com/images/b569675248246c3988c45dbf3d055cd0/tenor.gif",
67 ]
68 let hugresult = Math.floor((Math.random() * hug.length));
69 if (!args[0]) {
70 const ghembed = new Discord.RichEmbed()
71 .setColor(`RANDOM`)
72 .setTitle(`${message.author.username} hug themself...! (aww)`)
73 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/hug.gif')
74 message.channel.send({
75 embed: ghembed
76 })
77 return;
78 }
79 if (!message.mentions.members.first().user.username === message.isMentioned(message.author)) {
80 const hembed = new Discord.RichEmbed()
81 .setColor(`RANDOM`)
82 .setTitle(`${message.author.username} gave ${message.mentions.members.first().user.username} a hug! wow so sweet!`)
83 .setImage(hug[hugresult])
84 message.channel.send({
85 embed: hembed
86 })
87 return;
88 }
89 const ghembed = new Discord.RichEmbed()
90 .setColor(`RANDOM`)
91 .setTitle(`${message.author.username} hug themself...! (aww)`)
92 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/hug.gif')
93 message.channel.send({
94 embed: ghembed
95 })
96}
97
98 if (message.content.startsWith ('k!slap')) {
99 let slap = [
100 "https://media1.tenor.com/images/85722c3e51d390e11a0493696f32fb69/tenor.gif",
101 "https://media.tenor.com/images/5f29f333980601ed94c4357bdcb75652/tenor.gif",
102 "https://media.tenor.com/images/a2ec7d51b7a8e4c74a5b2d8add44f07a/tenor.gif",
103 "https://media.tenor.com/images/a9a4fa8958fe746c6dca54b1383ab361/tenor.gif",
104 "https://media.tenor.com/images/491fe527d67d22d363dd53c7a33deed9/tenor.gif",
105 "https://media.tenor.com/images/0965d68160781edb0b1de4e47d5a11ba/tenor.gif",
106 "https://i.imgur.com/fm49srQ.gif",
107 "https://i.imgur.com/oOCq3Bt.gif",
108 "https://i.imgur.com/CwbYjBX.gif",
109 "https://media.tenor.com/images/f60e0a3bf7040edb043ab7432c450757/tenor.gif",
110 "https://media.tenor.com/images/6f8c86917816bc65e36731891d775159/tenor.gif",
111 "https://media.tenor.com/images/46e1c0815a398f6d081094113c88755c/tenor.gif",
112 "https://media.tenor.com/images/332854b46da66c11bf69c0000a6a21f8/tenor.gif",
113 "https://media.tenor.com/images/b9b4a34aab0446846672d9a0c0523d74/tenor.gif",
114 "https://media.tenor.com/images/b4a78120936ae0072f57cb5afae48ffa/tenor.gif",
115 "https://media.tenor.com/images/904d06d1404a9c9c232b6a82f2199a30/tenor.gif",
116 "https://media.tenor.com/images/9498f97cef953043ff27014704a39346/tenor.gif",
117 ]
118 let hugresult = Math.floor((Math.random() * slap.length));
119 if (!args[0]) {
120 const ghembed = new Discord.RichEmbed()
121 .setColor(`RANDOM`)
122 .setTitle(`${message.author.username} slap themself...! (sakitt)`)
123 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/slap.gif')
124 message.channel.send({
125 embed: ghembed
126 })
127 return;
128 }
129 if (!message.mentions.members.first().user.username === message.isMentioned(message.author)) {
130 const hembed = new Discord.RichEmbed()
131 .setColor(`RANDOM`)
132 .setTitle(`${message.author.username} gave ${message.mentions.members.first().user.username} a slap! Sakit Ga tuh, Mamam!`)
133 .setImage(slap[hugresult])
134 message.channel.send({
135 embed: hembed
136 })
137 return;
138 }
139 const ghembed = new Discord.RichEmbed()
140 .setColor(`RANDOM`)
141 .setTitle(`${message.author.username} slap diri sendiri...! (sakittt)`)
142 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/slap.gif')
143 message.channel.send({
144 embed: ghembed
145 })
146}
147
148
149 if (message.content.startsWith ('k!kiss')) {
150 let kiss = [
151 "https://media1.tenor.com/images/395b565d26a74bcf6b6fc8cea50df021/tenor.gif",
152 "http://cdn.smosh.com/wp-content/uploads/ftpuploads/bloguploads/awkward-kiss-little-girl.gif",
153 "https://thumbs.gfycat.com/BasicPeskyGuillemot-max-1mb.gif",
154 "https://i.pinimg.com/originals/fe/64/e9/fe64e9e2f16ced383c0cb69e5f71722d.gif",
155 "http://25.media.tumblr.com/e7f39c316f0923710c9b12e9583455ba/tumblr_mj7yrrtFaa1s7cfr2o1_500.gif",
156 "https://media2.giphy.com/media/TkDX9bkIROf8k/giphy.gif",
157 "http://gifimage.net/wp-content/uploads/2017/09/anime-gif-kiss-11.gif",
158 "https://i.imgur.com/eisk88U.gif",
159 "https://i.pinimg.com/originals/42/c3/85/42c3851fc31dc3434dfe5fa7e3463f1d.gif",
160 "https://i.makeagif.com/media/7-05-2015/553Vsb.gif",
161 "https://i.gifer.com/2II9.gif",
162 "http:/http://gif-finder.com/wp-content/uploads/2015/09/Angry-Birds-Orange-Kiss.gif/a.fod4.com/images/GifGuide/michael_scott/119477_o.gif",
163 "http://gif-finder.com/wp-content/uploads/2015/09/Angry-Birds-Orange-Kiss.gif",
164 "https://media1.tenor.com/images/6af13a438013667a81031dde8d6b6931/tenor.gif",
165 "https://media1.tenor.com/images/a3e63e98f0344a2e9a040ea5df3769b0/tenor.gif",
166 "https://media1.tenor.com/images/fb92d0be78a1ea19af0168c0ca29c1bd/tenor.gif?itemid=5615952",
167
168 ]
169 let hugresult = Math.floor((Math.random() * kiss.length));
170 if (!args[0]) {
171 const ghembed = new Discord.RichEmbed()
172 .setColor(`RANDOM`)
173 .setTitle(`${message.author.username} kiss themself...! (weirdo)`)
174 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/kiss.gif')
175 message.channel.send({
176 embed: ghembed
177 })
178 return;
179 }
180 if (!message.mentions.members.first().user.username === message.isMentioned(message.author)) {
181 const hembed = new Discord.RichEmbed()
182 .setColor(`RANDOM`)
183 .setTitle(`${message.author.username} gave ${message.mentions.members.first().user.username} a kiss! wow so sweet!`)
184 .setImage(kiss[hugresult])
185 message.channel.send({
186 embed: hembed
187 })
188 return;
189 }
190 const ghembed = new Discord.RichEmbed()
191 .setColor(`RANDOM`)
192 .setTitle(`${message.author.username} kiss themself...! (aww)`)
193 .setImage('https://cdn.discordapp.com/attachments/452115003659780096/460369555823525898/kiss.gif')
194 message.channel.send({
195 embed: ghembed
196 })
197}
198
199
200 if (message.content == 'k!help') {
201 var footertext = [`${bot.user.username} : ©robs.s.kom`];
202 var rand = Math.floor(Math.random() * footertext.leght);
203 var randomfooter = footertext[Math.floor(Math.random() * footertext.length)];
204 let boticon = bot.user.displayAvatarURL
205 let embed = new Discord.RichEmbed()
206 .setColor('RANDOM')
207 .setThumbnail("https://cdn.discordapp.com/avatars/496464427055448067/b90368718d7b41814ec152a31f98042d.png?size=2048")
208 .setAuthor(`List All Command`)
209 .setDescription(`My Prefix is ( k! )`)
210 .addField(`? **Info**`, `\`ping,\` \`help,\` \`say\``)
211 .addField(`⏯️ **Music**`, `\`play,\` \`skip,\` \`pause,\` \`resume,\` \`np,\` \`queue,\` \`stop,\` \`volume\``)
212 .addField(`:tada: **Fun**`, `\`kiss,\` \`hug,\` \`slap\``)
213 .addField(`**__Usefull Links__**`, `[invite bot](https://discordapp.com/oauth2/authorize?client_id=496464427055448067&permissions=8&scope=bot)`)
214 .setTimestamp()
215 .setFooter(`${randomfooter}`,`${boticon}`)
216 message.channel.send(embed)
217 }
218
219});
220
221bot.login(process.env.SECRET)
222
223
224
225SERVER.JS
226// server.js
227// where your node app starts
228
229// init project
230var express = require('express');
231var bodyParser = require('body-parser');
232var app = express();
233app.use(bodyParser.urlencoded({ extended: true }));
234
235// we've started you off with Express,
236// but feel free to use whatever libs or frameworks you'd like through `package.json`.
237
238// http://expressjs.com/en/starter/static-files.html
239app.use(express.static('public'));
240
241// init sqlite db
242var fs = require('fs');
243var dbFile = './.data/sqlite.db';
244var exists = fs.existsSync(dbFile);
245var sqlite3 = require('sqlite3').verbose();
246var db = new sqlite3.Database(dbFile);
247
248// if ./.data/sqlite.db does not exist, create it, otherwise print records to console
249db.serialize(function(){
250 if (!exists) {
251 db.run('CREATE TABLE Dreams (dream TEXT)');
252 console.log('New table Dreams created!');
253
254 // insert default dreams
255 db.serialize(function() {
256 db.run('INSERT INTO Dreams (dream) VALUES ("Find and count some sheep"), ("Climb a really tall mountain"), ("Wash the dishes")');
257 });
258 }
259 else {
260 console.log('Database "Dreams" ready to go!');
261 db.each('SELECT * from Dreams', function(err, row) {
262 if ( row ) {
263 console.log('record:', row);
264 }
265 });
266 }
267});
268
269// http://expressjs.com/en/starter/basic-routing.html
270app.get('/', function(request, response) {
271 response.sendFile(__dirname + '/views/index.html');
272});
273
274// endpoint to get all the dreams in the database
275// currently this is the only endpoint, ie. adding dreams won't update the database
276// read the sqlite3 module docs and try to add your own! https://www.npmjs.com/package/sqlite3
277app.get('/getDreams', function(request, response) {
278 db.all('SELECT * from Dreams', function(err, rows) {
279 response.send(JSON.stringify(rows));
280 });
281});
282
283// listen for requests :)
284var listener = app.listen(process.env.PORT, function() {
285 console.log('Your app is listening on port ' + listener.address().port);
286});
287
288
289CONFIG.JSON
290 {
291 "Prefix": "k!",
292 "token": ""
293}
294
295
296
297PACKAGE.JSON
298
299{
300 "//1": "describes your app and its dependencies",
301 "//2": "https://docs.npmjs.com/files/package.json",
302 "//3": "updating this file will download and update your packages",
303 "name": "hello-sqlite",
304 "version": "0.0.1",
305 "description": "A simple Node app with SQLite as a database management system, instantly up and running.",
306 "main": "run.js",
307 "scripts": {
308 "start": "node bot.js"
309 },
310 "dependencies": {
311 "discord.js": "^11.4.2",
312 "express": "^4.16.3",
313 "sqlite3": "^4.0.2"
314 },
315 "engines": {
316 "node": "8.x"
317 },
318 "repository": {
319 "url": "https://glitch.com/edit/#!/hello-sqlite"
320 },
321 "license": "MIT",
322 "keywords": [
323 "node",
324 "glitch",
325 "express"
326 ]
327}