Author Topic: Discord / Website ULX sync ranks?  (Read 184 times)

0 Members and 1 Guest are viewing this topic.

Offline KewlerGames

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Discord / Website ULX sync ranks?
« on: October 26, 2017, 05:30:27 PM »
So if it's possible I'm looking for something that if they get a rank it also gives it to them in discord and a mistfourm / Enjin website? I'm not sure if this is possible but I've never seen anyone even asking so here I am

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 691
  • Karma: 37
    • View Profile
    • iViscosity Gaming
Re: Discord / Website ULX sync ranks?
« Reply #1 on: October 26, 2017, 06:39:27 PM »
I'm not positive about syncing it to the website, but I know you can do it for Discord using their API.

You would need some way to identify the player on your Discord, though, as people may use different names. The way I do it on my test server is have a channel where people will post their Steam IDs (rather, a bot finds it for them using the Steam API), and periodically my script checks this channel's messages and looks for the ID (more information here). When it's able to find that, it compares that to the player's SteamID in-game, and then uses the Modify Guild Member call on them (which isn't completely supported at the moment because HTTP PATCH calls are currently unavailable on the main branch of gmod) to then edit their role.

Pseudo-code:
Code: Lua
  1. function findPlayer( ply )
  2.         -- Use the HTTP() function (http://wiki.garrysmod.com/page/Global/HTTP) to launch a
  3.         -- GET request to your server
  4.         HTTP( {
  5.                 failed = function() end, -- do something on failure, maybe let the server know we failed?
  6.                 success = function( cody, body, headers ) -- This is where we look through the messages
  7.                         local data = body and util.JSONToTable( body ) -- Discord returns in JSON,
  8.                                                                                              -- so we can access a table easily.
  9.                         -- Loop through the data, looking for the "content" tag (data[ i ].content)
  10.                                 -- If we find it, copy their ID (data[ i ].author.id)
  11.                                 -- If not, do something?
  12.                 end,
  13.                 method = "GET",         -- We're using an HTTP GET request, as specified by the
  14.                                                 -- Discord documentation
  15.                 url = "https://discordapp.com/api/channels/YOUR_CHANNEL_ID",    -- You can find the channel's ID by right-clicking the channel on the left and Copy ID (you may need to turn on Developer tools in User Settings)
  16.                 headers = {
  17.                         Authorization = "Bot YOUR_BOTS_CLIENT_ID" -- Discord mandates an authorization key in many HTTP requests, and if you're bot is authorized on your server, you can use it's ID. Note: You DO need to keep the leading "Bot" in there.
  18.                 }
  19.         } )
  20. end
  21.  
  22. -- Now we actually set the person's role
  23. function setRole( ply )
  24.         -- Now we want to use the HTTP() function, but with a PATCH request.
  25.         -- Keep in mind, PATCH is NOT integrated in the main build of gmod, so it will not work for the moment.
  26.         HTTP( {
  27.                 failed = function() end,
  28.                 success = function() end, -- Since we're not trying to do anything on our side, we can just notify the server if we succeed, or just do nothing.
  29.                 method = "PATCH", -- Again, not implemented currently.
  30.                 url = "https://discordapp.com/api/guilds/YOUR_GUILD_ID/members/THE_USERS_ID", -- The Guild ID can be found by right-clicking the server's name in the upper left and click Copy ID, and the user's ID was found earlier. You could return the user's ID in findPlayer() and set this to "https://discordapp.com/api/guilds/YOUR_GUILD_ID/members/" .. findPlayer( ply ) as well.
  31.                 headers = {
  32.                         Authorization = "Bot BOT_CLIENT_ID", -- Again, this is required.
  33.                         roles = util.TableToJSON( {
  34.                                 -- Fill this with the IDs of the roles you want to give. This can be found by doing '\@role name' in Discord. You want to copy the numbers inside the brackets and paste them in here.
  35.                         }
  36.                 }
  37.         } )
  38. end
  39.  

So, basically, it is POSSIBLE, just until the next update (says so) it is not, unless you use some third-party wrapper that allows PATCH requests.
« Last Edit: October 26, 2017, 06:58:41 PM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.

Offline KewlerGames

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: Discord / Website ULX sync ranks?
« Reply #2 on: October 26, 2017, 09:39:15 PM »
I didn't include this but I'm new to the whole server developing stuff and I'm confused on where to put this and how to do it, I don't want to be spammy so I'll just include it in this post, is there a screen grab as of right now that's working? If not could someone help me in creating one with some starting code from a old one

Offline monkeymacman

  • Newbie
  • *
  • Posts: 43
  • Karma: 12
    • View Profile
Re: Discord / Website ULX sync ranks?
« Reply #3 on: October 28, 2017, 09:10:26 PM »
I'm not positive about syncing it to the website, but I know you can do it for Discord using their API.

You would need some way to identify the player on your Discord, though, as people may use different names. The way I do it on my test server is have a channel where people will post their Steam IDs (rather, a bot finds it for them using the Steam API), and periodically my script checks this channel's messages and looks for the ID (more information here). When it's able to find that, it compares that to the player's SteamID in-game, and then uses the Modify Guild Member call on them (which isn't completely supported at the moment because HTTP PATCH calls are currently unavailable on the main branch of gmod) to then edit their role.

Pseudo-code:
Code: Lua
  1. function findPlayer( ply )
  2.    -- Use the HTTP() function (http://wiki.garrysmod.com/page/Global/HTTP) to launch a
  3.    -- GET request to your server
  4.    HTTP( {
  5.       failed = function() end, -- do something on failure, maybe let the server know we failed?
  6.       success = function( cody, body, headers ) -- This is where we look through the messages
  7.          local data = body and util.JSONToTable( body ) -- Discord returns in JSON,
  8.                                       -- so we can access a table easily.
  9.          -- Loop through the data, looking for the "content" tag (data[ i ].content)
  10.             -- If we find it, copy their ID (data[ i ].author.id)
  11.             -- If not, do something?
  12.       end,
  13.       method = "GET",    -- We're using an HTTP GET request, as specified by the
  14.                   -- Discord documentation
  15.       url = "https://discordapp.com/api/channels/YOUR_CHANNEL_ID",   -- You can find the channel's ID by right-clicking the channel on the left and Copy ID (you may need to turn on Developer tools in User Settings)
  16.       headers = {
  17.          Authorization = "Bot YOUR_BOTS_CLIENT_ID" -- Discord mandates an authorization key in many HTTP requests, and if you're bot is authorized on your server, you can use it's ID. Note: You DO need to keep the leading "Bot" in there.
  18.       }
  19.    } )
  20. end
  21.  
  22. -- Now we actually set the person's role
  23. function setRole( ply )
  24.    -- Now we want to use the HTTP() function, but with a PATCH request.
  25.    -- Keep in mind, PATCH is NOT integrated in the main build of gmod, so it will not work for the moment.
  26.    HTTP( {
  27.       failed = function() end,
  28.       success = function() end, -- Since we're not trying to do anything on our side, we can just notify the server if we succeed, or just do nothing.
  29.       method = "PATCH", -- Again, not implemented currently.
  30.       url = "https://discordapp.com/api/guilds/YOUR_GUILD_ID/members/THE_USERS_ID", -- The Guild ID can be found by right-clicking the server's name in the upper left and click Copy ID, and the user's ID was found earlier. You could return the user's ID in findPlayer() and set this to "https://discordapp.com/api/guilds/YOUR_GUILD_ID/members/" .. findPlayer( ply ) as well.
  31.       headers = {
  32.          Authorization = "Bot BOT_CLIENT_ID", -- Again, this is required.
  33.          roles = util.TableToJSON( {
  34.             -- Fill this with the IDs of the roles you want to give. This can be found by doing '\@role name' in Discord. You want to copy the numbers inside the brackets and paste them in here.
  35.          }
  36.       }
  37.    } )
  38. end
  39.  

So, basically, it is POSSIBLE, just until the next update (says so) it is not, unless you use some third-party wrapper that allows PATCH requests.
I assume you must verify that the ID is actually them at some point, right? Do they need to have their discord account linked to steam?

Offline iViscosity

  • Hero Member
  • *****
  • Posts: 691
  • Karma: 37
    • View Profile
    • iViscosity Gaming
Re: Discord / Website ULX sync ranks?
« Reply #4 on: October 28, 2017, 10:28:58 PM »
I assume you must verify that the ID is actually them at some point, right? Do they need to have their discord account linked to steam?
I actually thought of this after I posted this but forgot to edit it. Basically I changed it so now the player uses a command (such as !register or !verify, I use !register) and then they type in their Discord username. It isn't 100% perfect because of duplicate nicknames, but when the script identifies them, it uses an HTTP DELETE request to delete that message, so it can only be requested once.

EDIT: Another idea, you could use the author's ID that you collect to file.Write that person into a file that tracks IDs, if that author's ID (which is unique to everyone) is already found, it would be ignored.
« Last Edit: October 28, 2017, 10:31:45 PM by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Forums
Public Discord
Teamspeak

Quote from: Steve Jobs
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle.