话语游戏化

是否可以手动重置排行榜网址?

例如,将 leaderboards/2 重置为 leaderboards/1

是否可以将积分作为额外奖励分配给用户? :grin:

1 个赞

您可能想看:

其中包含此 curl 请求:

curl --location 'https://my.discourse.com/admin/plugins/gamification/score_events' \
--header 'Api-Key: <您的密钥>' \
--header 'Api-Username: <您的用户名>' \
--header 'Content-Type: application/json' \
--data '{
    "user_id": "101",
    "date": "2024-05-15",
    "points": "-141",
    "description": "Gamification point adjustment"
}'
2 个赞

我在admin打开了这个插件,但是标签栏并没有自动出现Leaderboard,我添加了新的榜单也没出现。这是为什么?我应该去哪里看这些榜单?

我认为您必须自己将它们添加到侧边栏 :thinking:。排行榜位于 /leaderboard/leaderboard/2/leaderboard/3 等。

是否可以为特定类别或标签创建排行榜?

排行榜与群组相关联。但是,您可以在游戏化设置中指定哪些类别会影响所有排行榜。将此移至排行榜似乎是个有趣的主意,例如在此社区中设置一个#support 排行榜。

3 个赞

2 篇帖子已拆分为新主题:为被标记的用户减少积分

我有什么办法将自己从排行榜中排除吗?

是的,将您自己添加到一个新组(称之为“leaderboard-exclusion”或类似名称),然后在插件设置中排除该组。

编辑:这样以后您也可以轻松地将任何其他人添加到同一组中以将其排除在外。:slight_smile:

3 个赞

非常感谢。这很有道理。

2 个赞

我升级到2026.1.0版本后,新建了一个月度排行榜,然后访问下面的路由出现了报错:

http://localhost:4200/admin/plugins/discourse-gamification/leaderboards

报错如下:

assert.js:40 
 Uncaught (in promise) Error: Assertion Failed: You attempted to update `_value` on `TrackedStorageImpl`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`_value` was first used:

- While rendering:
  {{outlet}} for -top-level
    -top-level
      {{outlet}} for application
        application
          DiscourseRoot
            {{outlet}} for admin
              admin
                {{outlet}} for adminPlugins
                  admin-plugins
                    {{outlet}} for adminPlugins.show
                      show
                        AdminPluginConfigPage
                          AdminPluginConfigArea
                            {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards
                              adminPlugins.show.discourse-gamification-leaderboards
                                {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards.index
                                  discourse-gamification-leaderboards
                                    DPageSubheader
                                      (result of a `unknown` helper)

Stack trace for the update:
    at TrackedArray._dirtyCollection2 (array.ts:163:13)
    at Object.set (array.ts:126:15)
    at Proxy.sort (<anonymous>)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.sortedLeaderboards (index.js:23:1)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.<anonymous> (handle-descriptor.js:67:17)

然后我定位到出问题的文件如下:

plugins/discourse-gamification/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-gamification-leaderboards/index.js

具体代码:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || [] // 22行
    );
  }

错误的原因是:

Ember.js(准确说是 Glimmer 跟踪系统)的响应式状态管理断言错误,核心原因是:在同一个计算周期内,你先读取了一个tracked(跟踪状态)的值,随后又试图修改这个值,这种 “先使用后更新” 的操作会导致逻辑混乱、无限循环或性能问题,因此 Ember 直接禁止了该行为。

关键问题:

  • Array.sort() 原地修改原数组,会更新@trackedleaderboards状态

  • 计算属性(sortedLeaderboards)的职责是派生新值,而非修改原始状态,它本身应该是 “纯函数”(无副作用、不修改输入源)

下面是修复的方案:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      //leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
      leaderboards?.slice().sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
    );
  }

修复后截图:

然后这种类似的问题好像不是个例。我猜想是emberjs升级后导致的不兼容问题。而,很多插件中的这些地方并没有随着升级而同步修改,毕竟这项工作并没有说起来这么简单。