0.1.2 • Published 1 year ago

puppet-bot v0.1.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

puppet-bot

Build a bot using puppeteer extra. Support multiple tab, single tab and easy multi-process integration with queue. Built-in reddit bot and more Easyly customize your bot with API

Installation

Install globally as root:

# npm install -g puppet-bot

On Ubuntu or Mac OS X systems install using sudo:

$ sudo npm install -g puppet-bot

For access to the API just add package puppet-bot to your package.json devDependencies:

{
    ...
    "devDependencies": {
        "puppet-bot": "*"
    },
    ...
}

Compatibility

Should be used at least with Node.js v10 or later:

  • Node.js v10 or later

Usage

puppet-bot allows you to build your bot using puppeteer extra, or you can use build-in bot (eg: reddit bot)

Basic Usage

Using reddit bot or another (use help command to research):

$ reddit -h OR $ reddit auto -h

API

puppet-bot You can be controlled using an API

const { Page, Browser, Reddit } = require('puppet-bot');
const {StealthPlugin} = require('puppeteer-extra-plugin-stealth');
var queue = require('queue');

(async () => {
    var loginReddit = new Reddit();
    await loginReddit.init('https://www.reddit.com/login', [StealthPlugin()]);
    if (await loginReddit.validate()) {
        await loginReddit.open();
        await loginReddit.signIn('your-reddit-user', 'your-reddit-pass);

        var browser = loginReddit.browser;
        var searchReddit = new Reddit(browser);
        await searchReddit.init('https://www.reddit.com/search/?q=comics', [StealthPlugin()]);
        await searchReddit.open();
        await searchReddit.scroll();
        var links = await searchReddit.getPostUrls();
        var q = queue({ results: [], concurrency: 10, autostart: false });
        for (let i in links) {
            q.push(async function (cb) {
                let p = new Reddit(browser);
                await p.init(links[i], [StealthPlugin()]);
                await p.open();
                await p.comment("+1 vote");
                await p.vote();
                await p.close();
                cb(null, true);
            });
        }
        q.start(async function (err) {
            if (err) console.log(err);
            await searchReddit.close();
            await browser.close();
        })
    }
})();

Using to build a bot class

const { Page } = require('puppet-bot');

export class YourBot extends Page {

}

Options

Udating...

...

Complete Example

The file examples/index.mjs shows a complete example.

Licensed under The MIT License

Copyright (c) 2022 Hưng Lê hunglsxx@gmail.com and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.