Class: Commands_manager
- Inherits:
-
Object
- Object
- Commands_manager
- Defined in:
- lib/rirc.rb
Instance Method Summary collapse
- #check_cmds(ircbot, msg, pluginmgr) ⇒ Object
- #hooks ⇒ Object
-
#initialize ⇒ Commands_manager
constructor
A new instance of Commands_manager.
-
#on(reg, &block) ⇒ Object
def initialize(log_path, err_path) @reg_s = [] @hook_s = [] @size = 0 @log_path = log_path @err_path = err_path end.
- #regs ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Commands_manager
Returns a new instance of Commands_manager.
790 791 792 793 794 795 796 |
# File 'lib/rirc.rb', line 790 def initialize @reg_s = [] @hook_s = [] @size = 0 @log_path = "./.log" @err_path = "./.errlog" end |
Instance Method Details
#check_cmds(ircbot, msg, pluginmgr) ⇒ Object
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 |
# File 'lib/rirc.rb', line 814 def check_cmds(ircbot, msg, pluginmgr) if @size == 0 return end 0.upto(@size - 1) do |i| if msg.(@reg_s[i]) File.write(@log_path, msg, File.size(@log_path), mode: 'a') begin @hook_s[i].call(ircbot, msg, pluginmgr) rescue => e if File.exist?(@err_path) File.write(@err_path, "COMMAND FAILED TO EXECUTE", File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') File.write(@err_path, e.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, e.backtrace.to_s, File.size(@err_path), mode: 'a') File.write(@err_path, "======================================================", File.size(@err_path), mode: 'a') end end end end end |
#hooks ⇒ Object
838 839 840 |
# File 'lib/rirc.rb', line 838 def hooks return @hook_s end |
#on(reg, &block) ⇒ Object
def initialize(log_path, err_path) @reg_s = [] @hook_s = [] @size = 0 @log_path = log_path @err_path = err_path end
807 808 809 810 811 812 |
# File 'lib/rirc.rb', line 807 def on(reg, &block) reg = Regexp.new(reg.to_s) @reg_s.push(reg) @hook_s << block @size += 1 end |
#regs ⇒ Object
842 843 844 |
# File 'lib/rirc.rb', line 842 def regs return @reg_s end |
#size ⇒ Object
846 847 848 |
# File 'lib/rirc.rb', line 846 def size return @size end |