ULX

Author Topic: Capturing String Argument (ULX Command Hook)  (Read 460 times)

0 Members and 1 Guest are viewing this topic.

Offline Fobro879

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Capturing String Argument (ULX Command Hook)
« on: December 08, 2020, 12:25:10 PM »
Okay, so I am making a discord-gmod synchronization addon with MySQL. I have literally everything working except for one ULX parameter hook

So, here is the code that matters:

Code: [Select]
--Inroduces the function
function ulx.linkdiscord( calling_ply, discord )

--Sanitization module
function input_laundry(source)
source.gsub(source, ";", "ILLEGAL") -- sanitizes ; kill value for SQL
source.gsub(source, '"', "ILLEGAL") -- sanitizes general " for both
source.gsub(source, "'", "ILLEGAL") -- sanitizes general ' for both
end

--Info grab
local player_ulx_group = calling_ply:GetUserGroup() --grabs player ulx grouop (string v)
local player_playerid = tostring(calling_ply); input_laundry(player_playerid);  -- sanitized username input
local player_discordid = tostring(discord); input_laundry(player_discordid); -- sanitized discordID input
local player_steam_id = calling_ply:SteamID() --grabs steam ID
local player_verify_key = tostring(randomizedoutput) --grabs the player's specific and uniquely generated ID

--ULX Config
local CATEGORY_NAME = "Discord"
local linkdiscord = ulx.command( CATEGORY_NAME, "ulx linkdiscord", ulx.linkdiscord, "!linkdiscord", true )
linkdiscord:addParam{ type=ULib.cmds.CallingPlayerArg } -- First param to the function is the player running the command
linkdiscord:addParam{ type=ULib.cmds.StringArg, hint="discord", ULib.cmds.takeRestOfLine } -- Second param to the function is discord ID string
linkdiscord:defaultAccess( ULib.ACCESS_ALL )
linkdiscord:help( "Links your steam account to discord ID" )

My issue is that when I try and call the 'discord' string parameter, it doesn't translate as a string but defaults to user data (i.e. "Player [1][steam_name]"

I want people to do "!linkdiscord [discordID]" so that I can send the discordID to SQL for matching from the bot
« Last Edit: December 08, 2020, 12:27:47 PM by Fobro879 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8082
  • Karma: 389
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Capturing String Argument (ULX Command Hook)
« Reply #1 on: December 08, 2020, 07:32:21 PM »
'calling_ply' is always passed without the function needing to add it as a parameter - therefore, you're passing calling_ply twice to the function.
Basically, your_function(calling_ply, discord) becomes your_function(calling_ply, discord=calling_ply) because of this line.
Code: [Select]
linkdiscord:addParam{ type=ULib.cmds.CallingPlayerArg } -- First param to the function is the player running the command
That's the second parameter, not the first.
ulx.command already passes calling_ply as first.

Quick reference is the ulx map command. Calling_ply is called, then we add string map name as second param.
https://github.com/TeamUlysses/ulx/blob/a8b31ffb3ec6ae1e7bbcea35019312d1b2ca52e1/lua/ulx/modules/sh/util.lua#L47
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming