added discord webhook functionality#8
Conversation
|
I don't get how to fix that name bug. what do i do? |
dpca
left a comment
There was a problem hiding this comment.
Thanks for adding this functionality! I haven't made a discord bot before but overall this approach looks like it will work. I added some comments to help get you unstuck with the name bug, but let me know if there's anything that's confusing or unclear and I can elaborate more.
|
|
||
| def update(str) | ||
| @logger.info "[FakeDiscord]: #{str}" | ||
| end |
There was a problem hiding this comment.
Looks like this class is missing an end statement, which may be causing some of the name errors. In Ruby, each class and function definition must have a corresponding end to close it out.
| def initialize(logger) | ||
| @logger = logger | ||
| @discord = if ENV['ENVIRONMENT'] != 'test' && env_keys_exist? | ||
| Discordrb::Webhooks::Client.new(url: ENV['DISCORD_WEBHOOK_URL']).freeze |
There was a problem hiding this comment.
If the environment keys don't exist, we should instantiate a FakeDiscord instance here which just logs the output instead of sending to discord. Very useful for testing purposes.
| @@ -0,0 +1,53 @@ | |||
| require 'discordrb/webhooks' | |||
|
|
|||
| class FakeDiscord | |||
There was a problem hiding this comment.
The FakeDiscord class should respond to the same commands as the real class, which from looking below are execute and then content = to set the text. Is there an easier way than setting execute and using the webhook API? Usually there's a REST-based way to send messages, but I'm not familiar with Discord so maybe not.
|
|
||
| def send(clinic) | ||
| @logger.info "[DiscordClient] Sending message for #{clinic.title} (#{clinic.new_appointments} new appointments)" | ||
| text = clinic.discord_text |
There was a problem hiding this comment.
The BaseClinic class will need to have discord_text added to it, it can probably be similar to what the slack text looks like.
| end | ||
|
|
||
| def post(clinics) | ||
| clinics.filter(&:should_discord_message?).each do |clinic| |
There was a problem hiding this comment.
BaseClinic will also need to have should_discord_message? defined there. It should be similar to the logic for whether to slack. The &:should_discord_message? is short for filter { |clinic| clinic.should_discord_message? }.
| else | ||
| @twitter.update(text) | ||
| end | ||
| end |
There was a problem hiding this comment.
This file should stay the same, moving the end to here may change the behavior.
| clinic.save_message_time | ||
| end | ||
| end | ||
| end No newline at end of file |
There was a problem hiding this comment.
We should ensure that there are newlines at the end of each file too.
Hi!
I thought it'd be cool to add Discord functionality so that people who don't use Twitter or Slack have an option.
I've never used Ruby before whatsoever, so if there are any mistakes, let me know so I can fix them. Thanks!