From 1a7a502cbee1e4448b96c7e89aca7990fb5f9439 Mon Sep 17 00:00:00 2001 From: zgr2575 <62474113+zgr2575@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:38:37 -0400 Subject: [PATCH 1/3] In-Game-Ranking --- In Game Ranking/readme.md | 25 +++++ In Game Ranking/roblox script.lua | 179 ++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 In Game Ranking/readme.md create mode 100644 In Game Ranking/roblox script.lua diff --git a/In Game Ranking/readme.md b/In Game Ranking/readme.md new file mode 100644 index 0000000..aa3ea9d --- /dev/null +++ b/In Game Ranking/readme.md @@ -0,0 +1,25 @@ +## Qbot API In-Game-Ranking Commands. + +Allows the user to promote, demote, setrank, fire, shout, suspend, unsuspend, addexp, removexp all from in game. + +How to setup: + +1. Make sure QBOT is running and the port 3001 is forwarded. +2. Open the attached "roblox script.lua" +3. Configure the settings at the top +```lua +local requiredRank = 255 -- Minimum rank allowed to use commands +local groupId = 11717434 -- Set this as your group ID +local server = '' -- URL of your QBOT instance EG: http::3001 +local apiKey = '' -- Replace with your actual API key (The one set in the .env file) +local commandPrefix = "!" -- Set this to your desired command prefix +``` + +And voula, you now have ranking commands! + +For additional support open a ticket in Lengo Labs. + +Created by: zgr2575 + +Last Updated: 7/19/2024 +Created: 7/19/2024 \ No newline at end of file diff --git a/In Game Ranking/roblox script.lua b/In Game Ranking/roblox script.lua new file mode 100644 index 0000000..82f4e95 --- /dev/null +++ b/In Game Ranking/roblox script.lua @@ -0,0 +1,179 @@ +--[[ +Copyright 2024 zgr2575 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Join Us + +Created by zgr2575, ping me in the server for support. +]]-- + +local requiredRank = 255 -- Minimum rank allowed to use commands +local groupId = 11717434 -- Set this as your group ID +local server = '' -- URL of your QBOT instance EG: http::3001 +local apiKey = '' -- Replace with your actual API key +local commandPrefix = "!" -- Set this to your desired command prefix + +local HttpService = game:GetService('HttpService') +local Players = game:GetService('Players') + +function slice(tbl, first, last, step) + local sliced = {} + + for i = first or 1, last or #tbl, step or 1 do + sliced[#sliced + 1] = tbl[i] + end + + return sliced +end + +local function postRequest(endpoint, data) + local headers = { + ["Content-Type"] = "application/json", + ["Authorization"] = apiKey + } + local options = { + Url = server .. endpoint, + Method = "POST", + Headers = headers, + Body = HttpService:JSONEncode(data) + } + local success, response = pcall(function() + + return HttpService:RequestAsync(options) + end) + if success then + print(success) + print(response) + return response + else + warn("HTTP request failed: " .. tostring(response)) + end +end + +local function getUserIdFromUsername(username) + local success, result = pcall(function() + print(Players:GetUserIdFromNameAsync(username)) + return Players:GetUserIdFromNameAsync(username) + end) + if success then + return result + else + warn("Failed to get user ID from username: " .. tostring(result)) + return nil + end +end + +game.Players.PlayerAdded:Connect(function(player) + player.Chatted:Connect(function(msg) + local args = msg:split(" ") + local command = args[1]:sub(1, #commandPrefix) + + if command == commandPrefix then + local cmd = args[1]:sub(#commandPrefix + 1) + + if cmd == "setrank" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local rank = slice(args, 3) + rank = table.concat(rank, ' ') + if userId and rank and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/setrank', { + id = userId, + role = rank + }) + end + end + elseif cmd == "promote" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/promote', { + id = userId + }) + end + end + elseif cmd == "demote" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/demote', { + id = userId + }) + end + end + elseif cmd == "fire" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/fire', { + id = userId + }) + end + end + elseif cmd == "shout" then + table.remove(args, 1) + local msg = table.concat(args, ' ') + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/shout', { + content = msg + }) + end + elseif cmd == "suspend" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local duration = tonumber(args[3]) + if userId and duration and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/suspend', { + id = userId, + duration = duration + }) + end + end + elseif cmd == "unsuspend" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/unsuspend', { + id = userId + }) + end + end + elseif cmd == "addxp" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local amount = tonumber(args[3]) + if userId and amount and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/xp/add', { + id = userId, + amount = amount + }) + end + end + elseif cmd == "removexp" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local amount = tonumber(args[3]) + if userId and amount and userId ~= player.UserId then + if player:GetRankInGroup(groupId) >= requiredRank then + postRequest('/xp/remove', { + id = userId, + amount = amount + }) + end + end + end + end + end) +end) From 261494be92ebaffa21583f13273e802f30d809f7 Mon Sep 17 00:00:00 2001 From: zgr2575 <62474113+zgr2575@users.noreply.github.com> Date: Fri, 19 Jul 2024 22:57:40 -0400 Subject: [PATCH 2/3] Update readme.md --- In Game Ranking/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/In Game Ranking/readme.md b/In Game Ranking/readme.md index aa3ea9d..58b5f60 100644 --- a/In Game Ranking/readme.md +++ b/In Game Ranking/readme.md @@ -15,11 +15,11 @@ local apiKey = '' -- Replace with your actual API key (The one set in the .env f local commandPrefix = "!" -- Set this to your desired command prefix ``` -And voula, you now have ranking commands! +And voila, you now have ranking commands! -For additional support open a ticket in Lengo Labs. +For additional support open a thread in qbot-help via the [discord server](https://discord.gg/ADQrmhVsPq). Created by: zgr2575 Last Updated: 7/19/2024 -Created: 7/19/2024 \ No newline at end of file +Created: 7/19/2024 From 59a0946d3b839fa6a1d61da5d21a2af04c284c82 Mon Sep 17 00:00:00 2001 From: zgr2575 <62474113+zgr2575@users.noreply.github.com> Date: Fri, 19 Jul 2024 23:14:38 -0400 Subject: [PATCH 3/3] Update roblox script.lua --- In Game Ranking/roblox script.lua | 234 ++++++++++++++++-------------- 1 file changed, 122 insertions(+), 112 deletions(-) diff --git a/In Game Ranking/roblox script.lua b/In Game Ranking/roblox script.lua index 82f4e95..ceac313 100644 --- a/In Game Ranking/roblox script.lua +++ b/In Game Ranking/roblox script.lua @@ -1,63 +1,102 @@ --[[ -Copyright 2024 zgr2575 +Created by zgr2575 -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +For any assistance create a thread in qbot help. +]] -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +local commandPrefix = "!" -- Set this to your desired command prefix +local groupId = 11717434 -- Set this to your desired group ID +local secretsEnabled = true -- If you're using secrets set this to true (Recommended) +local server = '' -- URL of your QBOT instance, e.g., http://iporhostname:3001/ -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +local secrets = { + apikey = '', -- Set this as the name of the secret holding your API key. +} -Join Us +local apiKey = '' -- Replace with your actual API key (secrets must be disabled) -Created by zgr2575, ping me in the server for support. -]]-- +-- Define command permissions +local commandPermissions = { + promote = {['Group Rank'] = 0, ['Tolerance Type'] = '>='}, + demote = {['Group Rank'] = 0, ['Tolerance Type'] = '>='}, + setrank = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + shout = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + fire = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + suspend = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + unsuspend = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + addxp = {['Group Rank'] = 255, ['Tolerance Type'] = '>='}, + removexp = {['Group Rank'] = 255, ['Tolerance Type'] = '>='} +} -local requiredRank = 255 -- Minimum rank allowed to use commands -local groupId = 11717434 -- Set this as your group ID -local server = '' -- URL of your QBOT instance EG: http::3001 -local apiKey = '' -- Replace with your actual API key -local commandPrefix = "!" -- Set this to your desired command prefix +--[[ + +End of Configuration + +Do not touch anything past this point unless you know what you're doing. + +]]-- local HttpService = game:GetService('HttpService') local Players = game:GetService('Players') -function slice(tbl, first, last, step) - local sliced = {} +-- Retrieve API key if secrets are enabled +if secretsEnabled then + local success, result = pcall(function() return HttpService:GetSecret(secrets.apikey) end) + if success then + apiKey = result + print("Successfully retrieved API key secret.") + else + warn("Failed to retrieve secret with key: " .. secrets.apiKey) + end +end - for i = first or 1, last or #tbl, step or 1 do - sliced[#sliced + 1] = tbl[i] +local function checkCommandPermission(player, command) + local perm = commandPermissions[command] + if not perm then return false end + + local playerRank = player:GetRankInGroup(groupId) + if perm['Tolerance Type'] == '>=' and playerRank >= perm['Group Rank'] then + return true + elseif perm['Tolerance Type'] == '<=' and playerRank <= perm['Group Rank'] then + return true + elseif perm['Tolerance Type'] == '==' and playerRank == perm['Group Rank'] then + return true end - return sliced + return false end local function postRequest(endpoint, data) local headers = { ["Content-Type"] = "application/json", - ["Authorization"] = apiKey + ["Authorization"] = apiKey } local options = { Url = server .. endpoint, Method = "POST", Headers = headers, - Body = HttpService:JSONEncode(data) + Body = HttpService:JSONEncode(data) -- Send data in JSON format } local success, response = pcall(function() - return HttpService:RequestAsync(options) end) if success then - print(success) - print(response) - return response + if response.Success then + print("Response Status Code: " .. response.StatusCode) + print("Response Body: " .. response.Body) + return response + else + warn("Request failed with status code: " .. response.StatusCode) + warn("Response Body: " .. response.Body) + end else warn("HTTP request failed: " .. tostring(response)) end end + local function getUserIdFromUsername(username) local success, result = pcall(function() - print(Players:GetUserIdFromNameAsync(username)) return Players:GetUserIdFromNameAsync(username) end) if success then @@ -68,6 +107,16 @@ local function getUserIdFromUsername(username) end end +-- Slice a table from a given start to end index +local function slice(tbl, first, last, step) + local sliced = {} + for i = first or 1, last or #tbl, step or 1 do + sliced[#sliced + 1] = tbl[i] + end + return sliced +end + +-- Handle player commands game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(msg) local args = msg:split(" ") @@ -76,101 +125,62 @@ game.Players.PlayerAdded:Connect(function(player) if command == commandPrefix then local cmd = args[1]:sub(#commandPrefix + 1) - if cmd == "setrank" then - local username = args[2] - local userId = getUserIdFromUsername(username) - local rank = slice(args, 3) - rank = table.concat(rank, ' ') - if userId and rank and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/setrank', { - id = userId, - role = rank - }) + if checkCommandPermission(player, cmd) then + if cmd == "setrank" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local rank = table.concat(slice(args, 3), ' ') + if userId and rank and userId ~= player.UserId then + postRequest('setrank', {id = userId, role = rank}) end - end - elseif cmd == "promote" then - local username = args[2] - local userId = getUserIdFromUsername(username) - if userId and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/promote', { - id = userId - }) + elseif cmd == "promote" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + postRequest('promote', {id = userId}) end - end - elseif cmd == "demote" then - local username = args[2] - local userId = getUserIdFromUsername(username) - if userId and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/demote', { - id = userId - }) + elseif cmd == "demote" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + postRequest('demote', {id = userId}) end - end - elseif cmd == "fire" then - local username = args[2] - local userId = getUserIdFromUsername(username) - if userId and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/fire', { - id = userId - }) + elseif cmd == "fire" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + postRequest('fire', {id = userId}) end - end - elseif cmd == "shout" then - table.remove(args, 1) - local msg = table.concat(args, ' ') - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/shout', { - content = msg - }) - end - elseif cmd == "suspend" then - local username = args[2] - local userId = getUserIdFromUsername(username) - local duration = tonumber(args[3]) - if userId and duration and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/suspend', { - id = userId, - duration = duration - }) + elseif cmd == "shout" then + table.remove(args, 1) + local message = table.concat(args, ' ') + postRequest('shout', {content = message}) + elseif cmd == "suspend" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local duration = tonumber(args[3]) + if userId and duration and userId ~= player.UserId then + postRequest('suspend', {id = userId, duration = duration}) end - end - elseif cmd == "unsuspend" then - local username = args[2] - local userId = getUserIdFromUsername(username) - if userId and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/unsuspend', { - id = userId - }) + elseif cmd == "unsuspend" then + local username = args[2] + local userId = getUserIdFromUsername(username) + if userId and userId ~= player.UserId then + postRequest('unsuspend', {id = userId}) end - end - elseif cmd == "addxp" then - local username = args[2] - local userId = getUserIdFromUsername(username) - local amount = tonumber(args[3]) - if userId and amount and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/xp/add', { - id = userId, - amount = amount - }) + elseif cmd == "addxp" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local amount = tonumber(args[3]) + if userId and amount and userId ~= player.UserId then + postRequest('xp/add', {id = userId, amount = amount}) end - end - elseif cmd == "removexp" then - local username = args[2] - local userId = getUserIdFromUsername(username) - local amount = tonumber(args[3]) - if userId and amount and userId ~= player.UserId then - if player:GetRankInGroup(groupId) >= requiredRank then - postRequest('/xp/remove', { - id = userId, - amount = amount - }) + elseif cmd == "removexp" then + local username = args[2] + local userId = getUserIdFromUsername(username) + local amount = tonumber(args[3]) + if userId and amount and userId ~= player.UserId then + postRequest('xp/remove', {id = userId, amount = amount}) end end end