Skip to content

Commit

Permalink
ServerConnectionReport: Atheme-Services のサポート
Browse files Browse the repository at this point in the history
Atheme-Services が出力するサーバー状態を検知することができるようになった。
  • Loading branch information
koi-chan committed May 8, 2015
1 parent d8682a9 commit 25f9484
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/server_connection_report/atheme_services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Atheme-Services 用サーバーリレー監視プラグインの設定
ServerConnectionReport::AthemeServices:
# NOTICE を行うチャンネルの一覧
ChannelsToSend:
- ''
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# vim: fileencoding=utf-8

require 'cinch'

require 'rgrb/plugin/util/notice_on_each_channel'
require 'rgrb/plugin/util/logging'
require 'rgrb/plugin/server_connection_report/generator'

module RGRB
module Plugin
module ServerConnectionReport
# Atheme-Services 用サーバリレー監視プラグイン
module AthemeServices
# ServerConnectionReport::AthemeServices の IRC アダプター
class IrcAdapter
include Cinch::Plugin
include Util::NoticeOnEachChannel

# メッセージを送信するチャンネルのリスト
attr_reader :channels_to_send

# サーバメッセージのチャンネル名
SERVER_MESSAGE_CHANNEL = '#services'

set(plugin_name: 'ServerConnectionReport::AthemeServices')
self.prefix = ''

match(/^server_add\(\): ([\w\.]+)/, method: :joined)
match(/^server_delete\(\): ([\w\.]+)/, method: :disconnected)

def initialize(*)
super

config_data = config[:plugin]
@channels_to_send = config_data['ChannelsToSend']

@generator = Generator.new
end

# サーバ接続メッセージを NOTICE する
# @param [Cinch::Message] m メッセージ
# @param [String] server サーバ
# @return [void]
def joined(m, server)
if m.channel == SERVER_MESSAGE_CHANNEL
log_incoming(m)
notice_on_each_channel(@generator.joined(server))
end
end

# サーバ切断メッセージを NOTICE する
# @param [Cinch::Message] m メッセージ
# @param [String] server サーバ
# @return [void]
def disconnected(m, server)
if m.channel == SERVER_MESSAGE_CHANNEL
log_incoming(m)
notice_on_each_channel(@generator.disconnected(server))
end
end
end
end
end
end
end

0 comments on commit 25f9484

Please sign in to comment.