הירשם כדי לפרסם מודעה

אני מחפש דרך ליישם קטגוריה כדגם שוק פשוט שבו משתמשים יכולים לרכוש פרסום (קריאת פוסט).

נראה שהתוסף הרשמות מאפשר תוספת בתשלום לקבוצה, וכאשר המנוי מבוטל, באופן ידני או תכנותי, הוא מסיר את המשתמש.

מה שאני מנסה להשיג הוא מנוי שיאפשר פרסום בפוסט בקטגוריה ואז יוסר המשתמש מקבוצה שהותרה לפרסם.

האם זה אפשרי או רק עם תוסף ההרשמות או אולי בשילוב בין הרשמות לאוטומציה?

בפשטות, אני רוצה למכור הודעות בודדות. תגובות לפוסטים יהיו חינמיות.

I believe this set of permissions would allow what I’m asking given that ‘marketplace’ is the subscription group.

אני חושב שתצטרך תוסף שיסיר אותם מהקבוצה כשיצרת נושא בקטגוריית הפרסום.

אני לא בטוח שהתוסף האוטומציה יסיר משתמשים מקבוצות.

לייק 1

ובכן, אני לא יכול לתכנת בעצמי, ומכיוון שזה יהיה הוכחת רעיון לפני שאוכל לשכנע את המנהל שלי לתמוך בזה, אין לי דרך להציע תמיכה כספית כרגע.
האם מישהו אחר חושב שמשהו כזה יהיה טוב לקהילה?

שיקול נוסף, האם קיימת תקשורת בין Discourse ותוסף המנויים שיכול לעקוב אחר מספר המנויים שיש למשתמש? זה יהיה מועיל לאפשר למישהו לקנות מספר פוסטים בבת אחת במקום לקנות אחד, ואז לפרסם, ואז לקנות עוד אחד ולפרסם שוב.

[ציטוט=“tknospdr, פוסט:6, נושא:366751”]
זה יהיה הוכחה של קונספט לפני שאוכל לגרום למנהל שלי לתמוך בזה אני לא יכול להציע תמיכה כספית בזמן זה.
[/ציטוט]

היית simplement צריך להגיד לו להשתמש בדמיון שלו כהוכחת קונספט.

כנראה שתוכל לעשות את זה באמצעות webhooks ואחד מאותם כלים כמו Zapier.

[ציטוט=“tknospdr, פוסט:6, נושא:366751”]
היה לעזור לאפשר למישהו לקנות כמה פוסטים בבת אחת במקום לקנות אחד, ואז לפרסם, אחר כך לקנות עוד ועוד.
[/ציטוט]

זה היה עושה את הפלאגין ליותר מסובך.

For sure, but would be cool to have.
Anyway, it looks like this would do the job as long as you hard code the category ID and group name.
Can any real coders expand on this so that you can set those variables from the plunin’s settings page?

# name: discourse-auto-remove-group
# version: 0.1
# authors: tknospdr
# url: https://github.com/tknospdr/discourse-auto-remove-group

enabled_site_setting :auto_remove_group_enabled

# Site setting to enable/disable the plugin
register_site_setting :auto_remove_group_enabled, type: :boolean, default: false
register_site_setting :auto_remove_group_category_id, type: :integer, default: 0
register_site_setting :auto_remove_group_name, type: :string, default: ""

after_initialize do
  # Listen for post creation events
  DiscourseEvent.on(:post_created) do |post|
    next unless SiteSetting.auto_remove_group_enabled
    next unless post&.user # Ensure post has a user
    next unless post&.topic&.category_id # Ensure post is in a category

    target_category_id = SiteSetting.auto_remove_group_category_id
    group_name = SiteSetting.auto_remove_group_name

    # Check if the post is in the configured category
    if post.topic.category_id == target_category_id
      begin
        group = Group.find_by(name: group_name)
        unless group
          Rails.logger.error("AutoRemoveGroup: Group '#{group_name}' not found")
          next
        end

        user = post.user
        if group.users.include?(user)
          group.remove(user)
          Rails.logger.info("AutoRemoveGroup: Removed user #{user.username} from group #{group_name} after posting in category #{target_category_id}")
        else
          Rails.logger.info("AutoRemoveGroup: User #{user.username} is not in group #{group_name}, no action taken")
        end
      rescue StandardError => e
        Rails.logger.error("AutoRemoveGroup: Error removing user from group: #{e.message}")
      end
    end
  end
end

That could work!

Start with the Discourse-plugin-skeleton, make that your plugin.rb and maybe see what Ask.discourse.com can do to help.

And use add_model_callback instead of Discourse.event. You can look in the all_the_plugins repo for some examples.

לייק 1

Both grok and ask.discourse.com say to install the plugin @ /var/discouse/plugins/.

Problem is that I don’t have that path, either inside or out of the container. The closest I can find is inside the container I have /var/www/discourse/plugins/.

When I try to install it there and rebuild, it disappears.

Okay, so the bot says that’s normal for a self hosted install. I don’t know how to set up a proper git repository in order to get the plugin installed the normal way. Can someone help me out with that?

Think I got git going, installed the plugin and got some errors. This is honestly where I’m lost.

/var/www/discourse/plugins/discourse-auto-remove-group/plugin.rb:9:in `activate!': undefined method `register_site_setting' for an instance of Plugin::Instance (NoMethodError)
You are unable to start Discourse due to errors in the plugin at
/var/www/discourse/plugins/discourse-auto-remove-group

Please try removing this plugin and rebuilding again!
I, [2025-05-20T16:17:10.306025 #1]  INFO -- : 
I, [2025-05-20T16:17:10.347496 #1]  INFO -- : Terminating async processes
I, [2025-05-20T16:17:10.350251 #1]  INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main pid: 42
I, [2025-05-20T16:17:10.351238 #1]  INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 109
2025-05-20 16:17:10.351 UTC [42] LOG:  received fast shutdown request
109:signal-handler (1747757830) Received SIGTERM scheduling shutdown...
109:M 20 May 2025 16:17:10.368 # User requested shutdown...
109:M 20 May 2025 16:17:10.369 * Saving the final RDB snapshot before exiting.
2025-05-20 16:17:10.412 UTC [42] LOG:  aborting any active transactions
2025-05-20 16:17:10.438 UTC [42] LOG:  background worker "logical replication launcher" (PID 56) exited with exit code 1
2025-05-20 16:17:10.438 UTC [51] LOG:  shutting down
2025-05-20 16:17:10.447 UTC [51] LOG:  checkpoint starting: shutdown immediate
2025-05-20 16:17:10.526 UTC [51] LOG:  checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.088 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=4 kB
2025-05-20 16:17:10.540 UTC [42] LOG:  database system is shut down
109:M 20 May 2025 16:17:10.947 * DB saved on disk
109:M 20 May 2025 16:17:10.947 # Redis is now ready to exit, bye bye...


FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 987 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "tag"=>"migrate", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
9fed9596b10ffb4628947e678585b813813ae27a4de746feba16e89f2b9cdc51

Holy crap! After several more conversations with Ask Discourse and Grok. The plugin is now working.

I guess AI really IS useful sometimes.

It’s ugly, but confirmed to be working.


לייק 1

האם יש לך سلسلة הפעלה מוגדרת?

אני אפילו לא יודע מה זה אומר. :חייכן:

אתה צריך למקם את כתובת שירות ה-Github בקובץ app.yml שלך, אם אתה מריץ התקנה של סביבה פרודקשן.

שיטת השכפול שביצעת עובדת יותר להתקנות לפיתוח, אבל אני לא חושב שזה מה שאתה מריץ (מאחר ואתה משתמש ב-Launcher).

אה, כן, זה מה שעשיתי.
הוספתי שורת git clone בקובץ app.yml ועשיתי בנייה מחדש כדי להתחיל את הדברים.

2 לייקים

שמחים שהצלחת לגרום לזה לעבוד!

If you are going to develop a plugin then it’s 1000 times faster to set up a Install Discourse for development using Docker or Install Discourse on Windows for development or Linux or Mac.

It means you can edit a file and hit reload on your browser to see if it worked. Sometimes you don’t even have to reload.

לייק 1