-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ServerConnectionReport: Atheme-Services のサポート
Atheme-Services が出力するサーバー状態を検知することができるようになった。
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Atheme-Services 用サーバーリレー監視プラグインの設定 | ||
ServerConnectionReport::AthemeServices: | ||
# NOTICE を行うチャンネルの一覧 | ||
ChannelsToSend: | ||
- '' |
65 changes: 65 additions & 0 deletions
65
lib/rgrb/plugin/server_connection_report/atheme_services/irc_adapter.rb
This file contains 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
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 |