Move basic command handling to Server

master
Marrub 2017-08-13 06:48:00 -04:00
parent e84f48c4a5
commit 34d8744a6a
2 changed files with 30 additions and 24 deletions

View File

@ -180,6 +180,23 @@ module Vrobot4::Server
""
end
# Basic command message handler.
#
# Checks if the message starts with "." and splits the command
# from the arguments, then emits an on_command event.
#
# Otherwise, it will emit an on_message event.
#
# @param m [Vrobot4::Server::Message] the message to parse and emit
def handle_text_cmd m
if m.msg.start_with? '.'
arg = m.msg.split(' ', 2)
on_command m, arg[0][1 .. -1], (arg[1] or "")
else
on_message m
end
end
protected
# Implementation defined permission loader.
# Loads information into +@mprm+.

View File

@ -31,12 +31,7 @@ class Sv_Discord < Vrobot4::Server::AudioServer
reply: -> (text) {evt.respond text},
reply_b: -> (text) {evt.respond "```\n" + text + "```"}
if m.msg.start_with? '.'
arg = m.msg.split(' ', 2)
on_command m, arg[0][1..-1], (arg[1] or "")
else
on_message m
end
handle_text_cmd m
end
end
@ -80,33 +75,27 @@ class Sv_Discord < Vrobot4::Server::AudioServer
# (see Vrobot4::Server::Server#load_permissions)
def load_permissions pinf
@mprm = {chan: {}, role: {}, glob: {}}
pinf.each do |perm|
mod = Vrobot4::Module.get_module_type(perm["module"])[:type]
if perm.key? "channel"
pinf.each do |pr|
mod = Vrobot4::Module.get_module_type(pr["module"])[:type]
if pr.key? "channel"
@mprm[:chan][mod] = ChannelPerms.new unless @mprm[:chan].key? mod
@mprm[:chan][mod][perm["channel"]] = true
elsif perm.key? "roles"
@mprm[:role][mod] = perm["roles"]
elsif perm.key? "enable"
@mprm[:glob][mod] = perm["enable"]
@mprm[:chan][mod][pr["channel"]] = true
elsif pr.key? "roles"
@mprm[:role][mod] = pr["roles"]
elsif pr.key? "enable"
@mprm[:glob][mod] = pr["enable"]
end
end
end if pinf
end
class ChannelPerms
def initialize
@cprm = {}
end
def initialize() @cprm = {} end
# Returns true if the channel is enabled, false otherwise.
def [] chan
@cprm[chan.name] or @cprm[chan.real.id]
end
def [](chan) @cprm[chan.name] or @cprm[chan.real.id] end
# Sets a channel's permission on/off.
def []= chan, set
@cprm[chan] = set
end
def []=(chan, set) @cprm[chan] = set end
end
private_constant :ChannelPerms