Created
May 1, 2017 17:49
-
-
Save esetomo/65bd1b4084a888e7b47e0e9514232da5 to your computer and use it in GitHub Desktop.
マストドンに通知を送り付けるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot-secret-string: /home/username/run/bot.pipe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- ruby -*- | |
God.watch do |w| | |
w.name = "bot-pipe" | |
w.group = "local" | |
w.dir = HOME + '/work/mastodon/bot' | |
w.start = HOME + '/work/mastodon/bot/bot.rb' | |
w.log = HOME + "/log/bot.log" | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 1.minutes | |
c.running = false | |
c.notify = 'developers' | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/username/.rbenv/shims/ruby | |
# -*- ruby -*- | |
require 'bundler' | |
Bundler.require | |
DOMAIN = "my.domain" | |
TOKEN = "API TOKEN" | |
loop do | |
open("/home/username/run/bot.pipe", "r") do |r| | |
input = r.read | |
mail = Mail.new(input) | |
text = mail.body.decoded | |
text = input if text.empty? | |
client = Mastodon::REST::Client.new(base_url: "https://#{DOMAIN}", bearer_token: TOKEN) | |
client.create_status("@Owner\n" + text, visibility: :direct) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem 'mail' | |
gem 'mastodon-api', require: 'mastodon', github: 'tootsuite/mastodon-api' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkfifo ~/run/bot.pipe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment