marsy.js
Version:
Marsy.Live için tasarlanmış bir API yönetim uygulamasıdır. Bu modül ise kolay bir şekilde kullanımını sağlamaktadır.
103 lines (90 loc) • 3.38 kB
JavaScript
const fetch = require('node-fetch');
const { EventEmitter } = require('stream');
class Base extends EventEmitter {
constructor(client, {
license = null,
authorization = null,
ip = null,
test = null,
}) {
super();
this.license_key = license;
this.ip = ip;
this.test = test || false;
this.licenseChecked = false; // New flag to track if license is checked
if (!client) throw new Error("BaseClient bulunamadığı için işleme devam edilemiyor.");
if (authorization) this.authorization = authorization;
if (!this.license_key) throw new Error("Lisans Anahtarı Girilmediği İçin İstemci Başlatılamıyor.");
this.api_url = "https://api.marsy.live";
this.data = null;
this._rest = this;
}
/**
* @returns {String<IP>}
*/
get_check_ip() {
return fetch('https://api.marsy.live/@/status/check/ip')
.then(res => res.json())
.then(response => {
if(response.Status) {
this.ip = response.IP;
return this.check_license();
} else {
throw new Error("Marsy.Live'a bağlanılamadı için kullanım sağlayamazsınız.");
}
}).catch(err => {
this.emit("error", err);
});
}
check_license() {
return fetch(`${this.api_url}`, {
method: "GET",
headers: {
"Client-IP": this.ip,
"License-Key": this.license_key,
"Host-IP": this.ip,
"Authorization": `${this.test ? "Basic" : "Bearer"} ${this.test ? "=TestMarsyLive" : this.authorization ? this.authorization : "Marsy"}`,
"x-module-marsy": this.api_url,
"user-agent": "MarsyClient/1.0.0 (+API Hizmeti)"
}
})
.then(res => res.json())
.then(response => {
if (response.Status) {
this.data = response;
this.licenseChecked = true;
this.emit("ready", this);
return response;
} else {
console.error("Güncel IP Adresiniz: " + this.ip);
throw new Error(response.Message);
}
})
.catch(error => {
console.error("Hata:", error.message);
this.emit("error", this, error.message);
throw error;
});
}
_get(url, method) {
if (!this.licenseChecked) {
throw new Error("Bağlantı sağlanamadı veya sağlanmadan.");
}
return fetch(`${this.api_url}/${url}`, {
method: method || "GET",
headers: this.data?.Headers
}).then(res => res.json())
.then(response => {
if(response.Status) return response;
return null;
}).catch(error => {
console.error("Hata:", error.message);
this.emit("error", this, error.message);
throw error;
});
}
onReady() {
return this.get_check_ip();
}
}
module.exports = Base;