Skip to content

Commit

Permalink
Part: 対象外のチャンネルでコマンドが使われたときにメッセージを送れるようにした
Browse files Browse the repository at this point in the history
Util::Logging を使ってログ出力するようにした。
  • Loading branch information
koi-chan committed Sep 4, 2015
1 parent cd9fcba commit 59ec60f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/part.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Part:
# コマンドを無効化するチャンネル
ExcludeChannels:
- '#cre'
# コマンドを無効化したチャンネルで代わりに送信するメッセージ
NotPartMessage: 'このチャンネルでは退出コマンドを使えないよう設定されています'
2 changes: 2 additions & 0 deletions doc/plugins/part.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ Part:
# コマンドを無効化するチャンネル
ExcludeChannels:
- '#cre'
# コマンドを無効化したチャンネルで代わりに送信するメッセージ
NotPartMessage: 'このチャンネルでは退出コマンドを使えないよう設定されています'
```
13 changes: 11 additions & 2 deletions lib/rgrb/plugin/part/irc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'cinch'
require 'rgrb/plugin/configurable_adapter'
require 'rgrb/plugin/util/logging'

module RGRB
module Plugin
Expand All @@ -11,6 +12,7 @@ module Part
class IrcAdapter
include Cinch::Plugin
include ConfigurableAdapter
include Util::Logging

set(plugin_name: 'Part')
match(/part(?:-(\w+))?$/, method: :part)
Expand All @@ -21,6 +23,8 @@ def initialize(*args)
config_data = config[:plugin] || {}
@part_message =
config_data['PartMessage'] || 'ご利用ありがとうございました'
@not_part_message =
config_data['NotPartMessage'] || 'このチャンネルでは退出コマンドを利用できません'
@exclude_channels =
config_data['ExcludeChannels'].map do |channel|
channel.downcase
Expand All @@ -32,10 +36,15 @@ def initialize(*args)
# @param [String] nick 指定されたニックネーム
# @return [void]
def part(m, nick)
return if @exclude_channels.index(m.channel.name.downcase)
if @exclude_channels.index(m.channel.name.downcase)
log_incoming(m)
m.target.send(@not_part_message, true)
log_notice(m.target, @not_part_message)
return
end

if !nick || nick.downcase == bot.nick.downcase
log(m.raw, :incoming, :info)
log_incoming(m)
Channel(m.channel).part(@part_message)
log("<PART on #{m.channel}> #{@part_message}", :outgoing, :info)
end
Expand Down

0 comments on commit 59ec60f

Please sign in to comment.