cuy-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ var mysql = require('mysql');
2
+ var conn = mysql.createConnection({
3
+ host: process.env.DB_HOST,
4
+ user: process.env.DB_USERNAME,
5
+ password: process.env.DB_PASSWORD,
6
+ database: process.env.DB_DATABASE
7
+ });
8
+ conn.connect(function (err) {
9
+ if (err) throw err;
10
+ });
11
+ module.exports = conn;
package/bin/index.js ADDED
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+ const { config } = require('dotenv');
3
+ config()
4
+ const db = require('./database')
5
+ const program = require('commander')
6
+ const inq = require('inquirer')
7
+ const timestamp = Date.now();
8
+
9
+ const dateObject = new Date(timestamp);
10
+ const date = dateObject.getDate();
11
+ const month = dateObject.getMonth() + 1;
12
+ const year = dateObject.getFullYear();
13
+ const hour = dateObject.getUTCHours();
14
+ const minute = dateObject.getUTCMinutes();
15
+ const second = dateObject.getUTCSeconds();
16
+ const now = `${year}-${month}-${date} ${hour}:${minute}:${second}`
17
+
18
+ const posting = [
19
+ {
20
+ type: 'input',
21
+ name: 'description',
22
+ message: 'masukan deskripsi postingan: '
23
+ },
24
+ {
25
+ type: 'input',
26
+ name: 'hashtag',
27
+ message: 'gunakan # untuk hashtag (optional): '
28
+ },
29
+ {
30
+ type: 'input',
31
+ name: 'secret',
32
+ message: 'masukan secret kode yang anda miliki: '
33
+ }
34
+ ]
35
+
36
+ const search = [
37
+ {
38
+ type: 'input',
39
+ name: 'username',
40
+ message: 'masukan username yang ingin anda cari: '
41
+ }
42
+ ]
43
+
44
+ const menuList = [
45
+ {
46
+ type: 'list',
47
+ name: 'menu',
48
+ choices: ['find last seen user', 'create new posts'],
49
+ message: 'Pilih menu: '
50
+ }
51
+ ]
52
+
53
+ const cuyPost = (data) => {
54
+ if (data.description.length < 8 || data.description.length > 100) {
55
+ // MBxJn081At2MS1EMpx8J
56
+ console.log('deskripsi terlalu panjang! min:8 max:100');
57
+ return db.destroy();
58
+ }
59
+
60
+ if (data.hashtag.length < 2 || data.hashtag.length > 20) {
61
+ // MBxJn081At2MS1EMpx8J
62
+ console.log('hashtag terlalu panjang! min:2 max:20');
63
+ return db.destroy();
64
+ }
65
+
66
+ db.query(`SELECT * from users where secret='${data.secret}' AND cuycli=1`, (err, rows) => {
67
+ if (rows.length == 0) {
68
+ console.warn('Maaf, saat ini data yang anda masukan tidak dapat kami proses.')
69
+ return db.destroy();
70
+ }
71
+ if (!err) {
72
+ const { username, id } = rows[0]
73
+ db.query(`INSERT INTO posts (description, hashtag, author, user_id, created_at, updated_at) VALUES ('${data.description}', '${data.hashtag.replaceAll(' ', '')}', '${username}', '${id}', '${now}', '${now}')`, (err, rows) => {
74
+ if (!err) {
75
+ if (rows != null) {
76
+ console.info(`congrats ${username} :) anda berhasil membuat postingan baru. silahkan cek di https://cuyuniverse.co`);
77
+ db.destroy();
78
+ } else {
79
+ console.log('Terjadi kesalahan, saat ini anda tidak dapat membuat postingan via cuycli. Coba lagi nanti!');
80
+ db.destroy();
81
+ }
82
+ } else {
83
+ console.warn('Maaf, saat ini data yang anda masukan tidak dapat kami proses.')
84
+ }
85
+ })
86
+ }
87
+ })
88
+ }
89
+
90
+ const lastSeen = ({ username }) => {
91
+ db.query(`select last_seen from users where username='${username}'`, (err, rows) => {
92
+ if (rows.length > 0) {
93
+ last_seen = rows[0].last_seen
94
+ if (last_seen == null) {
95
+ console.info(`${username} belum pernah login`);
96
+ db.destroy();
97
+ } else {
98
+ console.info(`${username} terahir terlihat pada ${last_seen}`);
99
+ db.destroy();
100
+ }
101
+ }
102
+ else {
103
+ console.warn('Maaf, saat ini data yang anda masukan tidak dapat kami proses.')
104
+ return db.destroy();
105
+ }
106
+ })
107
+ }
108
+
109
+ program
110
+ .version('1.0.0')
111
+ .description('CUYUNIVERSE CLI')
112
+
113
+ program
114
+ .command('posting')
115
+ .alias('p')
116
+ .description('posting via terminal - deskripsi[spasi]hashtag(optional)[spasi]secretcode')
117
+ .action(() => {
118
+ inq.prompt(posting).then(postData => cuyPost(postData))
119
+ })
120
+
121
+ program
122
+ .command('lastseen')
123
+ .alias('ls')
124
+ .description('find cuypeople last seen activity by username')
125
+ .action(() => {
126
+ inq.prompt(search).then(username => lastSeen(username))
127
+ })
128
+
129
+ program.showHelpAfterError();
130
+
131
+ program.parse(process.argv);
132
+
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "cuy-cli",
3
+ "version": "1.0.0",
4
+ "description": "Cuyuniverse Command Line Tools",
5
+ "main": "index.js",
6
+ "preferGlobal": true,
7
+ "bin": {
8
+ "cuy-cli": "./bin/index.js"
9
+ },
10
+ "keywords": [
11
+ "cuycli",
12
+ "cuy-cli",
13
+ "cuyuniverse cli"
14
+ ],
15
+ "author": "Dea Afrizal",
16
+ "license": "ISC",
17
+ "dependencies": {
18
+ "commander": "^9.4.0",
19
+ "dotenv": "^16.0.1",
20
+ "inquirer": "^4.0.0",
21
+ "mysql": "^2.18.1"
22
+ }
23
+ }