طقم بناء بوت Discord 🤖

غرض هذا الإضافة

تقوم هذه الإضافة بعدة مهام:

  1. تتيح لك تشغيل روبوت Discord باستخدام خادم Discourse الخاص بك للقيام بأشياء تربط النظامين معًا. انسخ هذا المستودع وقم بتوسيعه باستخدام Ruby بسيط لإنشاء جميع أنواع وظائف الروبوت.

  2. الوظائف الموجودة لتقديم أمثلة وأدوات مفيدة:

  • توفر نشرًا تلقائيًا ثنائي الاتجاه للمحتوى الذي يستوفي بعض المعايير.
  • أمر لنسخ الرسائل بشكل فردي إلى Discourse.
  • أمر لمزامنة عضوية المجموعات مع عضوية الأدوار في خادم Discord الخاص بك مع مثيل Discourse الخاص بك.

توفر الإضافة هيكلًا قابلًا للتوسع يمكنك من خلاله بناء ميزات إضافية. نرحب بطلبات الدمج (PRs) للإضافات المفيدة بشكل عام.


هذه ليست أوامر المزامنة الفعلية، بل مجرد توضيح لتفاعل الروبوت الممكن. الأمر الثاني في لقطة الشاشة تم إلغاؤه أثناء التطوير :wink:

من الضروري أن تكون معقدًا في الإعداد، لكنه رائع لعشاق كلا النظامين الذين يرغبون في بذل الوقت لفهم كيفية عمل كل نظام، على الأقل على المستوى الوظيفي والمفاهيمي. تحتاج إلى فهم بعض أساسيات كيفية عمل إدارة المستخدمين في Discourse و Discord للحصول على أفضل استفادة من هذه الإضافة.

أوامر الروبوت

هناك أربعة أوامر:

  1. Ping!
  2. !disckick
  3. !discsync
  4. !disccopy

Ping!

للتحقق مما إذا كان الروبوت يستجيب، اكتب ببساطة “Ping!” ويجب أن يستجيب الروبوت بـ “:robot: : Pong!” - مذهل، أليس كذلك؟ :smiley: (هذا في الواقع نوع من الميمز btw!)

!disckick <min_trust_level: الافتراضي 2>

سيؤدي كتابة هذا الأمر إلى طرد أي مستخدم موجود في Discourse الخاص بك ولكن بمستوى ثقة أقل من القيمة التي قدمتها. الافتراضي إذا لم تقم بتوفير قيمة هو 2.

مثال:

!discsync <clean up: الافتراضي false, min_visibility: الافتراضي 0, include automated groups: الافتراضي false>

سيحاول هذا الأمر نسخ جميع المجموعات إلى أدوار في Discord والتي تطابق المعايير المقدمة (أو الافتراضيات إذا لم يتم توفيرها). ثم سيحاول ملء الأدوار وفقًا لعضوية المجموعة في Discourse. إنها مزامنة في اتجاه واحد فقط. لا يتم تغيير أي بيانات في Discourse أبدًا.

!disccopy <number_of_messages> <optional_target_category_name> <optional_target_topic_name>

يتيح لك نسخ سجل محادثات Discord إلى مثيل Discourse الخاص بك من داخل دردشة Discord. يمكن التعامل مع آلاف الرسائل دفعة واحدة (ولكنه سيستغرق وقتًا لهذا الحجم).

اتصال ثنائي الاتجاه

إليك الإعدادات

  • يمكنك تعيين قناة إعلانات في Discord في إعدادات الإضافة.
  • يمكنك الآن الكتابة في قناة إعلانات Discord المحددة وسيتم نشر رسالتك في موضوع Discourse المحدد في إعدادات الإضافة.
  • يمكنك إعداد قائمة بالفئات في Discourse للنشر في قناة الإعلانات في Discord إذا قام شخص ما بالنشر هناك أو إضافة موضوع جديد (أي منهما أو كلاهما).
  • نسخ دردشة تلقائي لكل رسالة، من قناة إلى أي فئة تحمل نفس الاسم في Discourse: إذا كان اسم القناة يطابق اسم الفئة، فسيتم نسخ الرسالة إلى Discourse.

image

بالإضافة إلى ذلك، قمت بإضافة ملف جديد لإدارة أحداث Discord المدعومة من API discordrb، مع كون منطق الإعلانات هو المثال الأول (لا تتردد في تطوير أمثلة جديدة وتقديم طلب دمج إذا كانت مفيدة بشكل عام للمجتمع).

ملاحظة: بالنسبة لأي رسالة يتم نسخها إلى Discourse من Discord، سيظهر المستخدم بشكل صحيح إذا قام هذا المستخدم بتسجيل الدخول إلى Discourse باستخدام تسجيل دخول Discord (لذلك يمكن لـ Discord Bot مطابقة المستخدمين).

حالة هذه الإضافة

هذه إضافة معقدة في الإعداد. كان ذلك لا مفر منه إلى حد كبير.

ومع ذلك، فإن استخدامها سهل جدًا بمجرد تشغيلها بالكامل.

اعتبر الكود حاليًا في النسخة التجريبية (Beta). تم اختباره، حتى في بيئة الإنتاج، ولكن من المرجح أن يحتوي على أخطاء. أوصي باختباره أولاً على خادم Discord جديد قبل تطبيقه على خادم Discord الرئيسي “الإنتاجي” الخاص بك، ما لم تكن تبدأ للتو.

من المرجح أن أي أخطاء ستزعج مثيل Discord الخاص بك أكثر من مثيل Discourse الخاص بك، لأنه لا يتم إجراء أي تغييرات على Discourse. ومع ذلك، لقد كتبته بطريقة تعني أن معظم الأشياء قابلة للاسترداد ويمكنك ببساطة تكرار شيء ما لإصلاح مشكلة عادةً. يتم استخدام Discourse كمصدر أساسي لمعلومات العضوية والمجموعات، وتُستخدم هذه البيانات لتحديث العضوية والأدوار في خادم Discord الخاص بك.

تعليمات الإعداد

المتطلبات الأساسية

  1. خادم Discord أنت مدير فيه.
  2. تطبيق Discord (انظر أدناه).
  3. روبوت Discord (انظر أدناه).
  4. وصول ssh كمستخدم root إلى خادم Discourse الخاص بك.
  5. تحديثات لملف app.yml لتثبيت الإضافة.
  6. سيحتاج جميع مستخدمي Discourse الخاص بك إلى تسجيل الدخول باستخدام تسجيل دخول Discord OAuth الذي سيظهر على صفحة تسجيل الدخول الخاصة بك بمجرد تثبيت الإضافة.

تطبيق Discord

اذهب إلى هنا وأنشئ تطبيقًا:

اضغط على “New Application”.

ستحتاج إلى إنشاء روبوت وسيبدو شيئًا مثل هذا (اتركه غير ‘عام’):

ستحتاج إلى تفويض الروبوت في المتصفح، راجع OAuth2 - Documentation - Discord

بمجرد إعداد الروبوت، انسخ الرمز (Token). ستحتاج إلى إدخال ذلك في Discourse لاحقًا.

تغييرات app.yml

الإضافة

تحتاج فقط إلى إضافة واحدة الآن لأن تسجيل الدخول الاجتماعي لـ Discord أصبح جزءًا أساسيًا من نواة Discourse (واو :tada: )

ثم في المطالبة ./launcher rebuild app كما هو معتاد.

يجب أن يعمل هذا، لا مشكلة.

قد تحصل على بعض أخطاء وحدة التحكم والسجل تشير إلى فشل الروبوت في البناء الأول حيث لم تقم بعد بإدخال بيانات اعتماد الروبوت في واجهة إعدادات Discourse الأمامية. (التعامل مع هذا بشكل أكثر سلاسة هو أمر معلق، سأحذف هذا الجزء عندما يتم ذلك). لن يسبب ذلك أي ضرر وسيعمل Discourse نفسه بشكل طبيعي.

بمجرد الدخول إلى منطقة المسؤول في Discourse، انتقل إلى إعدادات الإضافة واملأ هذه الحقول:

ستحصل على المعرفات (IDs) من واجهة Discord. ستحتاج إلى تفعيل وضع المطور للسماح لك بنسخ هذه المعرفات. في Discord، انتقل إلى الإعدادات - > المظهر - > متقدم (ADVANCED) وقم بتفعيل وضع المطور:

يمكنك بعد ذلك الحصول على المعرفات من الواجهة، على سبيل المثال:

ستحتاج أيضًا إلى ملء إعدادات OAuth الخاصة بـ Discord. معرف العميل (Client ID) والسر (Secret) يأتيان من تطبيق Discord نفسه.

بمجرد تعيين هذه الإعدادات، عد إلى المطالبة الجذرية (root prompt) في linux واكتب:

./launcher restart app

إذا قمت بإعداد خوادم Discord و Discourse الخاصة بك بشكل صحيح، يجب أن ترى الروبوت ينضم إلى الخادم.

إذا سقط الروبوت في أي وقت (سيصبح غير متصل)، ستحتاج إلى فعل الشيء نفسه مرة أخرى لإعادته. الاستقلالية المحسنة للروبوت عن خادم نواة Discourse هي أمر معلق. مع ذلك، لقد شغلت روبوتًا في بيئة الإنتاج لفترة طويلة ولم يسقط حتى الآن.

أوامر مستقبلية؟

إذا كان لديك فكرة عن أمر آخر يستغل الرابط بين Discourse و Discord وتعتقد أنه سيكون مفيدًا للمجتمع الأوسع، فأخبرني في الردود ويمكننا النظر في إمكانية تنفيذ ذلك. ملاحظة: لا يُقصد بهذا الروبوت أداء مهام خارج نطاق Discourse.

القيود

كان الهدف الرئيسي من هذه الإضافة هو السماح للمستخدم بإنشاء روبوت على خادم Discord الخاص به يتم تشغيله بواسطة خادم Discourse الخاص به ويكون قادرًا على أداء بعض وظائف إدارة العضوية الأساسية. كما يوفر أساسًا لأي تفاعلات إضافية شبيهة بالروبوت بين النظامين في المستقبل. جزء من الدافع لاستخدام الروبوتات هو أنها ممتعة ببساطة fun.

أوامر الروبوت هي بشكل فردي بطبيعتها.

مشاكل معروفة

  • سيبدأ الروبوت مثيلًا من نفسه إذا ذهبت إلى جلسة وحدة تحكم rails على الخادم. سيسبب ذلك في ظهور الروبوت وكأنه يستجيب مرتين (ولكن في الواقع يوجد روبوتان الآن). في وحدة تحكم rails، ببساطة أوقف الروبوت الإضافي عن طريق كتابة: ::DiscordBot::Bot.discord_bot.stop لم يعد هذا ضروريًا الآن!

  • الروبوت ثرثار قليلاً خلال ترقيات Discourse ‘المتصل’ حيث يستمر في إعادة التفعيل أثناء عملية الترقية. هذا يعود إلى إيجاد طريقة جيدة لتشغيل الروبوت في عملية منفصلة ومدارة بدلاً من خيط فرع من خادم الويب. أعتقد أن هذا كله غير ضار، وإذا كان إخراج الروبوت فقط إلى قناة المسؤول الخاصة بك في Discord، فهل تهتم حقًا؟ يجب أن يكون هذا قد تم حله الآن تقريبًا، مع إعلان الروبوت عن نفسه مرتين فقط أثناء إعادة البناء.

شكرًا

هناك العديد من الداعمين الذين يجب شكرهم على هذه الإضافة التي استغرقت وقتًا طويلاً للوصول إلى هذه المرحلة بما في ذلك @Wedgebert، @FoohonPie. شكرًا لـ Jeff على مساهمته السخية. شكرًا لـ @angus على كل التشجيع والتعامل مع الدعم المالي.

تمت استلهام الإضافة من العمل الذي قام به @Watercolor_Games في مرحلة سابقة وتعتمد على إضافة OAuth الخاصة بـ Discord التي بناها @featheredtoast.

تعتمد الإضافة على مكتبة Ruby discordrb شبه الرسمية المدعومة من Discord والعمل الرائع الذي قام به فريق Discord لجعل نظامهم في متناول الجميع. شكرًا لـ @Falco على مساعدتي في اعتماد في استجابة سريعة للغاية.

بالإضافة إلى ذلك، بالطبع، لن يكون هذا ممكنًا بدون نظام الإضافات المذهل في Discourse (واو!)

حالة هذه التعليمات

سيتم تحسينها مع مرور الوقت وأرحب بالتعليقات. هناك مناطق من المرجح أن تكون غير واضحة.

47 إعجابًا
Discord<-> Discourse Selective Group Sync
Discord login and obtain discord roles in discourse
Discord and Discourse - Better Together | Blog
Convert Existing Plugin to do Discord to Discourse role/group sync
Slack Bot Construction Kit :robot:
2019: The Year in Review
Creat a user automatically when granted a Discord Role?
Discord Sync: sync a Discourse forum with a Discord server
Creating bot on discourse
Using "custom" ruby gems
Discourse Trust Levels for Discord
Discord is taking aim at Discourse. How does Discourse remain unique and stand out from the crowd?
Discord is taking aim at Discourse. How does Discourse remain unique and stand out from the crowd?
Copy + Pasting text from Discord into Discourse mangles paragraph breaks
Discord Role Badge Sync
Discord Bot: Topics not Posts
How do I go about making a very customized theme?
API feature request for additonal info about external accounts
Can anyone help me to add chat option of discord on forum?
How to Integrate/Sync Discord User MEE6 Points with Discourse Leaderboard?
LF Developer, Theme Creator, and Discord/Discourse Hero
Discord Sync: sync a Discourse forum with a Discord server
[PAID] Discourse/Discord integration needed (roles/user groups)
Can anyone help me to add chat option of discord on forum?
Discord and Discourse - Better Together | Blog
How to easily make Discourse bots?
Discourse to Discord bot possible?
Migrating from Discord to Discourse
Convert Existing Plugin to do Discord to Discourse role/group sync
Is migration from other chat apps supported?
Partially enable login option
Introducing Discourse Chat (BETA)
Which instant messenger do you use with Discourse?
Request widgetbot.io
Discord Sync: sync a Discourse forum with a Discord server

Hey I’m super interested in this.

Would the opposite be possible? I’d love a way to be able to create a Discourse setup for my Discord server. I’m not sure if there’s a Discord API event for roles being given but you could probably check when someone logs in with Discord or with CRON.

إعجابَين (2)

Yes, absolutely.

You could either build that as a bot command for ad hoc application, but with a repeat feature that reran the command after a period (nice but not very transparent and no way to individually manage these recurrences)

OR

As I alluded to above, have it scheduled as a job in Discourse as a sidekiq job. That might be a separate plugin (I actually started on the skeleton of that approach before moving to a bot only solution mainly because the ‘bot’ approach was kind of the Discord ‘thing’, fun and offered a unique approach and result), but if I can get Discourse to fire off bot commands then that’s moot (not yet had the chance to test that), and then we can write stuff once and have it work either way (nice!).

Both these solutions would rely on the same OAuth login though.

Whilst this is an excellent idea, it can’t be a priority for me at present because I have a lot of other client work at the moment I need to deliver, but if you wish to support such an extension, we can discuss offline on a PM and schedule it in.

4 إعجابات

It might be interesting to play around with, but I have nowhere near the skill level required to volunteer to develop/maintain an addon like this. I might make a messy fork at some time but I certainly don’t want my name on anything official. :slight_smile:

3 إعجابات

Absolutely get messy. It’s the only way to learn. :).

4 إعجابات

Minor bug fix deployed:

Got this during rebuild:

Bot is still offline. Triple checked everything and it’s all set up correctly. Not sure how to proceed now… Maybe I need to open a port on my server instance?

إعجابَين (2)

Thanks for testing this out and so soon after the update. Let me try to reproduce and I will revert. I did not change anything wrt to the port config.

إعجابَين (2)

No issues rebuilding here, Bot comes up fine … have you changed anything in your server config in between?

Your 400 Bad Request sounds like your server sent a corrupt or bad request to the Discord server and this was the response. This suggests it received it fine and was not blocked.

