[英]How do I search through raw data for matching data?
Right now, I coded a function to go like this现在,我像这样将 function 编码为 go
async function checkPlayerScam(ign) {
const UUID = await getUUID(ign);
if(MATCHING){
playerIsScammer = true
}
else {
playerIsScammer = false
}
}
The MATCHING is just a placeholder at the moment. MATCHING 目前只是一个占位符。 I want to check their UUID, and make sure it isn't in this list: https://raw.githubusercontent.com/skyblockz/pricecheckbot/master/scammer.json
我想检查他们的 UUID,并确保它不在此列表中: https://raw.githubusercontent.com/skyblockz/pricecheckbot/master/scammer.json
Any idea how?知道怎么做吗? It needs to be relatively fast
它需要相对较快
EDIT: It'd also be cool if I could get the reason from the list, but that's not as necessary编辑:如果我能从列表中得到原因也很酷,但这不是必需的
https://lodash.com/docs/#find https://lodash.com/docs/#find
Use lodash _.find
to使用 lodash
_.find
来
const uuid = '000c97aaf948417a9a74d6858c01aaae'; // uuid you want to find
const scammer = _.find(scammersList, o => o.uuid === uuid);
if (scammer) { // if scammer found
console.log(scammer);
console.log(scammer.reason)
}
This function will fetch the data, then check if the uuid
1d0c0ef4295047b39f0fa899c485bd00
exists.这个 function 将获取数据,然后检查
uuid
1d0c0ef4295047b39f0fa899c485bd00
存在。 Assuming that you already fetched the data somewhere else and stored it, all you need to do is check if a given uuid
exists by adding the following line where you please:假设您已经在其他地方获取数据并将其存储,您需要做的就是通过在您喜欢的地方添加以下行来检查给定的
uuid
是否存在:
!!data[uuidToCheck]
uuidToCheck
should be the uuid
string that you are looking for. uuidToCheck
应该是您要查找的uuid
字符串。 This line will return true if the uuid
exists and false otherwise.如果
uuid
存在,此行将返回 true,否则返回 false。
In terms of the spacetime complexity, this function runs in constant time [O(1)] and O(N) space.就时空复杂度而言,这个 function 在恒定时间 [O(1)] 和 O(N) 空间中运行。 This is the fastest time you can get it to run.
这是您可以让它运行的最快时间。
data[uuidToCheck].reason
will return the reason. data[uuidToCheck].reason
将返回原因。
async function playerIsScammer(uuidToCheck) {
uuidToCheck = '1d0c0ef4295047b39f0fa899c485bd00';
const response = await fetch('https://raw.githubusercontent.com/skyblockz/pricecheckbot/master/scammer.json');
if (response.ok){
let data = await response.json();
if(!!data[uuidToCheck])
return data[uuidToCheck].reason;
return false
}
}
For anyone wondering, this is how I solved it:对于任何想知道的人,这就是我解决它的方法:
async function checkPlayerScam(ign) {
const UUID = await getUUID(ign);
const response = await fetch(`https://raw.githubusercontent.com/skyblockz/pricecheckbot/master/scammer.json`);
const result = await responsejson();
if (result[UUID] = null) {
playerIsScammer == False
}
else{
playerIsScammer == True
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.