Androz2091 / insta.js

💬 Object-oriented library for sending and receiving messages via Instagram
138 stars 42 forks source link

Suggestion: Add Collectors #5

Closed SimonLeclere closed 4 years ago

SimonLeclere commented 4 years ago

A createMessageCollector function and a createLikeCollector function (for messages).

Androz2091 commented 4 years ago

This is now possible using v1.3.0 ✅

if (message.content === '!apply') {
        message.reply('Hey, @' + message.author.username + ', welcome to the application form! Please enter your name: ')
        const infos = {
            name: null,
            age: null
        }

        const collector = message.createMessageCollector({
            filter: (m) => m.authorID === message.authorID,
            idle: 10000
        })

        collector.on('message', (m) => {
            if (!infos.name) {
                infos.name = m.content
                m.reply('Name saved! Now enter your age: ')
            } else if (infos.name && !infos.age) {
                infos.age = m.content
                m.reply('Age saved! We will contact you if we are interested!')
                collector.end()
            }
        })

        collector.on('end', (reason) => {
            if (reason === 'idle') {
                message.reply('It\'s been 10 seconds since you are AFK, Send !apply again to start the form again !')
            }
        })
    }