Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Commit

Permalink
getter msg.user
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Feb 10, 2019
1 parent fe24969 commit d66926e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ const bot = new Bot({
token: process.argv[2]
})

bot.msg.hear(/hello/i, msg => {
msg.send('simple message')
bot.msg.hear(/Hello/i, async msg => {
msg.send('Simple message')

msg.reply('answer')
msg.reply('Answer')

const user = await msg.user
msg.send(`Hello, ${user.first_name} ${user.last_name}!`)
})

bot.msg.poll()
7 changes: 7 additions & 0 deletions src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Message {
this.match = this.text.match(this.regexp)
}

get user () {
return this.bot.api.call('users.get', {
user_ids: this.attachments.from ? this.attachments.from : this.peerId
})
.then(value => value.response.shift())
}

async send (text, options = {}) {
options.peer_id = this.peerId
options.message = text
Expand Down

0 comments on commit d66926e

Please sign in to comment.