Open SKevo18 opened 4 years ago
Hi,
There should be an author property for each PM that you can access
Thanks for reply, but author.name
represents the author of the reply (user-A
), not the user I'm replying to (user-B
). I do not mean PMs, but username_mention
type of message (when you send a comment mentioning the bot).
Ah gotcha, there is a comment.parent_id
which points to the parent. You can use that to create a new Comment instance
Thank you, however I am using this code:
const Snoowrap = require("snoowrap");
const Snoostorm = require("snoostorm");
const { InboxStream } = require("snoostorm");
const r = new Snoowrap({
userAgent: "a-bot",
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
username: process.env.USERNAME,
password: process.env.PASSWORD
});
const inbox = new InboxStream(r);
inbox.on("item", async item => {
console.log("Scraped: " + r.getComment(item.parent_id).author.name)
});
The line before the last one is important. I tried to log the author.name
, however this returns just the following:
Here's an example of one Comment
(item
) from the inbox json (there are more, every returns just empty object):
Comment {
first_message: null,
first_message_name: null,
subreddit: Subreddit { display_name: 'some-subreddit' },
likes: true,
replies: Listing [],
id: '1234abc',
subject: 'kde ma spomenuli',
associated_awarding_id: null,
score: 1,
author: RedditUser { name: 'user-A' },
num_comments: 5,
parent_id: 't3_abc1234', <----- It's prefixed with t3, however if I try to remove the t3_ part, it still returns just an empty promise.
subreddit_name_prefixed: 'r/some-subreddit',
new: false,
type: 'username_mention',
body: 'u/bot',
link_title: 'ah',
dest: 'bot',
was_comment: true,
body_html: '<!-- SC_OFF --><div class="md"><p><a ' +
'href="/u/bot">u/bot</a></p>\n' +
'</div><!-- SC_ON -->',
name: 't1_1234abc',
created: 1598042633,
created_utc: 1598013833,
context: '/r/some-subreddit/comments/abc1234/ah/1234abc/?context=3',
distinguished: null
}
(the usernames & other private info is censored/replaced by placeholders).
Logging just console.log("Scraped: " + r.getComment(inbox.parent_id))
logs empty object Object
.
Sorry for late response. Did you solve the issue?
Otherwise, this seems to be a Promise issue, it didn't fetch the content. You can do something like
console.log("Scraped: " + (await r.getComment(item.parent_id)).author.name)
Hello everyone,
thanks for putting your time and effort to keep these projects alive.
I am having a trouble obtaining the username of the user I have replied to in the inbox
username_mention
message. I have a bot that watches theInboxStream
for mentions. Whenever a bot gets mentioned, it does stuff.Let's say we have
user-A
anduser-B
. The bot's name isbot
.user-A
mentionedbot
in reply touser-B
.bot
got an alert in its inbox that it was mentioned. However, how canbot
get the username ofuser-B
? I haven't found anything in the Inbox's json reply, so I guess that it's not possible due to this limitation, however I might've missed something.See https://github.com/MayorMonty/Snoostorm/issues/41 for reference.
Thank you.