-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (57 loc) · 2.08 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
import 'regenerator-runtime/runtime.js';
import * as Sphinx from 'sphinx-bot'
import * as fetch from 'node-fetch'
import axios from 'axios';
require('dotenv').config();
const msg_types = Sphinx.MSG_TYPE
let initted = false
let client
/*
// SPHINX_TOKEN contains id,secret,and url
// message.channel.send sends to the url the data
*/
const sphinxToken = process.env.SPHINX_TOKEN
async function init() {
if (initted) return
initted = true
client = new Sphinx.Client()
client.login(sphinxToken)
client.on(msg_types.INSTALL, async (message) => {
console.log('=> Installing')
const embed = new Sphinx.MessageEmbed()
.setAuthor('RustOff')
.setDescription('Welcome to RustOff! Enter /maxpaid followed by a number to set the maximum price for paid content.')
.setThumbnail(botSVG)
message.channel.send({ embed })
})
client.on(msg_types.MESSAGE, async (message) => {
const arr = message.content.split(' ')
if (arr.length < 2) return
if (arr[0] !== '/maxpaid') return
const maxAmount = parseInt(arr[1])
if(!maxAmount) return
const printOut = await fetchData(urlString)
console.log('printout', printOut)
const embed = new Sphinx.MessageEmbed()
.setAuthor('RustOff Bot')
.setTitle('Number Fact:')
.setDescription(printOut)
.setThumbnail(botSVG)
message.channel.send({ embed })
})
}
const botSVG = `<svg viewBox="64 64 896 896" height="12" width="12" fill="white">
<path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z" />
</svg>`
init()
const fetchData = (url) => {
return axios.get(url)
.then(res =>{
//handle success
console.log('res.data', res.data)
return res.data;
})
.catch(err => {
console.log(err);
})
}