class OceanWechatRobot::Command
Public Class Methods
new(argv)
click to toggle source
options()
click to toggle source
参数选项
Calls superclass method
# File lib/ocean_wechat_robot/command.rb, line 15 def self.options [ ['--webhook=wechat group webhook', '微信群的webhook'], ['--msg=content', '微信群消息'], ['--msg-type=[text|markdown|news]', '微信群消息的类型'], ['--at-mobiles=phone', '@人的手机号,多个用,分割'], ].concat(super) end
Public Instance Methods
run()
click to toggle source
3¶ ↑
重写父类run,执行逻辑,不需要调用 super
# File lib/ocean_wechat_robot/command.rb, line 66 def run wechat = OceanWechatRobot::WechatRobot.new("#{@webhook}") if @msg_type == 'text' wechat.send_text(@msg, @at_mobiles) elsif @msg_type == 'markdown' wechat.send_markdown(@msg, @at_mobiles) elsif @msg_type == 'news' # wechat.send_news('', '', '', '', @at_mobiles) raise 'news 类型未实现......' end end
validate!()
click to toggle source
3¶ ↑
参数校验
Calls superclass method
# File lib/ocean_wechat_robot/command.rb, line 44 def validate! super unless @webhook help!('please set webhook value!') end unless @msg help!('please set msg value!') end unless @msg_type help!('please set msg type value!') end if @msg_type && !%w(text markdown news).include?(@msg_type) help! "`#{@msg_type}' is not a valid msg type!" end end