├── Procfile
├── .vscode
└── settings.json
├── src
├── example.config.json
├── commands
│ ├── donate.js
│ ├── github.js
│ ├── discord.js
│ ├── help.js
│ ├── coins.js
│ └── crypto.js
└── coinIDs.json
├── .eslintrc.js
├── .travis.yml
├── README.md
├── test
└── api.test.js
├── LICENSE
├── package.json
├── index.js
└── .gitignore
/Procfile:
--------------------------------------------------------------------------------
1 | worker: node index.js
2 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "git.ignoreLimitWarning": true
3 | }
--------------------------------------------------------------------------------
/src/example.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "prefix": "!",
3 | "token": "your_bot_token_here"
4 | }
5 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "extends": "airbnb-base",
3 | "env": {
4 | "jest": true
5 | }
6 | };
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | sudo: false
3 | node_js:
4 | - "8.11.1"
5 | install:
6 | - npm install
7 | script:
8 | - npm run lint
9 | - npm run test
10 | after_success:
11 | - wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
12 | - chmod +x send.sh
13 | - ./send.sh success $WEBHOOK_URL
14 | after_failure:
15 | - wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh
16 | - chmod +x send.sh
17 | - ./send.sh failure $WEBHOOK_URL
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Coin bot []()
2 |
3 | # :warning: :warning: This bot is no longer under maintainence :warning: :warning:
4 |
5 | ## Add bot to your Discord server!
6 |
7 | OAuth link:
8 |
9 | > [discordapp.com/coinbot](https://discordapp.com/oauth2/authorize?client_id=%20395240399750299658&scope=bot&permissions=0)
10 |
11 | With any questions join our [discord](https://discord.gg/7q5VcC6) server
12 |
13 | :warning: Remember about giving bot role with proper permissions! :warning:
14 |
--------------------------------------------------------------------------------
/test/api.test.js:
--------------------------------------------------------------------------------
1 | const coinID = require('../src/coinIDs.json');
2 | const request = require('supertest');
3 |
4 | const BASE_URL = 'https://api.coinmarketcap.com/v2/ticker/';
5 |
6 | describe('GET all coins (coinmarketcap)', () => {
7 | Object.entries(coinID.coinmarketcap).map(([key, value]) => it(`respond with ${key}`, (done) => {
8 | request(BASE_URL)
9 | .get(`${value}/?convert=PLN`)
10 | .set('Accept', 'application/json')
11 | .expect('Content-Type', 'application/json')
12 | .expect(res => expect(res.body.data.quotes.PLN.price).not.toBeNull())
13 | .expect(200, done);
14 | }));
15 | });
16 |
--------------------------------------------------------------------------------
/src/commands/donate.js:
--------------------------------------------------------------------------------
1 | const TurndownService = require('turndown')
2 | const debug = require('debug')
3 |
4 | const turndownService = new TurndownService()
5 |
6 | const mess = async (message) => {
7 | try {
8 | const embed = {
9 | title: 'Donate us by PayPal',
10 | author: {
11 | name: 'Paypal.me',
12 | url: 'https://www.paypal.me',
13 | icon_url: 'https://i.imgur.com/CxxgcQH.png',
14 | },
15 | description: turndownService.turndown(
16 | 'Donate here'
17 | ),
18 | color: 151511,
19 | footer: {
20 | icon_url:
21 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
22 | text: 'Coinbot by fosscord',
23 | },
24 | }
25 | message.channel.send({ embed })
26 | } catch (err) {
27 | debug(err)
28 | }
29 | }
30 |
31 | module.exports = mess
32 |
--------------------------------------------------------------------------------
/src/commands/github.js:
--------------------------------------------------------------------------------
1 | const TurndownService = require('turndown')
2 | const debug = require('debug')
3 |
4 | const turndownService = new TurndownService()
5 |
6 | const git = async (message) => {
7 | try {
8 | const embed = {
9 | title: 'Github Repository',
10 | author: {
11 | name: 'Github.com',
12 | url: 'https://www.github.com',
13 | icon_url:
14 | 'https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png',
15 | },
16 | description: turndownService.turndown(
17 | 'CoinBot repository link'
18 | ),
19 | color: 2369838,
20 | footer: {
21 | icon_url:
22 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
23 | text: 'Coinbot by fosscord',
24 | },
25 | }
26 | message.channel.send({ embed })
27 | } catch (err) {
28 | debug(err)
29 | }
30 | }
31 |
32 | module.exports = git
33 |
--------------------------------------------------------------------------------
/src/commands/discord.js:
--------------------------------------------------------------------------------
1 | const TurndownService = require('turndown')
2 | const debug = require('debug')
3 |
4 | const turndownService = new TurndownService()
5 |
6 | const mess = async (message) => {
7 | try {
8 | const embed = {
9 | title: 'Join our discord server',
10 | author: {
11 | name: 'Discord',
12 | url: 'https://discordapp.com/',
13 | icon_url:
14 | 'https://icon2.cleanpng.com/20180628/kvf/kisspng-discord-computer-servers-teamspeak-discord-icon-5b34991d1d3e09.8364918215301737251198.jpg',
15 | },
16 | description: turndownService.turndown(
17 | 'Join via this link!'
18 | ),
19 | color: 151511,
20 | footer: {
21 | icon_url:
22 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
23 | text: 'Coinbot by fosscord',
24 | },
25 | }
26 | message.channel.send({ embed })
27 | } catch (err) {
28 | debug(err)
29 | }
30 | }
31 |
32 | module.exports = mess
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/commands/help.js:
--------------------------------------------------------------------------------
1 | const debug = require('debug')('help')
2 |
3 | const help = async (message) => {
4 | try {
5 | const embed = {
6 | title: 'Coin bot commands:',
7 | description:
8 | '- !help (All commands)\n- !coins (All coins)\n- !github (Coin bot repository)\n- !donate (We are collecting for hosting)\n**Now in coins embeds you can find charts!**',
9 | color: 0x4c4cff,
10 | footer: {
11 | icon_url:
12 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
13 | text: 'Coin bot by fosscord',
14 | },
15 | author: {
16 | name: 'Coin bot',
17 | url: 'https://github.com/quritto/coin_bot',
18 | icon_url:
19 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
20 | },
21 | fields: [
22 | {
23 | name: 'Legend:',
24 | value:
25 | ':clock1: - 1 hour\n:calendar: - 24 hours\n:calendar_spiral: - 7 days',
26 | },
27 | ],
28 | }
29 | await message.channel.send({ embed })
30 | } catch (err) {
31 | debug(err)
32 | }
33 | }
34 |
35 | module.exports = help
36 |
--------------------------------------------------------------------------------
/src/coinIDs.json:
--------------------------------------------------------------------------------
1 | {
2 | "coinmarketcap": {
3 | "btc": 1,
4 | "bitcoin": 1,
5 | "eth": 1027,
6 | "ethereum": 1027,
7 | "ltc": 2,
8 | "litecoin": 2,
9 | "lsk": 1214,
10 | "lisk": 1214,
11 | "dash": 131,
12 | "dsh": 131,
13 | "btg": 2083,
14 | "btcgold": 2083,
15 | "bitcoingold": 2083,
16 | "xmr": 328,
17 | "monero": 328,
18 | "xrp": 52,
19 | "ripple": 52,
20 | "doge": 74,
21 | "dogecoin": 74,
22 | "etn": 2137,
23 | "electroneum": 2137,
24 | "papajcoin": 2137,
25 | "bch": 1831,
26 | "bcc": 1831,
27 | "btccash": 1831,
28 | "bitcoincash": 1831,
29 | "eos": 1765,
30 | "iota": 1720,
31 | "miota": 1720,
32 | "zec": 1437,
33 | "zcash": 1437,
34 | "steem": 1230,
35 | "stm": 1230,
36 | "steemdollar": 1312,
37 | "steemdollars": 1312,
38 | "sbd": 1312,
39 | "mag": 2218,
40 | "magnet": 2218,
41 | "nexo": 2694,
42 | "holo": 2682,
43 | "hot": 2682,
44 | "etc": 1321
45 | },
46 | "coincapio": {
47 | "doge": "DOGE"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "coinbot",
3 | "version": "0.7.0",
4 | "description": "Crypto bot",
5 | "main": "./src/index.js",
6 | "dependencies": {
7 | "axios": "^0.18.1",
8 | "cryptiles": "^4.1.2",
9 | "debug": "^3.1.0",
10 | "discord.js": "^11.3.2",
11 | "plotly": "^1.0.6",
12 | "turndown": "^4.0.2",
13 | "unix-timestamp-transform": "0.0.5"
14 | },
15 | "devDependencies": {
16 | "eslint": "^5.14.1",
17 | "eslint-config-airbnb-base": "^12.1.0",
18 | "eslint-plugin-import": "^2.11.0",
19 | "eslint-plugin-jsx-a11y": "^6.0.3",
20 | "jest": "^24.9.0",
21 | "nodemon": "^1.17.3",
22 | "supertest": "^3.0.0"
23 | },
24 | "scripts": {
25 | "start": "nodemon src/index.js",
26 | "lint": "eslint --ext .js, src test",
27 | "lint:fix": "eslint --ext .js, --fix src test",
28 | "test": "jest --forceExit --verbose"
29 | },
30 | "repository": {
31 | "type": "git",
32 | "url": "git+https://github.com/animek66/coin_bot"
33 | },
34 | "author": "animek66",
35 | "license": "MIT",
36 | "bugs": {
37 | "url": "https://github.com/animek66/coin_bot/issues"
38 | },
39 | "homepage": "https://github.com/animek66/coin_bot/blob/master/README.md",
40 | "jest": {
41 | "moduleFileExtensions": [
42 | "js",
43 | "json",
44 | "node"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const Discord = require('discord.js')
2 | const debug = require('debug')('index')
3 | const config = require('./src/config.json')
4 | const crypto = require('./src/commands/crypto')
5 | const coins = require('./src/commands/coins')
6 | const help = require('./src/commands/help')
7 | const donate = require('./src/commands/donate')
8 | const github = require('./src/commands/github')
9 | const discord = require('./src/commands/discord')
10 | const token = require('./src/config.json').token
11 |
12 | const client = new Discord.Client()
13 |
14 | client.login(token)
15 |
16 | client.on('ready', () => {
17 | console.log(
18 | `Coin bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`
19 | )
20 | client.user.setPresence({
21 | game: { name: client.users.size + ' miners', type: 3 },
22 | })
23 | })
24 |
25 | client.on('message', async (message) => {
26 | if (message.content.substring(0, config.prefix.length) === config.prefix) {
27 | const command = message.content.slice(config.prefix.length)
28 |
29 | switch (command) {
30 | case 'coins':
31 | coins(message)
32 | break
33 | case 'help':
34 | help(message)
35 | break
36 | case 'donate':
37 | donate(message)
38 | break
39 | case 'github':
40 | github(message)
41 | break
42 | case 'discord':
43 | discord(message)
44 | break
45 | default:
46 | crypto(message, command)
47 | }
48 | }
49 | })
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Node template
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 |
10 | # Runtime data
11 | pids
12 | *.pid
13 | *.seed
14 | *.pid.lock
15 |
16 | # Directory for instrumented libs generated by jscoverage/JSCover
17 | lib-cov
18 |
19 | # Coverage directory used by tools like istanbul
20 | coverage
21 |
22 | # nyc test coverage
23 | .nyc_output
24 |
25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26 | .grunt
27 |
28 | # Bower dependency directory (https://bower.io/)
29 | bower_components
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (http://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules/
39 | jspm_packages/
40 |
41 | # Typescript v1 declaration files
42 | typings/
43 |
44 | # Optional npm cache directory
45 | .npm
46 |
47 | # Optional eslint cache
48 | .eslintcache
49 |
50 | # Optional REPL history
51 | .node_repl_history
52 |
53 | # Output of 'npm pack'
54 | *.tgz
55 |
56 | # Yarn Integrity file
57 | .yarn-integrity
58 |
59 | # dotenv environment variables file
60 | .env
61 |
62 | ### Example user template template
63 | ### Example user template
64 |
65 | # IntelliJ project files
66 | .idea
67 | *.iml
68 | out
69 | gen### Example user template template
70 | ### Example user template
71 |
72 | # IntelliJ project files
73 | gen
74 |
75 |
76 | dist
77 | VERY VERY IMPORTANT
78 | src/token.json
79 |
80 | .vscode
81 |
82 | src/token\.js
83 |
84 | src/config.json
85 |
--------------------------------------------------------------------------------
/src/commands/coins.js:
--------------------------------------------------------------------------------
1 | const TurndownService = require('turndown')
2 | const debug = require('debug')('coins')
3 |
4 | const turndownService = new TurndownService()
5 |
6 | const coin = async (message) => {
7 | try {
8 | const embed = {
9 | title: 'Available coins price:',
10 | description: `
11 | - !btc (BitCoin)
12 | - !eth (Ethereum)
13 | - !ltc (LiteCoin)
14 | - !btg (BitCoin Gold)
15 | - !dash (DASH)
16 | - !xmr (Monero)
17 | - !xrp (Ripple)
18 | - !lsk (Lisk)
19 | - !mag (Magnet)
20 | - !doge (DogeCoin)
21 | - !bch (BitCoin cash)
22 | - !etn (Electroneum)
23 | - !eos (EOS)
24 | - !iota (IOTA)
25 | - !zcash (ZEC)
26 | - !sbd (Steem Dollars)
27 | - !etc (Ethereum Classic)
28 | - !steem (STEEM)`,
29 | color: 0xc6ff00,
30 | footer: {
31 | icon_url:
32 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
33 | text: 'Coin bot by fosscord',
34 | },
35 | author: {
36 | name: 'Coin bot',
37 | url: 'https://github.com/quritto/coin_bot',
38 | icon_url:
39 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
40 | },
41 | fields: [
42 | {
43 | name: "You don't see your favourite coin?",
44 | value: turndownService.turndown(
45 | 'Write your coin in issue here:Github.com'
46 | ),
47 | },
48 | ],
49 | }
50 | await message.channel.send({ embed })
51 | } catch (err) {
52 | debug(err)
53 | }
54 | }
55 |
56 | module.exports = coin
57 |
--------------------------------------------------------------------------------
/src/commands/crypto.js:
--------------------------------------------------------------------------------
1 | const axios = require('axios')
2 | const debug = require('debug')('crypto')
3 | const coinIDs = require('../coinIDs.json')
4 |
5 | function colors(data) {
6 | if (data.quotes.USD.percent_change_1h < 0) return 0xf44336
7 | return 0x00e676
8 | }
9 |
10 | const responder = async (message, command) => {
11 | try {
12 | const coinID = coinIDs.coinmarketcap[command]
13 | if (!(coinID === undefined || typeof coinID === 'undefined')) {
14 | const query = await axios.get(
15 | `https://api.alternative.me/v2/ticker/${coinID}/?convert=PLN`
16 | )
17 |
18 | const data = query.data.data[coinID]
19 |
20 | const embed = {
21 | title: `[${data.symbol}] ${data.name} price:`,
22 | description: ` - ${data.quotes.USD.price.toFixed(
23 | 2
24 | )} USD\n- ${data.quotes.PLN.price.toFixed(
25 | 2
26 | )} PLN\n**Percent Change in:**\n:clock1: :arrow_right: ${
27 | data.quotes.USD.percentage_change_1h
28 | }% (1 hour)\n:calendar: :arrow_right: ${
29 | data.quotes.USD.percentage_change_24h
30 | }% (24 hours)\n:calendar_spiral: :arrow_right: ${
31 | data.quotes.USD.percentage_change_7d
32 | }% (7 days)`,
33 | color: colors(data),
34 | timestamp: new Date(data.last_updated * 1000),
35 | footer: {
36 | icon_url:
37 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
38 | text: 'Coin bot by fosscord',
39 | },
40 | image: {
41 | url: `https://s2.coinmarketcap.com/generated/sparklines/web/30d/usd/${coinID}.png`,
42 | },
43 | author: {
44 | name: 'Coin bot',
45 | url: 'https://github.com/quritto/coin_bot',
46 | icon_url:
47 | 'https://cdn.discordapp.com/avatars/395240399750299658/1e9edd0c9edf5a6edb9fd36fcd693a9f.png',
48 | },
49 | fields: [
50 | {
51 | name: 'Chart from last 30 days:',
52 | value: '**More charts coming soon**',
53 | },
54 | ],
55 | }
56 |
57 | message.channel.send({ embed })
58 | } else {
59 | debug(`${command} is an undefined coin`)
60 | }
61 | } catch (err) {
62 | console.log(err)
63 | }
64 | }
65 |
66 | module.exports = responder
67 |
--------------------------------------------------------------------------------