forked from paviliondev/discourse-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: added event listening stub area and example
- Loading branch information
Showing
7 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
en: | ||
site_settings: | ||
discord_bot_enabled: "Enable the Discourse Discord bot plugin" | ||
discord_bot_token: "Enter your bot TOKEN from Discord here" | ||
discord_bot_admin_channel_id: "The id of your admin text channel on Discord" | ||
discord_bot_admin_role_id: "The id of your admin role on Discord for which commands are permitted" | ||
discord_bot_rate_limit_delay: "The delay in seconds between sending commands to Discord so we don't annihilate rate limits" | ||
discord_bot_enabled: "Enable the Discourse Discord bot plugin" | ||
discord_bot_token: "Enter your bot TOKEN from Discord here" | ||
discord_bot_admin_channel_id: "The id of your admin text channel on Discord" | ||
discord_bot_admin_role_id: "The id of your admin role on Discord for which commands are permitted" | ||
discord_bot_rate_limit_delay: "The delay in seconds between sending commands to Discord so we don't annihilate rate limits" | ||
discord_bot_post_announcement_categories: "Announce new Posts in here within the admin channel" | ||
discord_bot_topic_announcement_categories: "Announce new Topics in here within the admin channel" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ::DiscordBot::DiscourseEventsHandlers | ||
def self.hook_events | ||
DiscourseEvent.on(:post_created) do |post| | ||
if post.id > 0 && !::DiscordBot::Bot.discord_bot.nil? then | ||
post_listening_categories = SiteSetting.discord_bot_post_announcement_categories.split('|') | ||
topic_listening_categories = SiteSetting.discord_bot_topic_announcement_categories.split('|') | ||
posted_category = post.topic.category.id | ||
posted_category_name = Category.find_by(id: posted_category).name | ||
if post_listening_categories.include?(posted_category.to_s) then | ||
message = "There's a new Post in the '#{posted_category_name}' Category on Discourse: #{Discourse.base_url + post.url}" | ||
::DiscordBot::Bot.discord_bot.send_message(SiteSetting.discord_bot_admin_channel_id, message) | ||
else | ||
if topic_listening_categories.include?(posted_category.to_s) && post.post_number = 1 then | ||
message = "There's a new Topic in the '#{posted_category_name}' Category on Discourse: #{Discourse.base_url + post.url}" | ||
::DiscordBot::Bot.discord_bot.send_message(SiteSetting.discord_bot_admin_channel_id, message) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module ::DiscordBot | ||
class Engine < ::Rails::Engine | ||
engine_name "discord_bot" | ||
isolate_namespace DiscordBot | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters