Method: AuthModule#parse_args
- Defined in:
- lib/rbot/core/auth.rb
#parse_args(ar, setting) ⇒ Object
The permission parameters accept arguments with the following syntax:
cmd_path... [on #chan .... | in here | in private]
This auxiliary method scans the array ar to see if it matches the given syntax: it expects + or - signs in front of cmd_path elements when setting = true
It returns an array whose first element is the array of cmd_path, the second element is an array of locations and third an array of warnings occurred while parsing the strings
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbot/core/auth.rb', line 59 def parse_args(ar, setting) cmds = [] locs = [] warns = [] doing_cmds = true next_must_be_chan = false want_more = false last_idx = 0 ar.each_with_index { |x, i| if doing_cmds # parse cmd_path # check if the list is done if x == "on" or x == "in" doing_cmds = false next_must_be_chan = true if x == "on" next end if "+-".include?(x[0]) warns << ArgumentError.new(_("please do not use + or - in front of command %{command} when resetting") % {:command => x}) unless setting else warns << ArgumentError.new(_("+ or - expected in front of %{string}") % {:string => x}) if setting end cmds << x else # parse locations if x[-1].chr == ',' want_more = true else want_more = false end case next_must_be_chan when false locs << x.gsub(/^here$/,'_').gsub(/^private$/,'?') else warns << ArgumentError.new(_("'%{string}' doesn't look like a channel name") % {:string => x}) unless @bot.server.supports[:chantypes].include?(x[0]) locs << x end unless want_more last_idx = i break end end } warns << _("trailing comma") if want_more warns << _("you probably forgot a comma") unless last_idx == ar.length - 1 return cmds, locs, warns end |