Skip to content

Commit

Permalink
Invite: プラグインを新規作成
Browse files Browse the repository at this point in the history
JOIN メッセージが複数行でも発言できるようにしてある
  • Loading branch information
koi-chan committed Aug 10, 2015
1 parent a80f631 commit 58b7cbd
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/rgrb/plugin/invite/irc_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# vim: fileencoding=utf-8

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

module RGRB
module Plugin
# INVITE されたとき、そのチャンネルに JOIN するプラグイン
module Invite
# Invite の IRC アダプター
class IrcAdapter
include Cinch::Plugin
include ConfigurableAdapter

set(plugin_name: 'Invite')
listen_to(:invite, method: :invite)

def initialize(*args)
super

config_data = config[:plugin] || {}
@join_message =
config_data['JoinMessage'] || 'ご招待いただきありがとう'
end

# 自分が INVITE されたら自動的にそのチャンネルに入る
# @param [Cinch::Message] m 送信されたメッセージ
# @return [void]
def invite(m)
Channel(m.channel).join
@join_message.each do |line|
message = line.chomp
m.target.send(message, true)
log_notice(m.target, message)
end
end
end
end
end
end

0 comments on commit 58b7cbd

Please sign in to comment.