Discord Bot Construction Kit 🤖

Great. Btw I will gladly consider any useful generic improvements to this plugin in case you decide to get coding again :wink:

「いいね!」 2

Okay let’s start slow. I just submitted my first pull request to this repo :smile:.
https://github.com/merefield/discourse-discord-bot/pull/3

「いいね!」 4

merged :slight_smile: thanks!

「いいね!」 4

Hey! I’ve been trying to find a plugin that will give users in Discord a role based on the badges they have on their Discourse profile. Is this possible with your plugin? If not, is it even possible? Thanks!

「いいね!」 2

Not at present but no reason why you couldn’t fork it and add an appropriate command to implement that!

If implemented well I would consider merging a PR. However it might be a little specific for general use because presumably you’d have to maintain some kind of mapping unless the badge names were same as role names? In any case you’d have to filter out most of them? That might get messy for general use. If you find a really clean way to manage that which would work for general users of the plugin let me know.

But fork away, fill your boots!

「いいね!」 2

I would definitely like to see if it is possible. That would make me even more interested in this plugin. :smiley:

「いいね!」 1

Just a small question: do we have to manually run !discsync every time we want to update roles, or is it automatic?

「いいね!」 2

Unfortunately yes. It might be a nice enhancement to add a ‘repeat in x hours’ parameter (PR welcome or hire me to implement), but as I’ve mentioned before in this Topic, it would be better if someone produced a new plugin using their API and created some scheduled sidekiq jobs to do that. A bot is a fun solution but not the best architecture for scheduled syncing.

「いいね!」 2

Oh, thanks anyway. Yeah, we have already thought about a possible alternative…
We wanted to sync Discourse groups with Discord roles, but it looks like there is no perfect solution that suits.

We are now going to make some kind of bot using webhooks: Discourse will trigger a webhook when an user’s groups is updated (or username change as well) to a custom solution, which will then assign roles in Discord. We will keep using the Discord OAuth choice in order to get guilds, and by creating a custom Data Explorer query, we can get through the API those guilds.

It would be something like this:

  1. User changes groups or username
  2. Webhook to custom solution is triggered
  3. This custom solution will call back to Data Explorer API to a custom query that returns the guilds from the user
  4. With that guild, we call Discord back to update roles
「いいね!」 2

A proper batch job would be better so you don’t lose data integrity due to one-off event glitches. Both would be perfect.

「いいね!」 2

Well, I didn’t go through that way… :sweat_smile:
I’ve forked your repo, and made a new plugin that suited our needs:

It basically syncs all groups with Discord roles, but automatically. When a user is added or removed from a group, it will run a sync job and update their roles according to the public groups. In addition, I’ve added a setting to mark a “verified role”, that will be added to all users who have a Discourse account. And also it supports adding a list of safe roles, which the bot will ignore when syncing users (useful, for example, if wanting to set different admins and mods in the server than in the forum).
I’ve also added a username-nickname syncer. It can enforce users to have the same server nickname as the forum username.

I’ll open a plugin topic after cleaning up a couple of things, as maybe someone can find it useful.

「いいね!」 7

@barreeeiroo what was really interesting about your fork was your leveraging of DiscourseEvents hooks.

I had assumed that wasn’t possible because the bot is running in a separate thread. But as you’ve discovered, it seems we can act on events and influence the bot. So thanks for that, that’s a really important insight we can develop going forward.

So I’ve started adopting that technique in the main repo, starting with the ability to set some watches on new posts or Topics that willl be announced in the admin channel of Discord.

https://github.com/merefield/discourse-discord-bot/commit/9f8498c6a56baebb4d21009dff57932b35a46b86

The functionality may be of little use as it currently stands but it demostrates the concept for others to leverage.

「いいね!」 5

OK I’ve developed the plugin a little further now and have POC for two way communication working:

Here are the new settings

image

  • You can designate an Announcements Channel on Discord in the plugin settings.

  • You can now type into the assigned Discord Announcements Channel and this will post your message to your assigned Discourse Topic in the plugin settings

  • You can set up a list of Categories in Discourse to post to the Announcements channel on your Discord if someone Posts there or adds a new Topic (either or both).

https://github.com/merefield/discourse-discord-bot/commit/a19aa35f6aab2504aa220a1ab3856475f27c795a

In addition I’ve added a new file to manage Discord events supported by the discordrb API, with Announcements logic being the first example (feel free to develop new ones and PR if of general use to the community).

I’ve also removed the changes required to app.yml to install libsodium-dev as this is now optional having updated the dependencies and not required for the plugin at present (no need to handle voice). This will make installation much simpler.

「いいね!」 9

インストール手順に従い、再起動まで全て順調に進みました。ボットが部屋に参加しなかったので、/logsを確認しました。

これは discord_bot_token のことでしょうか?入力済みで、値も確認しました。何か手がかりはありますか?

「いいね!」 3

マーク、申し訳ありません、どういうわけか見落としていました。

問題は発見できましたか?

更新して新しいバージョンを試していただけますか。そこから進めましょう。

「いいね!」 2

Discourseチームが資金提供した重要なアップデートです :tada:

FEATURES: new message auto-copy and history copy command by merefield · Pull Request #4 ·
merefield/discourse-discord-bot (github.com)

  1. 新しいコマンド !disccopy <メッセージ数> <オプションのターゲットカテゴリ名> <オプションのターゲットトピック名> を使用すると、DiscordチャットからDiscordメッセージ履歴(そのチャンネルの)をDiscourseインスタンスにコピーできます。これは一度に数千件のメッセージを安全に処理できます(ただし、その量では時間がかかります)。
  2. チャネルごとにメッセージを自動コピーします。チャネル名がDiscourseのカテゴリ名と一致する場合、これが設定されていればメッセージをDiscourseにコピーします。
    image
  3. DiscordからDiscourseにコピーされたメッセージについて、ユーザーが正しく表示されるようになります。これは、ユーザーがDiscordログインを使用してDiscourseにログインした場合です(Discord Botがユーザーアカウントを照合できるようになります)。
  4. 多くの機能でローカライゼーションサポートが追加されました。

この作業の仕様策定とスポンサーをしてくださった @erlend_sh およびDiscourseチームに感謝します!! :pray:

さらに多くのボット機能が登場します :wink: :robot:

「いいね!」 5

Discord OAuth 以外の、Discourse 認証またはその他の認証でログインした場合、このプラグインは単にそれらを無視しますか?

「いいね!」 1

無視しているわけではなく、相手のシステムでユーザーと一致させることができないだけです。その結果、コピーされたメッセージは「システム」からのものとして表示されます。

「いいね!」 2

スレッドはサポートされていますか?

「いいね!」 4

まだですが、Klaus、それは潜在的に計画中です。Ruby APIが更新されるのを待っています(ブロッカー)、その後、バッカーがその機能を追加します。

「いいね!」 2