· 5 years ago · May 26, 2020, 11:34 PM
1const botconfig = require('./config.json');
2const Discord = require('discord.js');
3const myApis = [
4 'https://withhive.com/api/notice/list/?page=1',
5 'https://withhive.com/api/notice/list/?page=2',
6 'https://withhive.com/api/notice/list/?page=3',
7 'https://withhive.com/api/notice/list/?page=6',
8];
9//"https://withhive.com/api/notice/list/?type=E"
10const axios = require('axios');
11const sqlite = require('sqlite3').verbose();
12const bot = new Discord.Client();
13
14bot.on('ready', async () => {
15 console.log('Logged in!');
16
17 let db = new sqlite.Database('./SRoHNotices.sqlite', sqlite.OPEN_READWRITE || sqlite.OPEN_CREATE);
18 //db.run('CREATE TABLE IF NOT EXISTS Notices(noticeId INTEGER NOT NULL UNIQUE, type TEXT NOT NULL, typeName TEXT NOT NULL, gameIndex INTEGER NOT NULL, gameName TEXT NOT NULL, imageIcon TEXT NOT NULL, noticeTitle TEXT NOT NULL)')
19 db.run(
20 'CREATE TABLE IF NOT EXISTS SRoHNotices(noticeId INTEGER NOT NULL UNIQUE, type TEXT NOT NULL, typeName TEXT NOT NULL, gameIndex INTEGER NOT NULL, gameName TEXT NOT NULL, imageIcon TEXT NOT NULL, noticeTitle TEXT NOT NULL)'
21 );
22
23 for (const myApi of myApis) {
24 await axios.post(myApi).then((res) => {
25 //console.log(res.data.data.notice_list);
26 for (let i = 0; i < res.data.data.notice_list.length; i++) {
27 const Notices = res.data.data.notice_list[i];
28 const { noticeId, type, typeName, gameIndex, gameName, imageIcon, noticeTitle } = Notices;
29
30 if (gameName === 'Skylanders™ Ring of Heroes' || gameIndex === 585 || gameName === 'HIVE') {
31 db.all("SELECT * FROM 'SRoHNotices' WHERE noticeId = ?", [noticeId], (err, rows) => {
32 if (!rows || rows.length === 0) {
33 console.log('It will get posted');
34
35 console.log('SRoH Notices', Notices, 'SRoH DB Rows', rows);
36
37 channel = bot.channels.cache.get('711333232297115720');
38
39 const exampleEmbed = {
40 color: 0x0099ff,
41 title: noticeTitle,
42 url: 'https://www.withhive.com/notice/' + encodeURIComponent(noticeId),
43 description: '**' + noticeTitle + '**',
44 fields: [
45 {
46 name: 'Desktop Link',
47 value: '[Link](https://www.withhive.com/notice/' + noticeId + ')',
48 inline: true,
49 },
50 {
51 name: 'Mobile Link',
52 value: '[Link](https://m.withhive.com/notice/' + noticeId + ')',
53 inline: true,
54 },
55 ],
56 image: {
57 url: imageIcon,
58 },
59 };
60 channel.send('**' + noticeTitle + '**' + ' @everyone');
61 channel.send({ embed: exampleEmbed });
62
63 let insertdata = db.prepare('INSERT OR IGNORE INTO SRoHNotices VALUES(?,?,?,?,?,?,?)');
64 insertdata.run(noticeId, type, typeName, gameIndex, gameName, imageIcon, noticeTitle);
65 insertdata.finalize();
66 }
67 });
68 }
69 }
70 console.log(myApi);
71 });
72 }
73});
74
75bot.login(botconfig.token);