|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -module Scrims |
4 | | - module Services |
5 | | - # Sends Discord webhook notifications for scrim-related events. |
6 | | - # Webhook URL is configured via SCRIMS_LOL_DISCORD_WEBHOOK_URL env variable. |
7 | | - class DiscordWebhookService |
8 | | - WEBHOOK_URL = ENV.fetch('SCRIMS_LOL_DISCORD_WEBHOOK_URL', nil) |
| 3 | +# Sends Discord webhook notifications for scrim-related events. |
| 4 | +# Webhook URL is configured via SCRIMS_LOL_DISCORD_WEBHOOK_URL env variable. |
| 5 | +class DiscordWebhookService |
| 6 | + WEBHOOK_URL = ENV.fetch('SCRIMS_LOL_DISCORD_WEBHOOK_URL', nil) |
9 | 7 |
|
10 | | - def self.notify_scrim_created(scrim) |
11 | | - return unless WEBHOOK_URL.present? |
| 8 | + def self.notify_scrim_created(scrim) |
| 9 | + return unless WEBHOOK_URL.present? |
12 | 10 |
|
13 | | - org_name = scrim.organization.name |
14 | | - opponent = scrim.opponent_team&.name || 'TBD' |
15 | | - scheduled = scrim.scheduled_at&.strftime('%d/%m %H:%M') || 'TBD' |
| 11 | + org_name = scrim.organization.name |
| 12 | + opponent = scrim.opponent_team&.name || 'TBD' |
| 13 | + scheduled = scrim.scheduled_at&.strftime('%d/%m %H:%M') || 'TBD' |
16 | 14 |
|
17 | | - payload = { |
18 | | - embeds: [{ |
19 | | - title: '📅 New Scrim Scheduled', |
20 | | - color: 0xC89B3C, |
21 | | - fields: [ |
22 | | - { name: 'Team', value: org_name, inline: true }, |
23 | | - { name: 'Opponent', value: opponent, inline: true }, |
24 | | - { name: 'Scheduled', value: scheduled, inline: true } |
25 | | - ], |
26 | | - footer: { text: 'scrims.lol — powered by ProStaff.gg' }, |
27 | | - timestamp: Time.current.iso8601 |
28 | | - }] |
29 | | - } |
| 15 | + payload = { |
| 16 | + embeds: [{ |
| 17 | + title: 'New Scrim Scheduled', |
| 18 | + color: 0xC89B3C, |
| 19 | + fields: [ |
| 20 | + { name: 'Team', value: org_name, inline: true }, |
| 21 | + { name: 'Opponent', value: opponent, inline: true }, |
| 22 | + { name: 'Scheduled', value: scheduled, inline: true } |
| 23 | + ], |
| 24 | + footer: { text: 'scrims.lol — powered by ProStaff.gg' }, |
| 25 | + timestamp: Time.current.iso8601 |
| 26 | + }] |
| 27 | + } |
30 | 28 |
|
31 | | - post_webhook(payload) |
32 | | - end |
| 29 | + post_webhook(payload) |
| 30 | + end |
33 | 31 |
|
34 | | - def self.post_webhook(payload) |
35 | | - conn = Faraday.new(url: WEBHOOK_URL) do |f| |
36 | | - f.request :json |
37 | | - f.adapter Faraday.default_adapter |
38 | | - end |
39 | | - conn.post('', payload) |
40 | | - rescue Faraday::Error => e |
41 | | - Rails.logger.warn("[ScrimsDiscordWebhook] #{e.message}") |
42 | | - end |
| 32 | + def self.post_webhook(payload) |
| 33 | + conn = Faraday.new(url: WEBHOOK_URL) do |f| |
| 34 | + f.request :json |
| 35 | + f.adapter Faraday.default_adapter |
43 | 36 | end |
| 37 | + conn.post('', payload) |
| 38 | + rescue Faraday::Error => e |
| 39 | + Rails.logger.warn("[ScrimsDiscordWebhook] #{e.message}") |
44 | 40 | end |
45 | 41 | end |
0 commit comments