From f987c780f7a476a380258f6257c74fcb740a5d03 Mon Sep 17 00:00:00 2001 From: Marrub Date: Sat, 12 Aug 2017 02:07:09 -0400 Subject: [PATCH] Fix over-complicated syntax Look, I started this project not knowing anything about Ruby, okay? :) --- source/module.rb | 17 ++++++----------- source/modules/mod_fun.rb | 8 ++++---- source/server.rb | 14 +++++++------- source/servers/sv_discord.rb | 12 ++++-------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/source/module.rb b/source/module.rb index 3d1763e..bdd4e4f 100644 --- a/source/module.rb +++ b/source/module.rb @@ -54,9 +54,12 @@ module Vrobot4::Module # @param argv [Array] array of string arguments # @return [Boolean] if this should block further command callbacks def on_command m, cnam, argv - if (cmd = get_cmd m, cnam) - begin; cmd.run(m, argv) - rescue; m.reply "Error:", $!.to_s; end + if (cmd = all_cmds(m)[cnam]) + begin + cmd.run(m, argv) + rescue + m.reply "Error:", $!.to_s + end true else false @@ -70,14 +73,6 @@ module Vrobot4::Module @commands.select {|name, cmd| cmd.usable_in? m} end - # Gets a command by name in a specified context. - # @param m [Vrobot4::Server::Message] message for context - # @return [Vrobot4::Module::Command] command if found, nil if not - def get_cmd m, name - cmds = all_cmds(m) - cmds[name] if cmds.key? name - end - protected # Registers a command into this module. # @param fn [Symbol] name of method to add diff --git a/source/modules/mod_fun.rb b/source/modules/mod_fun.rb index 28dc622..77baf05 100644 --- a/source/modules/mod_fun.rb +++ b/source/modules/mod_fun.rb @@ -23,10 +23,10 @@ class Mod_Fun < Vrobot4::Module::Module register :c_what, "what", "What the fuck did you just fucking say about" end - def c_carmack m, argv; m.reply "m" * (rand(24) + 5) ; end - def c_revenant m, argv; m.reply "A" * (rand(24) + 3) ; end - def c_wan m, argv; m.reply "wan! " * (rand(10) + 1) ; end - def c_nyan m, argv; m.reply "nyan " * (rand(10) + 1) + "~"; end + def c_carmack (m, argv) m.reply "m" * (rand(24) + 5) end + def c_revenant(m, argv) m.reply "A" * (rand(24) + 3) end + def c_wan (m, argv) m.reply "wan! " * (rand(10) + 1) end + def c_nyan (m, argv) m.reply "nyan " * (rand(10) + 1) + "~" end def c_box m, argv str = argv.join(" ") diff --git a/source/server.rb b/source/server.rb index 04d63d8..1a490eb 100644 --- a/source/server.rb +++ b/source/server.rb @@ -105,12 +105,12 @@ module Vrobot4::Server # [:reply] Method that sends a message to the specified channel. # [:reply_b] Method that sends a large message to the specified channel. def initialize(**info) - @msg = info[:msg] if info.key? :msg - @user = info[:user] if info.key? :user - @chan = info[:chan] if info.key? :chan - @serv = info[:serv] if info.key? :serv - @reply = info[:reply] if info.key? :reply - @reply_b = info[:reply_b] if info.key? :reply_b + @msg = info[:msg] + @user = info[:user] + @chan = info[:chan] + @serv = info[:serv] + @reply = info[:reply] + @reply_b = info[:reply_b] end # Sends a message to the channel this message originated from. @@ -142,7 +142,7 @@ module Vrobot4::Server mt[:servflags] and mt[:servflags] !~ flags raise ArgumentError, "Module " + mod + " not valid for this server" end - @modules << mt[:type].new(@info.key?(mod) ? @info[mod] : nil) + @modules << mt[:type].new(@info[mod]) end # Drops a module from the load list. diff --git a/source/servers/sv_discord.rb b/source/servers/sv_discord.rb index 00a20f1..6fd9709 100644 --- a/source/servers/sv_discord.rb +++ b/source/servers/sv_discord.rb @@ -15,11 +15,8 @@ class Sv_Discord < Vrobot4::Server::AudioServer def initialize info super - if info.key? "admins"; @ops = info["admins"] - else; @ops = []; end - - if info.key? "halfop"; @hop = info["halfop"] - else; @hop = []; end + @ops = info["admins"] or [] + @hop = info["halfop"] or [] @bot = Discordrb::Bot.new \ token: info["apikey"], @@ -91,7 +88,7 @@ class Sv_Discord < Vrobot4::Server::AudioServer @mprm[:chan][mod][perm["channel"]] = true elsif perm.key? "roles" @mprm[:role][mod] = perm["roles"] - else + elsif perm.key? "enable" @mprm[:glob][mod] = perm["enable"] end end @@ -104,8 +101,7 @@ class Sv_Discord < Vrobot4::Server::AudioServer # Returns true if the channel is enabled, false otherwise. def [] chan - (@cprm.key? chan.name and @cprm[chan.name]) or - (@cprm.key? chan.real.id and @cprm[chan.real.id]) + @cprm[chan.name] or @cprm[chan.real.id] end # Sets a channel's permission on/off.