Skip to content

Commit

Permalink
fix-ctcp: ログを残すようにした
Browse files Browse the repository at this point in the history
自分(と同じNICKの他のクライアントを含む)が発信した CTCP 要求には応答しないようにした
  • Loading branch information
koi-chan committed Jan 19, 2019
1 parent 00ec914 commit 8e77346
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/rgrb/plugin/ctcp/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 Ctcp
class IrcAdapter
include Cinch::Plugin
include ConfigurableAdapter
include Util::Logging

set(plugin_name: 'Ctcp')
ctcp(:clientinfo)
Expand All @@ -29,27 +31,41 @@ def initialize(*args)
end

def ctcp_clientinfo(m)
m.ctcp_reply(@valid_cmd.join(' '))
ctcp_reply(m, @valid_cmd.join(' '))
end

def ctcp_version(m)
m.ctcp_reply("RGRB #{RGRB::VERSION_WITH_COMMIT_ID}")
ctcp_reply(m, "RGRB #{RGRB::VERSION_WITH_COMMIT_ID}")
end

def ctcp_time(m)
m.ctcp_reply(Time.now.strftime('%a, %d %b %Y %T %z'))
ctcp_reply(m, Time.now.strftime('%a, %d %b %Y %T %z'))
end

def ctcp_ping(m)
m.ctcp_reply(m.ctcp_args.join(' '))
ctcp_reply(m, m.ctcp_args.join(' '))
end

def ctcp_userinfo(m)
m.ctcp_reply(@userinfo)
ctcp_reply(m, @userinfo)
end

def ctcp_source(m)
m.ctcp_reply('https://github.com/cre-ne-jp/rgrb')
ctcp_reply(m, 'https://github.com/cre-ne-jp/rgrb')
end

private

# CTCP 応答を返す
# @param [Cinch::Message] m
# @param [String] message 送信メッセージ
# @return [void]
def ctcp_reply(m, message)
log_incoming(m)
return if m.target.name == bot.nick

m.ctcp_reply(message)
log("<CTCP-reply to #{m.target.name}> #{message.inspect}", :outgoing, :info)
end
end
end
Expand Down

0 comments on commit 8e77346

Please sign in to comment.