-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (90 loc) · 2.46 KB
/
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
const inquirer = require('inquirer');
const fetch = require('node-fetch');
const chalk = require('chalk');
const xss = require('xss');
const API_URL = 'https://ls.terminal.ink';
const makeSpace = (length) => {
let output = '';
for (let i = 0; i < length; i++) {
output += ' ';
}
return output;
}
const makeDangerous = contents => contents
.replace('>', '>')
.replace('<', '<')
.replace('&', '&')
.replace('"', '"')
.replace(''', '\'')
const mainMenu = () => {
return inquirer
.prompt({
type: 'rawlist',
name: 'type',
message: 'Please select a type of application',
choices: [
{
name: 'Bots',
value: 'bots'
}, {
name: 'RPC Applications',
value: 'rpc'
}, {
name: 'Exit',
value: 'exit'
}
]
})
}
const appMenu = (type, apps) => {
return inquirer
.prompt({
type: 'rawlist',
name: 'id',
message: 'Please select the application you wish to look at',
choices: apps
.filter(app => app.type === type)
.filter(bot => bot.contents)
.map(bot => ({
name: bot.contents.name,
value: bot.id
}))
})
}
const displayApp = (app) => {
const contents = xss(app.contents.page, {
whitelist: [],
stripIgnoreTag: true,
stripIgnoreTagBody: ['script', 'style']
});
console.log(`
${chalk.black.bgCyan(` ${makeSpace(app.contents.name.length)} `)}
${chalk.black.bgCyan(` ${app.contents.name} `)}
${chalk.black.bgCyan(` ${makeSpace(app.contents.name.length)} `)}
${chalk.italic(app.contents.description)}
---------------------------
${makeDangerous(contents)}
`);
}
(async () => {
console.log('Please wait...');
const fetchedApps = await fetch(`${API_URL}/api/v2/apps`)
.then(res => res.json())
const apps = fetchedApps.data.map((bot) => {
bot.contents = bot.contents[0];
return bot;
})
while(true) {
const { type } = await mainMenu();
if (type === 'exit') {
console.log(`This version of Discord Apps Marketplace is ${chalk.red('SHAREWARE')}.
Software licences start at just £1.99.
Read MAILORDR.TXT or MAILORDR.RTF for instructions on how to send in a mail order.
Thanks for visiting.
${chalk.underline('Copyright Internet Terminal Solutions Corp., 1983 - 1989')}`)
process.exit(0);
}
const { id } = await appMenu(type, apps);
displayApp(apps.find(bot => bot.id === id));
}
})();