small cleanup
This commit is contained in:
13
check.py
13
check.py
@@ -1,29 +1,33 @@
|
||||
import json
|
||||
import urllib2
|
||||
import datetime
|
||||
|
||||
from helpers import *
|
||||
|
||||
|
||||
# receive info based on the user's IP. information provided by ipinfo.io
|
||||
def ip_info(player):
|
||||
data = json.load(urllib2.urlopen("http://ipinfo.io%s/json" % str(player.getAddress().getAddress())))
|
||||
return data
|
||||
|
||||
|
||||
# receive first join date based on the player data (may not be accurate)
|
||||
def get_first_join(player):
|
||||
first_join = int(player.getFirstPlayed())
|
||||
dt = datetime.datetime.fromtimestamp(first_join/1000.0)
|
||||
return "%s-%s-%s %s:%s:%s" % (str(dt.year), str(dt.month), str(dt.day), str(dt.hour), str(dt.minute), str(dt.second))
|
||||
|
||||
|
||||
# receive country based on the user's IP
|
||||
def get_country(data):
|
||||
return str(data.get("country"))
|
||||
|
||||
|
||||
def get_all_names(player):
|
||||
uuid = str(player.getUniqueId()).replace("-", "")
|
||||
names = json.load(urllib2.urlopen("https://api.mojang.com/user/profiles/%s/names" % uuid))
|
||||
return ", ".join(names)
|
||||
|
||||
|
||||
# combines data
|
||||
def get_all_data(sender, player):
|
||||
data = ip_info(player)
|
||||
@@ -32,19 +36,18 @@ def get_all_data(sender, player):
|
||||
|
||||
try:
|
||||
msg(sender, "&7 -- Data provided by Redstoner")
|
||||
msg(sender, "&6> Unique User ID: &e%s" % str(player.getUniqueId()))
|
||||
msg(sender, "&6> UUID: &e%s" % str(player.getUniqueId()))
|
||||
msg(sender, "&6> First joined: &7(y-m-d h:m:s) &e%s" % get_first_join(player))
|
||||
msg(sender, "")
|
||||
msg(sender, "&7 -- Data provided by Mojang")
|
||||
msg(sender, "&6> Country: &e%s" % get_country(data))
|
||||
msg(sender, "&6> All ingame names used so far: &e%s" % get_all_names(player))
|
||||
except Exception as e:
|
||||
# can throw exceptions such as timeouts sometimes
|
||||
# can throw exceptions such as timeouts when Mojang API is down
|
||||
warn(e)
|
||||
|
||||
|
||||
|
||||
@hook.command("check", description="Displays useful stuff about a user", aliases="ck", usage="/check <player>")
|
||||
@hook.command("check", description="Displays useful stuff about a user", usage="/check <player>")
|
||||
def on_hook_command(sender, args):
|
||||
if sender.hasPermission("utils.check"):
|
||||
plugin_header(sender, "Check")
|
||||
|
||||
Reference in New Issue
Block a user