Created
May 7, 2018 16:02
-
-
Save 0x263b/27a1d37c1286b07e9d095659a3249b8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
Encoding.default_external = "UTF-8" | |
Encoding.default_internal = "UTF-8" | |
require "open-uri" | |
require "json" | |
GUILD = "" # Server ID | |
CHANNEL = "" # A Channel ID for the server, doesn't matter which | |
TOKEN = "" # My API Token | |
COOKIE = "" # My Cookie | |
REFERER = "https://discordapp.com/channels/#{GUILD}/#{CHANNEL}" | |
@member_list = [] | |
more = true | |
offset = "" | |
while more == true do # Loop through search result pages | |
begin | |
data = open("https://discordapp.com/api/v6/guilds/#{GUILD}/members?limit=1000#{offset}", | |
"Authorization" => TOKEN, | |
"Cookie" => COOKIE).read | |
data = JSON.parse(data) | |
@member_list << data | |
if data.length == 1000 | |
offset = "&after=#{data.last["user"]["id"]}" | |
else | |
more = false | |
end | |
rescue | |
more = false | |
end | |
end | |
@member_list.flatten!.uniq! | |
# Save the basic member list as backup | |
File.write("#{File.expand_path(File.dirname(__FILE__))}/member_list-#{GUILD}.json", JSON.pretty_generate(@member_list)) | |
# Loop through each member and look up their profile | |
# This gives the mutual server list and linked accounts | |
@member_list.each do |user| | |
begin | |
data = open("https://discordapp.com/api/v6/users/#{user["user"]["id"]}/profile", | |
"Authorization" => TOKEN, | |
"Cookie" => COOKIE, | |
"Referer" => REFERER).read | |
data = JSON.parse(data) | |
user["mutual_guilds"] = data["mutual_guilds"] | |
user["connected_accounts"] = data["connected_accounts"] | |
sleep 0.5 # Sleep to avoid Rate Limit | |
rescue OpenURI::HTTPError => err | |
puts "Error: #{user["user"]["id"]} (#{err.message})" | |
end | |
end | |
# Save the expanded list | |
File.write("#{File.expand_path(File.dirname(__FILE__))}/member_list_expanded-#{GUILD}.json", JSON.pretty_generate(@member_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment