diff --git a/plugin.rb b/plugin.rb index 004b614..2af7c53 100644 --- a/plugin.rb +++ b/plugin.rb @@ -6,6 +6,7 @@ require 'date' +# Hash to store course IDs and corresponding links courses = Hash.new courses = { 11 => "https://scratch.mit.edu/projects/00000000/", @@ -42,6 +43,7 @@ 76 => "h34_capstone_00" } +# Method to get the link based on course ID and username def get_link(id, username, hash) if id == 11 || id == 57 return "`https://scratch.mit.edu/projects/00000000`" @@ -55,6 +57,7 @@ def get_link(id, username, hash) return false end +# Method to create a post in a topic def create_post(topicId, text) post = PostCreator.create( Discourse.system_user, @@ -67,6 +70,7 @@ def create_post(topicId, text) end end +# Method to close a topic with a message def closeTopic(id, message) topic = Topic.find_by(id: id) topic.update_status("closed", true, Discourse.system_user, { message: message }) @@ -74,6 +78,7 @@ def closeTopic(id, message) send_pm_to_author(author_username, id, message) end +# Method to check if the title contains specific keywords def check_title(title) if title.downcase.include?("codewizardshq.com") || title.downcase.include?("scratch.mit.edu") return true @@ -82,18 +87,21 @@ def check_title(title) end end +# Method to check for different types of links in text def check_all_link_types(text) if (text.include?("codewizardshq.com") && !text.include?("/edit")) || (text.include?("cwhq-apps") || text.include?("scratch.mit.edu")) return true end end +# Method to log a command with a link and name def log_command(command, link, name) log_topic_id = 11303 text = "@#{name} #{command}:
#{link}" create_post(log_topic_id, text) end +# Method to send a private message to a user def send_pm(title, text, user) message = PostCreator.create!( Discourse.system_user, @@ -105,6 +113,7 @@ def send_pm(title, text, user) ) end +# Method to send a private message to the author of a topic def send_pm_to_author(author_username, topic_id, message) title = "Your topic (ID: #{topic_id}) has been closed" text = "Hello @#{author_username},\n\nYour topic (ID: #{topic_id}) has been closed. Reason: #{message}\n\nIf you have any questions or need further assistance, feel free to reach out to us.\n\nBest regards,\nThe CodeWizardsHQ Team"