Skip to content
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

Discord notifications #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.1.2
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.2'

gem 'net-http'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ GEM
nio4r (2.5.9)
nokogiri (1.15.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.3-x86_64-linux)
racc (~> 1.4)
optimist (3.0.1)
Expand Down
35 changes: 34 additions & 1 deletion app/controllers/concerns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create
if @concern.save

# TODO: Send notification to staff

send_discord_notification(@concern)
# Email confirmation to concerned player
ConcernMailer.confirm_receipt(@concern).deliver_now

Expand Down Expand Up @@ -132,5 +132,38 @@ def display_timezone
def concern_params
params.require(:concern).permit(:concerning_player_id, :concerning_player_id_type, :background, :description, :recommended_response, :concerned_email, :concerned_cert_code, screenshots: [])
end

def send_discord_notification(concern)
discord_webhook_url = 'https://discord.com/api/webhooks/1180257401870499921/yxNYyaQ28EmiO3mUEPBrwc9koZLSgWECosknNV8RMuOsNT1xbXH8FH0LjBt5cyWvxtrE'

# Concern contents to be sent to the discord server
concern_content = "New consern has been submitted\n\n"
concern_content += "Player being reported / ID: #{concern.concerning_player_id}\n"
concern_content += "Type of ID : #{concern.concerning_player_id_type}\n\n"
concern_content += "Background information: #{concern.background}\n\n"
concern_content += "Description: #{concern.description}\n\n"
concern_content += "Recommended Response: #{concern.recommended_response}"

payload = {
content: concern_content
}

uri = URI.parse(discord_webhook_url)
# Set up HTTP connction and send POST request
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' })
request.body = payload.to_json # Payload in the request body

response = http.request(request)

# For troubleshotting or debugging purposes
if response.code.to_i == 204
Rails.logger.info("Discord notification sent successfully.")
else
Rails.logger.error("Failed to send Discord notification. HTTP Status: #{response.code}, Response Body: #{response.body}")
end
end

end
22 changes: 11 additions & 11 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

ActiveRecord::Schema.define(version: 2024_01_10_174212) do

create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
Expand All @@ -22,7 +22,7 @@
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
Expand All @@ -34,7 +34,7 @@
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
Expand All @@ -57,7 +57,7 @@
t.string "mixer"
end

create_table "ahoy_events", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "ahoy_events", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.bigint "visit_id"
t.bigint "user_id"
t.string "name"
Expand All @@ -68,7 +68,7 @@
t.index ["visit_id"], name: "index_ahoy_events_on_visit_id"
end

create_table "ahoy_visits", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "ahoy_visits", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "visit_token"
t.string "visitor_token"
t.bigint "user_id"
Expand Down Expand Up @@ -96,7 +96,7 @@
t.index ["visitor_token", "started_at"], name: "index_ahoy_visits_on_visitor_token_and_started_at"
end

create_table "badge_activations", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "badge_activations", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "twitch_username"
t.integer "twitch_id"
t.datetime "activated_on"
Expand All @@ -105,7 +105,7 @@
t.datetime "updated_at", precision: 6, null: false
end

create_table "comments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "comments", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.integer "commenter_id"
t.integer "commentable_id"
t.string "commentable_type"
Expand All @@ -115,7 +115,7 @@
t.datetime "updated_at", precision: 6, null: false
end

create_table "concerns", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "concerns", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "concerning_player_id"
t.string "concerning_player_id_type"
t.text "background"
Expand Down Expand Up @@ -218,7 +218,7 @@
t.datetime "published_on"
end

create_table "survey_invites", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "survey_invites", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "email"
t.string "survey_code"
t.string "surveyable_type"
Expand All @@ -229,7 +229,7 @@
t.datetime "updated_at", precision: 6, null: false
end

create_table "twitch_tokens", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "twitch_tokens", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "access_token"
t.integer "expires_in"
t.datetime "created_at", precision: 6, null: false
Expand Down Expand Up @@ -271,7 +271,7 @@
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

create_table "verifications", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
create_table "verifications", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "email"
Expand Down
Binary file added redis-stable.tar.gz
Binary file not shown.