Alyssa

discord_discriminators

Jun 10th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import discord
  2. import json
  3. import math
  4. import os
  5. import requests
  6. import time
  7.  
  8. base = "https://discordapp.com/api"
  9. auth_path = "/root/Discord/bots/auths.json"
  10. master_path = "/root/Discord/master.txt"
  11.  
  12. #Tron
  13. with open(master_path, "r") as f:
  14.     auth = f.read()
  15.     headers = {"Authorization": auth}
  16. if not os.path.isfile(auth_path):
  17.     with open(auth_path, "x") as f:
  18.         f.write("[\n]")
  19.  
  20. with open(auth_path, "r") as f:
  21.     auths = json.loads( f.read() )
  22.  
  23. def get_members(guild):
  24.     time.sleep(1)
  25.     users = []
  26.     found = 1000
  27.     offset = 0
  28.     while found == 1000:
  29.         time.sleep(1)
  30.         print("Checking members " + str(offset) + " - " + str(offset + 1000) + " (?)")
  31.         print("Of guild: " + str(guild))
  32.         r = requests.get(base + "/guilds/" + str(guild) + "/members?limit=1000&offset=" + str(offset), headers = headers)
  33.         cur_list = json.loads(r.text)
  34.         found = len(cur_list)
  35.         for user in cur_list:
  36.             users.append(user)
  37.  
  38.         offset += 1000
  39.     return users
  40.  
  41. def get_me(headers):
  42.     r = requests.get(base + "/users/@me", headers = headers)
  43.     me = json.loads(r.text)
  44.     return me
  45.  
  46. def gen_discrim(my_names, user_list):
  47.     discrim = {}
  48.     for user in user_list:
  49.         if user["user"]["username"] not in my_names:
  50.             discrim[user["user"]["discriminator"]] = user["user"]["username"]
  51.     return discrim
  52.  
  53. def find_missing(discrim):
  54.     cur = 1
  55.     missing_num = 0
  56.     missing = []
  57.     while cur < 10000:
  58.         curd = str(cur).zfill(4)
  59.         try:
  60.             a = discrim[curd]
  61.         except KeyError:
  62.             missing_num += 1
  63.             missing.append(curd)
  64.         cur += 1
  65.     if missing_num < 200:
  66.         for miss in missing:
  67.             print("Missing: " + miss)
  68.     return missing
  69.  
  70. def get_guilds():
  71.     guilds = []
  72.     r = requests.get(base + "/users/@me/guilds", headers=headers)
  73.     guild_list = json.loads(r.text)
  74.     for guild in guild_list:
  75.         guilds.append(guild["id"])
  76.     return guilds
  77.  
  78. by_discrim = {}
  79. my_names = []
  80. for auth_token in auths:
  81.     me = get_me( { "Authorization": auth_token["auth"] } )
  82.     my_names.append(me["username"])
  83.  
  84. for name in my_names:
  85.     print("Added name " + name)
  86.  
  87. if False == True:
  88.     pass
  89. else:
  90.     guilds = get_guilds()
  91.     print("Guilds: " + str(guilds))
  92.     omniusers = []
  93.    
  94.     for guild in guilds:
  95.         print("Starting: " + guild)
  96.         cur_users = get_members(guild)
  97.         omniusers += cur_users
  98.        
  99.         by_discrim = gen_discrim(my_names, omniusers)
  100.        
  101.         missing = find_missing(by_discrim)
  102.         print("Missing: ")
  103.         print(str(missing))
  104.     with open("/root/Discord/disc.txt", "w") as f:
  105.      f.write(json.dumps(by_discrim))
Advertisement
Add Comment
Please, Sign In to add comment