You can get this for:

  • malformed requests
  • lack of authorisation
  • exceeding rate limits

Unfortunately the error message doesn’t appear to help us determine which of these was the particular issue.

Presumably your Discourse is up? Check all the plugin settings are populated correctly.

Just to rule out a temporary gremlin run ./launcher restart app when you get chance … this will take your site down for a few seconds only (sorry about that!).

I see it runs the bot in the after_initialize block, so it will prevent migrations (and rebuilds) if the bot is misconfigured, or if Discord is down.

Maybe try to handle this exception and just log it?

5 إعجابات

It runs on a separate thread? So I expect that not to be an issue?

However this callback seems to run several times in a rebuild, so the main issue will be that a misconfigured bot could actually breach rate limits if authorisation fails too many times in quick succession. If that happens the account, in worse case, could be blocked for some time.

In any case, I’ll do a quick patch to do that with the current implementation to lessen the impact. Thanks for the suggestion.

UPDATE: @falco, this is done, e.g.:

image

3 إعجابات

First I want to say thank you for making this, once I can get it working its going to be a huge help for us managing our discourse and discord for a volunteer community.
I am running into a 400 error when trying to run this bot. Prior to this plugin being added we have been successfully using the official discord auth plugin and webhooks via the chat integration plugin. I’ve validated that those are both still working appropriately.

I created the bot within the same discord app I’d previously created authorized the bot within the discord server, it shows up in the member list as offline. Your documentation didn’t say what permission value to apply, but given most bots I’ve encountered for discord asked for it I went ahead and set it up with a permissions value of 8 for Administrator.

Within the discord server I then copied the ID of the Role it created, which was named after my app, and the id of the channel for admin text.I added the app Role to that channel with full rights, just to be sure, then added the IDs to discourse and restarted.

Unfortunately no matter what I try I’m getting a 400, I even tried a rebuild just to be sure.

3 إعجابات

Thank you, kind words. It was also enabled by the generosity of funders.

Yes, that’s great. It should have Admin.

This is the second report of this issue.

If you intentially remove the last char of the token in settings (remember what this is) do you get a 401 instead?

Let’s move this to PM because it might get messy :wink: (we can always post the solution here).

4 إعجابات

Just to post an update in case anyone else sees this, we’re actively looking into the issue but haven’t yet narrowed down the cause. I’d say if anyone else is running into this issue please say so would help to have others testing.

إعجاب واحد (1)

This is now fixed. It was a weird one to track down.

Thanks to @ransim for raising and working with me to get to the bottom of it.

Huge thanks to the #ruby_discordrb gang on Discord API for their patient and instant help!

@neemiasvf

5 إعجابات

@merefield no problem,Your plugin is great.But I have encountered some problems now.
such this:

Discourse Sync:  Starting.  Please be patient, I'm rate limited to respect Discord services.
Discourse Sync:  Checking if there are any eligible groups for sync ...
Discourse Sync: 1 eligible group(s) were found
Discourse Sync:  Preparing list of users who also have a registered account on Discord ...
Discourse Sync:  Preparing list of groups that users who have a registered account on Discord belong to on Discourse ...
Discourse Sync: 0 eligible group(s) were found with Discord users
Discourse Sync:  No users were found in elibigle groups for sync using provided or default criteria!

my commond is : !discsync 4

and commond changed: !discsync false 5 false

Discourse Sync:  Starting.  Please be patient, I'm rate limited to respect Discord services.
Discourse Sync:  Checking if there are any eligible groups for sync ...
Discourse Sync: 10 eligible group(s) were found
Discourse Sync:  Preparing list of users who also have a registered account on Discord ...
Discourse Sync:  Preparing list of groups that users who have a registered account on Discord belong to on Discourse ...
إعجاب واحد (1)

Hey @p0nda, sorry for slow reply.

If you include any parameters, you need to include all of them. It might be interpreting things strangely.

3 إعجابات

Unable to get the extended bot settings to show up? I have the changes to the app.yml and plugins installed. I have the OAuth setup working, but not the bot settings. Any ideas?

إعجاب واحد (1)

The OAuth setting are there but no bot settings

إعجاب واحد (1)

image
These

إعجابَين (2)