(Ruby) Selecting only posts that are made by non-original posters

Hey everyone!

I have started volunteering for a community recently and I am tasked with updating an existing plugin. This plugin currently changes a topics tag when it reaches a certain word count threshold. I am supposed to convert this to only count words from posts in the topic that are not from the topic’s creator.

Currently, the word count is achieved by this snippet:

replies = topic.posts.where('post_number > 1')
reply_word_count = replies.sum(:word_count)

I’m thinking the strategy for this will be:

non_op_replies = topic.posts.where('post.user.username != topic.user.username')
reply_word_count = non_op_replies.sum(:word_count)

But this doesn’t seem to work. I have been fiddling around with the syntax for a while and can’t seem to get a working plugin out of it. I have been trying to find documentation for developing in Discourse with Ruby and I am coming up short. I would love if someone is able to help me out or point me in the right direction. I’m also new to Ruby so sorry in advance if it’s just a silly error.

Welcome aboard! :partying_face:

I’m also a beginner at Ruby, and I’ve found this tutorial really helpful to start off with.

Here’s a 7-part series on developing Discourse plugins, although it may not have exactly what you’re looking for, but it’s a good resource to help understand how a Discourse plugin is structured.

Personally, I learn best by example and logging each step of the way, so Rails.logger, along with Discourse’s logster, which you can access via localhost:3000/logs, are really helpful in doing that.

Here lies the Ruby documentation for Discourse core, if you are feeling brave and want to explore on your own.

Thank you for your help! I’ll take a look at these right away.