Skip to content

Instantly share code, notes, and snippets.

@esetomo
Created May 1, 2017 17:49
Show Gist options
  • Save esetomo/65bd1b4084a888e7b47e0e9514232da5 to your computer and use it in GitHub Desktop.
Save esetomo/65bd1b4084a888e7b47e0e9514232da5 to your computer and use it in GitHub Desktop.
マストドンに通知を送り付けるやつ
bot-secret-string: /home/username/run/bot.pipe
# -*- 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
#!/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
# frozen_string_literal: true
source "https://rubygems.org"
gem 'mail'
gem 'mastodon-api', require: 'mastodon', github: 'tootsuite/mastodon-api'
$ mkfifo ~/run/bot.pipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment