diff --git a/package-lock.json b/package-lock.json index 18c34bfaf..a6edf010a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "dblapi.js": "^2.4.0", "dd-trace": "^0.31.4", "dotenv": "^10.0.0", - "eris-sharder": "github:ChristopherBThai/eris-sharder#65d94d5725868dab23552b5bdb60d526e4391a7f", + "eris-sharder": "github:ChristopherBThai/eris-sharder#82e175ccbfa023450f26ab015151f57bc5dec766", "erlpack": "github:abalabahaha/erlpack", "eventemitter3": "^4.0.4", "express": "^4.17.1", @@ -33,6 +33,7 @@ "npm": "^7.8.0", "parse-duration": "^0.4.4", "patreon": "^0.4.1", + "patreon-discord": "^0.0.5", "pluralize": "^8.0.0", "prettier": "^2.8.0", "random-number-csprng": "^1.0.2", @@ -1851,8 +1852,8 @@ }, "node_modules/eris": { "version": "0.17.2", - "resolved": "git+ssh://git@github.com/ChristopherBThai/eris.git#3f44c84ebb82a844dcbe4f5c34df1b2774424bec", - "integrity": "sha512-2vJWU9dvLzM+FBsFye1NQREqgzU3Js19YjOhfNhuW7kGf8vzTYHiTXhaGzbN9PL9cWbkh9ElWM67/7BpUmQDrA==", + "resolved": "git+ssh://git@github.com/ChristopherBThai/eris.git#8db31a2a0eb27fa48e4c0cf7ef3a4ad8e8d5a9fc", + "integrity": "sha512-BrvrFDpalQMTJ9a4lNKVXFKAyu7FINe017JJWmqawk5AuIQEG1Y2gpXBB1L6fXypYHAhe69PYGkx5Mn0dDpJ4A==", "license": "MIT", "dependencies": { "ws": "^8.2.3" @@ -1867,14 +1868,14 @@ }, "node_modules/eris-sharder": { "version": "1.10.0", - "resolved": "git+ssh://git@github.com/ChristopherBThai/eris-sharder.git#65d94d5725868dab23552b5bdb60d526e4391a7f", - "integrity": "sha512-sewl6yqrZyFeABtJ80aZFuuSiORe5AYP1TNIKOFu6HQMoYqkdzfHR7pLNGcVW865CTVcBxHhlqmNK7APnNMvtg==", + "resolved": "git+ssh://git@github.com/ChristopherBThai/eris-sharder.git#82e175ccbfa023450f26ab015151f57bc5dec766", + "integrity": "sha512-GvSJFH33PRcks0ONJIAYiiJmWVCGibUtJ5AMEO1lQzpko29Nr/PgmUk+oIIGrYtxmU09PxVExVpr8oTO1xSdEw==", "license": "MIT", "dependencies": { "asciiart-logo": "^0.2.6", "bucket-queue": "^1.0.1", "colors": "^1.1.2", - "eris": "github:ChristopherBThai/eris#3f44c84ebb82a844dcbe4f5c34df1b2774424bec", + "eris": "github:ChristopherBThai/eris#8db31a2a0eb27fa48e4c0cf7ef3a4ad8e8d5a9fc", "fancy-log": "^1.3.0" }, "engines": { @@ -1882,9 +1883,9 @@ } }, "node_modules/eris/node_modules/ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", "engines": { "node": ">=10.0.0" }, @@ -7180,6 +7181,17 @@ "node": ">6.2.1" } }, + "node_modules/patreon-discord": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/patreon-discord/-/patreon-discord-0.0.5.tgz", + "integrity": "sha512-AWq7/HLsbAFmMg38gcxs0SE/PNaB8LNz7vQEURC2CxpwZFBbVKwev4/gqL0WPoqycV/pRraIXS//7BgifdaTKw==", + "dependencies": { + "node-fetch": "^2.6.1" + }, + "engines": { + "node": "14.x" + } + }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -10217,9 +10229,9 @@ "integrity": "sha512-+nVFp+5z1E3HcToEnO7ZIj3g+3k9389DvWtvJZz0T6/eOCPIyyxehFcedoYrZQrp0LgQbD9pPXhpMBKMd5QURg==" }, "eris": { - "version": "git+ssh://git@github.com/ChristopherBThai/eris.git#3f44c84ebb82a844dcbe4f5c34df1b2774424bec", - "integrity": "sha512-2vJWU9dvLzM+FBsFye1NQREqgzU3Js19YjOhfNhuW7kGf8vzTYHiTXhaGzbN9PL9cWbkh9ElWM67/7BpUmQDrA==", - "from": "eris@github:ChristopherBThai/eris#3f44c84ebb82a844dcbe4f5c34df1b2774424bec", + "version": "git+ssh://git@github.com/ChristopherBThai/eris.git#8db31a2a0eb27fa48e4c0cf7ef3a4ad8e8d5a9fc", + "integrity": "sha512-BrvrFDpalQMTJ9a4lNKVXFKAyu7FINe017JJWmqawk5AuIQEG1Y2gpXBB1L6fXypYHAhe69PYGkx5Mn0dDpJ4A==", + "from": "eris@github:ChristopherBThai/eris#8db31a2a0eb27fa48e4c0cf7ef3a4ad8e8d5a9fc", "requires": { "opusscript": "^0.0.8", "tweetnacl": "^1.0.3", @@ -10227,22 +10239,22 @@ }, "dependencies": { "ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", "requires": {} } } }, "eris-sharder": { - "version": "git+ssh://git@github.com/ChristopherBThai/eris-sharder.git#65d94d5725868dab23552b5bdb60d526e4391a7f", - "integrity": "sha512-sewl6yqrZyFeABtJ80aZFuuSiORe5AYP1TNIKOFu6HQMoYqkdzfHR7pLNGcVW865CTVcBxHhlqmNK7APnNMvtg==", - "from": "eris-sharder@github:ChristopherBThai/eris-sharder#65d94d5725868dab23552b5bdb60d526e4391a7f", + "version": "git+ssh://git@github.com/ChristopherBThai/eris-sharder.git#82e175ccbfa023450f26ab015151f57bc5dec766", + "integrity": "sha512-GvSJFH33PRcks0ONJIAYiiJmWVCGibUtJ5AMEO1lQzpko29Nr/PgmUk+oIIGrYtxmU09PxVExVpr8oTO1xSdEw==", + "from": "eris-sharder@github:ChristopherBThai/eris-sharder#82e175ccbfa023450f26ab015151f57bc5dec766", "requires": { "asciiart-logo": "^0.2.6", "bucket-queue": "^1.0.1", "colors": "^1.1.2", - "eris": "github:ChristopherBThai/eris#3f44c84ebb82a844dcbe4f5c34df1b2774424bec", + "eris": "github:ChristopherBThai/eris#8db31a2a0eb27fa48e4c0cf7ef3a4ad8e8d5a9fc", "fancy-log": "^1.3.0" } }, @@ -13939,6 +13951,14 @@ "jsonapi-datastore": "^0.4.0-beta" } }, + "patreon-discord": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/patreon-discord/-/patreon-discord-0.0.5.tgz", + "integrity": "sha512-AWq7/HLsbAFmMg38gcxs0SE/PNaB8LNz7vQEURC2CxpwZFBbVKwev4/gqL0WPoqycV/pRraIXS//7BgifdaTKw==", + "requires": { + "node-fetch": "^2.6.1" + } + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", diff --git a/package.json b/package.json index fe904413d..f24d7d20b 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "npm": "^7.8.0", "parse-duration": "^0.4.4", "patreon": "^0.4.1", + "patreon-discord": "^0.0.5", "pluralize": "^8.0.0", "prettier": "^2.8.0", "random-number-csprng": "^1.0.2", diff --git a/src/botHandlers/patreonHandler.js b/src/botHandlers/patreonHandler.js index 83cafd165..93ed319a6 100644 --- a/src/botHandlers/patreonHandler.js +++ b/src/botHandlers/patreonHandler.js @@ -5,6 +5,10 @@ * For more information, see README.md and LICENSE */ const axios = require('axios'); +const { Campaign } = require('patreon-discord'); +const members = {}; +const cache = {}; +let campaign; exports.request = async function (cookie) { console.log('getting cowoncy...'); @@ -67,10 +71,19 @@ async function getUsers(cookie, url, list) { list.push({ name: item.attributes?.full_name, discord: discord?.user_id, + user_id: item.id, }); + } else if (item.type === 'member') { + members[item.relationships.user.data.id] = item.id; } }); + for (let i in list) { + if (!list[i].discord) { + list[i].discord = await getDiscordId(list[i].user_id); + } + } + console.log('list length: ' + list.length); if (data.links.next) { console.log('getting next page...'); return getUsers(cookie, data.links.next, list); @@ -82,6 +95,25 @@ async function getUsers(cookie, url, list) { } } +async function getDiscordId(userId) { + if (!campaign) { + campaign = new Campaign({ + patreonToken: process.env.PATREON_ACCESS_TOKEN, + campaignId: 1623609, + }); + } + const memberId = members[userId]; + + if (cache[memberId]) { + return cache[memberId]; + } + + const patron = await campaign.fetchPatron(memberId); + const discordId = patron.discord_user_id; + cache[memberId] = discordId; + return discordId; +} + /* var url = require('url'); var patreon = require('patreon'); diff --git a/src/commands/command.js b/src/commands/command.js index 3419f64fb..6fe83d237 100644 --- a/src/commands/command.js +++ b/src/commands/command.js @@ -296,6 +296,7 @@ function initParam(msg, command, args, main, context) { dateUtil: main.dateUtil, neo4j: main.neo4j, giveaway: main.giveaway, + patreonUtil: main.patreonUtil, }; param.setCooldown = function (cooldown) { main.cooldown.setCooldown(param, aliasToCommand[command], cooldown); diff --git a/src/commands/commandList/admin/getPatreonRewards.js b/src/commands/commandList/admin/getPatreonRewards.js index f792a2a5f..0705a4baa 100644 --- a/src/commands/commandList/admin/getPatreonRewards.js +++ b/src/commands/commandList/admin/getPatreonRewards.js @@ -41,7 +41,6 @@ async function getPatreons(p) { console.error(err); return; } - console.log(patreons); let result = []; if (p.args[0] != 'ignoresql') { let sql = diff --git a/src/commands/commandList/battle/util/teamUtil.js b/src/commands/commandList/battle/util/teamUtil.js index ad16bc88f..9c319f4c9 100644 --- a/src/commands/commandList/battle/util/teamUtil.js +++ b/src/commands/commandList/battle/util/teamUtil.js @@ -10,7 +10,6 @@ const animalUtil = require('./animalUtil.js'); const WeaponInterface = require('../WeaponInterface.js'); const global = require('../../../../utils/global.js'); const mysql = require('../../../../botHandlers/mysqlHandler.js'); -const patreonUtil = require('../../patreon/utils/patreonUtil.js'); const defaultMaxTeams = 2; let weaponUtil; @@ -589,7 +588,7 @@ exports.setWeaponUtil = function (util) { exports.getMaxTeams = async function (user, patreonRank) { let maxTeams = defaultMaxTeams; - let patreon = patreonRank || (await patreonUtil.getSupporterRank(this, user)); + let patreon = patreonRank || (await this.patreonUtil.getSupporterRank(this, user)); if (patreon?.benefitRank >= 3) { maxTeams++; } diff --git a/src/owo.js b/src/owo.js index 75ddffcde..2f160eb06 100644 --- a/src/owo.js +++ b/src/owo.js @@ -113,6 +113,8 @@ class OwO extends Base { this.patreon = require('./utils/patreon.js'); this.patreon.init(this); + this.patreonUtil = require('./commands/commandList/patreon/utils/patreonUtil.js'); + try { this.badwords = require('./../../tokens/badwords.json'); } catch (err) {