diff --git a/bot.js b/bot.js index a9869f6bdd4e02cafd8cbbd9538728cf65b2021a..f274e28bce679a0ef50a6e40d1495e4a246319de 100644 --- a/bot.js +++ b/bot.js @@ -1,5 +1,6 @@ const EventEmitter = require('events'); const MastodonAPI = require('mastodon-api'); +const wurl = require('wurl'); class Bot extends EventEmitter { /** @@ -42,12 +43,8 @@ class Bot extends EventEmitter { this.me = (await this.verify_credentials()); } - /** - * Fav an existing toot - * @param {int} id - */ - fav(id) { - this.M.post('statuses/' + id + '/favourite'); + async verify_credentials() { + return (await this.M.get('accounts/verify_credentials')).data; } /** @@ -55,7 +52,26 @@ class Bot extends EventEmitter { * @returns {Array} */ async following_list() { - return (await this.M.get('accounts/' + this.me.id + '/following')).data; + let result = []; + let next_id = 0; + + for (let i = 0; true; i++) { + let test; + + if (next_id === 0) { + test = await this.M.get('accounts/' + this.me.id + '/following', {limit: 80}); + } else { + test = await this.M.get('accounts/' + this.me.id + '/following', {limit: 80, max_id:next_id}); + } + + next_id = parseInt(wurl('?max_id' ,test.resp.headers.link.split(",")[0].split(';')[0].slice(1, -1))); + + result = result.concat(test.data); + + if(test.data.length < 80) break; + } + + return result; } /** @@ -63,11 +79,26 @@ class Bot extends EventEmitter { * @returns {Array} */ async followers_list() { - return (await this.M.get('accounts/' + this.me.id + '/followers')).data; - } + let result = []; + let next_id = 0; - async verify_credentials() { - return (await this.M.get('accounts/verify_credentials')).data; + for (let i = 0; true; i++) { + let test; + + if (next_id === 0) { + test = await client.M.get('accounts/' + client.me.id + '/followers', {limit: 80}); + } else { + test = await client.M.get('accounts/' + client.me.id + '/followers', {limit: 80, max_id:next_id}); + } + + next_id = parseInt(wurl('?max_id' ,test.resp.headers.link.split(",")[0].split(';')[0].slice(1, -1))); + + result = result.concat(test.data); + + if(test.data.length < 80) break; + } + + return result; } /** @@ -96,6 +127,14 @@ class Bot extends EventEmitter { this.post(`@${data.account.acct} ${status}`, visibility, data.status.id); } + /** + * Fav an existing toot + * @param {int} id + */ + fav(id) { + this.M.post('statuses/' + id + '/favourite'); + } + /** * Follow a user * @param {int} id diff --git a/index.js b/index.js index be2602017a424f822650a4b0dc02ab4b113f4011..a7d57b2f594e5651665b74b98b71fd050b57c90f 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,8 @@ client.start().then(() => { for(const account of result) { following.add(account.acct) } + + console.log(`I'm currently following ${following.size} accounts.`) }); console.log("Federation Bot started ! 🎉") diff --git a/package.json b/package.json index 34e7f31acc62557aada5e7f560eeb3353a152991..8a88d4b7e59768b8cb8bebf5825b39134314b86e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "version": "0.0.1", "dependencies": { "mastodon-api": "^1.3.0", - "striptags": "^3.1.1" + "striptags": "^3.1.1", + "wurl": "^2.5.3" }, "repository": "https://git.cant.at/Tagada/FederationBot", "license": "AGPL-3.0",