My team would like a plugin where the system user is a random person from our PR team, as users respond better to real people than robots (even if it’s made obvious that it’s an automated action/message!)
In response, I wrote this code in a plugin:
Discourse.module_eval do
def self.pr_member
Group.find_by(name: "PRTeam").users.sample
end
def self.system_user
self.pr_member
end
def self.site_contact_user
self.pr_member
end
end
This seems to work fine, but are there any side effects I should be aware of for this? Is there a better way?
You mean a random user from a group? It might be a better idea to update the site contact username from within a plugin. You could create a background job that assigns a random member of the group if you wish.
Most likely. The system user is used all over the place. Returning a different, random user every time Discourse.system_user is called might lead to random problems. Also, Discourse often assumes that the system user has -1 as ID (Discourse.SYSTEM_USER_ID isn’t always used) and non-human users (ID < 0) are often excluded in SQL queries, etc. None of that will work anymore, so’ll have to live with the consequences.
In short: Don’t do it or you might break Discourse in unforeseen ways.