Skip to content

Documentation #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down Expand Up @@ -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`"
Expand All @@ -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,
Expand All @@ -67,13 +70,15 @@ 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 })
author_username = topic.user.username
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
Expand All @@ -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}:<br>#{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,
Expand All @@ -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"
Expand Down