Skip to content

Commit 697d0ec

Browse files
committed
Updating to TS, with some errors hah
1 parent f89896e commit 697d0ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1560
-1113
lines changed

..gitignore.swp

1 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
package-lock.json
2+
package-lock.json
3+
*.js
4+

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
2-
module.exports.A = ()=> {console.log("a")}
3-
module.exports.Client = require("./src/Client")
4-
module.exports.Routes = require("./src/routes/Routes")
5-
module.exports.Auth = require("./src/Auth")
6-
module.exports.route = require("./src/route")
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.Client = exports.A = void 0;
4+
var A = function () { console.log("a"); };
5+
exports.A = A;
6+
var Client_1 = require("./src/Client");
7+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return Client_1.default; } });

index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export const A = () => { console.log("a"); };
3+
export { default as Client } from "./src/Client";

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "An interactor for AnyBot-API",
55
"main": "index.js",
66
"scripts": {
7-
"test": "node test.js"
7+
"dev": "nodemon --exec ts-node index.ts",
8+
"test": "nodemon --exec ts-node test.ts",
9+
"build": "tsc index.ts"
810
},
911
"repository": {
1012
"type": "git",
@@ -19,7 +21,12 @@
1921
"dependencies": {
2022
"axios": "^1.3.4"
2123
},
22-
"devDependencies": {},
24+
"devDependencies": {
25+
"@types/node": "^20.10.5",
26+
"nodemon": "^3.0.2",
27+
"ts-node": "^10.9.2",
28+
"typescript": "^5.3.3"
29+
},
2330
"keywords": [
2431
"anybot",
2532
"anyapi",

src/Auth.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Client.js

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,23 @@
1-
2-
const Auth = require("./Auth");
3-
const route = require("./route");
4-
const Error = require("./utils/Error");
5-
const Routes = require("./routes/Routes")
6-
7-
8-
const Utils = require("./routes/definers/Utils");
9-
const Animals = require("./routes/definers/Animals");
10-
const Anime = require("./routes/definers/Anime");
11-
/**
12-
* Im dumb djslkajdkl
13-
*/
14-
const API_KEY = String
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var Auth_1 = require("./iteractors/Auth");
4+
var Routes_1 = require("./routes/Routes");
155
/**
166
* AnyAPI client
177
*/
18-
class Client {
19-
/**
20-
* AnyApi Client
21-
*
22-
* @param {{api_key: string}} settings
23-
*/
24-
constructor(settings)
25-
{
26-
if (!settings)
8+
var Client = /** @class */ (function () {
9+
function Client(settings) {
10+
if (!settings)
2711
settings = {
2812
api_key: undefined,
29-
}
30-
/**
31-
* used for some routes.
32-
*
33-
* @type {API_KEY}
34-
* @readonly
35-
*/
36-
this.api_key = settings.api_key
37-
38-
/**
39-
* Authenticator for AnyAPI
40-
*
41-
* @type {Auth}
42-
* @readonly
43-
*/
44-
this.auth = new Auth(settings);
45-
if (!this.api_key)
46-
console.warn("The key as:", this.api_key, "is not a valid api key.\nIf you don't have an API_KEY you can get one here: http://api.any-bot.xyz/get-apikey\nTo see the documentation enter in: https://docs.api.any-bot.xyz/")
47-
48-
/**
49-
* All the routes of AnyAPI
50-
* @type {Routes}
51-
*/
52-
this.routes = new Routes(this.auth)
53-
/**
54-
* Anime class, with the routes.
55-
* @type {Anime}
56-
*/
57-
this.anime = this.routes.anime
58-
/**
59-
* Utils class, with the routes.
60-
* @type {Utils}
61-
*/
62-
this.utils = this.routes.utils
63-
/**
64-
* Utils class, with the routes.
65-
* @type {Animals}
66-
*/
67-
this.animals = this.routes.animals
68-
13+
};
14+
this.api_key = settings.api_key;
15+
this.auth = new Auth_1.default(settings);
16+
this.routes = new Routes_1.default(this.auth);
17+
this.anime = this.routes.anime;
18+
this.utils = this.routes.utils;
19+
this.animals = this.routes.animals;
6920
}
70-
}
71-
72-
module.exports = Client
21+
return Client;
22+
}());
23+
exports.default = Client;

src/Client.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
import Auth from "./iteractors/Auth";
3+
4+
import Animals from "./routes/sections/Animals";
5+
import Anime from "./routes/sections/Anime";
6+
import Utils from "./routes/sections/Utils";
7+
8+
import Routes from "./routes/Routes"
9+
10+
import { ApiAuth } from "./utils/Interfaces";
11+
12+
/**
13+
* AnyAPI client
14+
*/
15+
export default class Client {
16+
17+
readonly api_key: string | undefined;
18+
readonly auth: Auth;
19+
readonly routes: Routes;
20+
readonly anime: Anime;
21+
readonly utils: Utils;
22+
readonly animals: Animals;
23+
24+
constructor(settings: ApiAuth)
25+
{
26+
if (!settings)
27+
settings = {
28+
api_key: undefined,
29+
}
30+
31+
this.api_key = settings.api_key
32+
33+
34+
this.auth = new Auth(settings);
35+
36+
37+
this.routes = new Routes (this.auth)
38+
39+
this.anime = this.routes.anime
40+
this.utils = this.routes.utils
41+
this.animals = this.routes.animals
42+
43+
}
44+
}

src/iteractors/Auth.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// TODO: Authenticator better login system
2+
import {ApiAuth} from "../utils/Interfaces";
3+
export default class Auth
4+
{
5+
readonly api_key: string | undefined;
6+
7+
constructor(settings: ApiAuth )
8+
{
9+
10+
this.api_key = settings.api_key
11+
}
12+
/**
13+
* @returns {string} API_KEY
14+
* @readonly
15+
*/
16+
get_api_key()
17+
{
18+
return this.api_key;
19+
}
20+
}

src/iteractors/Route.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { RouteData } from "../utils/Interfaces"
2+
import axios, { AxiosHeaders } from "axios"
3+
import Error from "../utils/Error"
4+
export default class Route {
5+
name: string
6+
route: string
7+
apikey: string | undefined;
8+
constructor(options:RouteData)
9+
{
10+
this.name = options.name
11+
this.apikey = options.apiKey
12+
this.route = options.route
13+
14+
15+
}
16+
async GET(...query:Array<Array<string>>):Promise<any | undefined>{
17+
const q:Array<string> = [];
18+
query.forEach(data=>{
19+
q.push(data.join("="))
20+
})
21+
const response =await axios
22+
.get(`https://api.any-bot.xyz/api/v1/${this.route}${q.length > 0 ? `?${q.join("&")}` : ``}`)
23+
.then((res) => res.data)
24+
.catch((err) => {
25+
console.log(err)
26+
return new Error("The API is down", "BID")
27+
});
28+
return response
29+
}
30+
async POST(...query:Array<Array<string>>):Promise<any | undefined> {
31+
if (!this.apikey) {
32+
console.warn("The key as:", this.apikey, "is not a valid api key.\nIf you don't have an API_KEY you can get one here: http://api.any-bot.xyz/get-apikey \n\nTo see the documentation enter in: https://docs.api.any-bot.xyz/")
33+
return;
34+
}
35+
const q:Array<string> = [];
36+
query.forEach(data=>{
37+
q.push(data.join("="))
38+
})
39+
40+
const response =await axios
41+
.post(
42+
`https://api.any-bot.xyz/api/v1/${this.route}${q.length > 0 ? `?${q.join("&")}` : ``}`,
43+
undefined,
44+
{
45+
headers: new AxiosHeaders(JSON.stringify( {
46+
API_KEY: this.apikey,
47+
},))
48+
}
49+
)
50+
.then(async (res:any) => {
51+
return res;
52+
})
53+
.catch(async () => {
54+
return new Error("Bad api response: the api is down", "AID");
55+
});
56+
}
57+
58+
}

0 commit comments

Comments
 (0)