raspdevpy / ccdoc

Custom Command Documentation Repo
8 stars 56 forks source link

Stored UserID and RoleID variables have whitespaces #8

Closed Xruptor closed 2 years ago

Xruptor commented 2 years ago

There is currently an issue where storing any roleID or userID has beginning and trailing whitespaces in the variable. This causes an error for functions such as $hasRoles.

Example

assume the following: x_Usr = 50000000000 x_Visitor= 70000000000 x_FCMember= 90000000000

Using this code:


$onlyIf[$mentioned[1]!=;Requires @usermention for second parameter.]

$let[x_Usr; $mentioned[1] ]
$let[x_Visitor; $roleID[Visitors] ]
$let[x_FCMember; $roleID[FC Members] ]

test$x_Usr
test$x_Visitor
test$x_FCMember

$hasRoles[$x_Usr;$x_Visitor]

 /* Lets remove the white spaces from the variables, because it adds it to the front and end */

testme$replaceTextWithRegex[$x_Usr;\s;gi;]

$hasRoles[$replaceTextWithRegex[$x_Usr;\s;gi;];$replaceTextWithRegex[$x_Visitor;\s;gi;]]

The following block:

test$x_Usr
test$x_Visitor
test$x_FCMember

will return the following:

test 50000000000
test 70000000000
test 90000000000

The following code: $hasRoles[$x_Usr;$x_Visitor]

Will return the error :x: Invalid user ID in $hasRoles[ 50000000000 ; 70000000000 ] Because there are white spaces in the front and end of the variables.

In order to get around this you have to remove the white spaces. testme$replaceTextWithRegex[$x_Usr;\s;gi;] Will return testme50000000000 with no whitespaces.

That means in order to properly use the $hasRoles function you have to do it like this $hasRoles[$replaceTextWithRegex[$x_Usr;\s;gi;];$replaceTextWithRegex[$x_Visitor;\s;gi;]]

Suggestion: 1) You can have the $hasRoles ignore whitespaces 2) put a $trim function to remove whitespaces from variables such as $trim[$x_Usr] 3) you can make variable returns using $variable or $get not return with whitespaces in the front or back using an optional variable. $get[x_Visitor;yes] where yes would be to trim whitespaces

MIRAYWIKI commented 2 years ago

hello Xruptor. About the spaces, isn't an issue, you created them on purpose, just look at yours vars, there are whitespaces that were created by you. Screenshot_20220225141920

Xruptor commented 2 years ago

hello Xruptor. About the spaces, isn't an issue, you created them on purpose, just look at yours vars, there are whitespaces that were created by you. Screenshot_20220225141920

I normally space out code so its easier to read. I didn't think that would play a major role as part of the assignment. Thanks,

raspdevpy commented 2 years ago

For future issues , suggestions or any type of help. We recommend to join our discord server https://ccommandbot.com/join