Module: ESM::Command::Server::Sqf::V1
- Defined in:
- lib/esm/command/server/sqf.rb
Instance Method Summary collapse
- #minify_sqf(sqf) ⇒ Object
- #on_execute ⇒ Object
- #on_response ⇒ Object
-
#response_message ⇒ Object
Unfortunately, the SQF sends back a formatted string.
Instance Method Details
#minify_sqf(sqf) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/esm/command/server/sqf.rb', line 101 def minify_sqf(sqf) [ [/\s*;\s*/, ";"], [/\s*:\s*/, ":"], [/\s*,\s*/, ","], [/\s*\[\s*/, "["], [/\s*\]\s*/, "]"], [/\s*\(\s*/, "("], [/\s*\)\s*/, ")"], [/\s*-\s*/, "-"], [/\s*\+\s*/, "+"], [/\s*\/\s*/, "/"], [/\s*\*\s*/, "*"], [/\s*%\s*/, "%"], [/\s*=\s*/, "="], [/\s*!\s*/, "!"], [/\s*>\s*/, ">"], [/\s*<\s*/, "<"], [/\s*>>\s*/, ">>"], [/\s*&&\s*/, "&&"], [/\s*\|\|\s*/, "||"], [/\s*\}\s*/, "}"], [/\s*\{\s*/, "{"], [/\s+/, " "], [/\n+/, ""], [/\r+/, ""], [/\t+/, ""] ].each do |group| sqf = sqf.gsub(group.first, group.second) end sqf end |
#on_execute ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/esm/command/server/sqf.rb', line 79 def on_execute check_for_owned_server! execute_on = if target_user check_for_registered_target_user! if target_user.is_a?(ESM::User) # Return their steam uid target_uid else "server" end deliver!(command_name: "exec", function_name: "exec", target: execute_on, code: minify_sqf(arguments.code_to_execute)) end |
#on_response ⇒ Object
95 96 97 98 99 |
# File 'lib/esm/command/server/sqf.rb', line 95 def on_response return if @response..blank? reply() end |
#response_message ⇒ Object
Unfortunately, the SQF sends back a formatted string. Match the response from the server and then reply back to the user with a new message
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/esm/command/server/sqf.rb', line 118 def case @response. when /executed on server successfully/i match = @response..match(/```(.*)```/) ESM::Embed.build( :success, description: I18n.t( "commands.sqf_v1.responses.server_success_with_return", user: current_user.mention, response: match[1], server_id: target_server.server_id ) ) when /executed code on server/i ESM::Embed.build( :success, description: I18n.t( "commands.sqf_v1.responses.server_success", user: current_user.mention, server_id: target_server.server_id ) ) when /executed code on target/i ESM::Embed.build( :success, description: I18n.t( "commands.sqf_v1.responses.target_success", user: current_user.mention, server_id: target_server.server_id, target_uid: target_user.steam_uid ) ) when /invalid target/i ESM::Embed.build( :error, description: I18n.t( "commands.sqf_v1.responses.invalid_target", user: current_user.mention, server_id: target_server.server_id, target_uid: target_user.steam_uid ) ) else @response. end end |