Skip to content

Commit

Permalink
プラグイン Part 追加
Browse files Browse the repository at this point in the history
退出コマンドが発言されたとき、そのチャンネルから PART するプラグインを追加した。
  • Loading branch information
koi-chan committed Mar 18, 2015
1 parent 1548138 commit 315916d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions doc/plugins/part.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Part
====

コマンドを発言されたとき、そのチャンネルから退出するプラグインです。

コマンド
--------

### チャンネルからの退出 (`.part` / `.part-NICK`)

どちらのコマンドもチャンネルから退出するという機能に違いはありません。
そのチャンネルに複数の `.part` コマンドに反応するボットがいた時に、ニックネームを指定して退出させるために、後者のコマンドも用意されています。

_NICK_ には、退出させたいボットのニックネームを入れます。
アルファベットの大文字・小文字の違いは無視します。

####

```
.part
.part-rgrb (ニックネームが "rgrb" の場合)
```

設定
----

設定ファイルに以下を追加して、プラグインの設定を行います。

```yaml
# 退出プラグインの設定
Part:
# 退出時のメッセージ
# (IRCプロトコルにおける) PART コマンドの引数として使われます。
PartMessage: 'config-part message'
```
35 changes: 35 additions & 0 deletions lib/rgrb/plugin/part/irc_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# vim: fileencoding=utf-8

require 'cinch'
require 'rgrb/plugin/configurable_adapter'

module RGRB
module Plugin
module Part
# Part の IRC アダプター
class IrcAdapter
include Cinch::Plugin
include ConfigurableAdapter

set(plugin_name: 'Part')
match(/part/, method: :part)
match(/part-(\w+)/, method: :part)

def initialize(*args)
super

config_data = config[:plugin]
@part_message = config_data['PartMessage']
end

# コマンドを発言されたらそのチャンネルから退出する
# @return [void]
def part(m, nick = nil)
if nick == m.bot.to_s || nick == nil
Channel(m.channel).part(@part_message)
end
end
end
end
end
end

0 comments on commit 315916d

Please sign in to comment.