Download dist/controllers/tagController.js from ItsMa8di/idbot: direct link, hf CLI and curl.
- Browser
- Download file 8.95 kB
-
https://huggingface.co/spaces/ItsMa8di/idbot/resolve/main/dist/controllers/tagController.js
- Command line
-
hf download hf://spaces/ItsMa8di/idbot/dist/controllers/tagController.js
-
curl -L -o tagController.js https://huggingface.co/spaces/ItsMa8di/idbot/resolve/main/dist/controllers/tagController.js
8.95 kB
| ; | |
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | |
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | |
| return new (P || (P = Promise))(function (resolve, reject) { | |
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | |
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | |
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | |
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | |
| }); | |
| }; | |
| var __importDefault = (this && this.__importDefault) || function (mod) { | |
| return (mod && mod.__esModule) ? mod : { "default": mod }; | |
| }; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| const playerSevices_1 = __importDefault(require("../services/playerSevices")); | |
| const playerToString_1 = __importDefault(require("../utils/playerToString")); | |
| const tagValidator_1 = __importDefault(require("../utils/tagValidator")); | |
| const userController_1 = require("./userController"); | |
| class TagController { | |
| static sendTutorial(ctx) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| var _a; | |
| try { | |
| const messageId = (_a = ctx.message) === null || _a === void 0 ? void 0 : _a.message_id; | |
| if (!messageId) | |
| return; | |
| const sentTutorial = yield ctx.reply(`برای استفاده از ربات به صورت زیر عمل کنید:\n\nid <#ABC123>\n\nتگ خود را به صورت درست وارد کنید و صبور باشید.\nتگ شما در قسمت پروفایل اکانت قابل مشاهده می باشد\nمیخوای تگ اکانتت رو ذخیره کنی تا هر دفعه نخوای بنویسی؟؟\nبا کامند زیر این کار انجام میشه:\n\nid #ABC123 save\nبه جای تگ پیشفرض تگ اکانت خودتو بنویس و بعدش هم کلمه ی "save" رو بنویس.\n\nاگر هم میخوای اکانتی که سیو کردی رو ببینی کامند زیر رو بفرست\nme$ یا account$\n\nبرای حذف کردن اکانتی که سیو کردی از این کامند استفاده کن:\nme$ remove یا account$ remove`, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| setTimeout(() => { | |
| var _a; | |
| ctx.api.deleteMessage((_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.id, sentTutorial.message_id); | |
| ctx.deleteMessage(); | |
| }, 2000); | |
| } | |
| catch (error) { | |
| console.error(error); | |
| //ctx.reply(`یک خطای غیر منتظره رخ داد`) | |
| return; | |
| } | |
| }); | |
| } | |
| static errorHandler(ctx, error) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| var _a; | |
| try { | |
| const messageId = (_a = ctx.message) === null || _a === void 0 ? void 0 : _a.message_id; | |
| if (!messageId) | |
| return; | |
| const status = error.status; | |
| switch (status) { | |
| case 404: | |
| ctx.reply(`اکانت مورد نظر یافت نشد`, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| return; | |
| default: | |
| ctx.reply(`یک خطای داخلی رخ داد`, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| } | |
| } | |
| catch (error) { | |
| console.error(error); | |
| return; | |
| } | |
| }); | |
| } | |
| static fetch(ctx, tag) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| var _a; | |
| try { | |
| const messageId = (_a = ctx.message) === null || _a === void 0 ? void 0 : _a.message_id; | |
| if (!messageId) | |
| return; | |
| const response = yield playerSevices_1.default.fetch(tag); | |
| if ("error" in response) { | |
| this.errorHandler(ctx, response); | |
| return; | |
| } | |
| const toString = (0, playerToString_1.default)(response); | |
| ctx.reply(toString, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| } | |
| catch (error) { | |
| console.error(error); | |
| return; | |
| } | |
| }); | |
| } | |
| static checkTag(ctx, tag) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| var _a, _b; | |
| try { | |
| const text = (_a = ctx.message) === null || _a === void 0 ? void 0 : _a.text; | |
| const trimedText = tag === null || tag === void 0 ? void 0 : tag.trim().replace("#", "").replace(/o/g, "0"); | |
| const messageId = (_b = ctx.message) === null || _b === void 0 ? void 0 : _b.message_id; | |
| if (!messageId) | |
| return; | |
| if (!trimedText) | |
| return; | |
| const isValidTag = (0, tagValidator_1.default)(trimedText); | |
| if (!isValidTag) { | |
| const sentError = yield ctx.reply(`کاربر گرامی تگ ارسالی معتبر نمی باشد.\n\nتگ ارسالی حتما باید حروف انگلیسی باشد.\nنکته: تگ شما در قسمت پروفایل قابل مشاهده می باشد.`, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| setTimeout(() => { | |
| var _a; | |
| ctx.api.deleteMessage((_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.id, sentError.message_id); | |
| ctx.deleteMessage(); | |
| }, 2000); | |
| return; | |
| } | |
| ctx.session.nextTime = Date.now() + 60 * 1000; | |
| tag && this.fetch(ctx, tag); | |
| } | |
| catch (error) { | |
| console.error(error); | |
| return; | |
| } | |
| }); | |
| } | |
| static saveTag(ctx, userid, tag) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| var _a; | |
| try { | |
| const trimedText = tag.replace("#", "").replace(/o/g, "0").trim(); | |
| const messageId = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.message) === null || _a === void 0 ? void 0 : _a.message_id; | |
| if (!messageId) | |
| return; | |
| const isValidTag = (0, tagValidator_1.default)(trimedText); | |
| if (!isValidTag) { | |
| const sentError = yield ctx.reply(`کاربر گرامی تگ ارسالی معتبر نمی باشد.\n\nتگ ارسالی حتما باید حروف انگلیسی باشد.\nنکته: تگ شما در قسمت پروفایل قابل مشاهده می باشد.`, { | |
| reply_parameters: { | |
| message_id: messageId, | |
| }, | |
| }); | |
| setTimeout(() => { | |
| var _a; | |
| ctx.api.deleteMessage((_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.id, sentError.message_id); | |
| ctx.deleteMessage(); | |
| }, 2000); | |
| return; | |
| } | |
| ctx.session.nextTime = Date.now() + 60 * 1000; | |
| //TODO : SAVE THE TAG TO USER | |
| // | |
| const user = yield userController_1.UserController.getByUserid(userid); | |
| console.log(user); | |
| if (user) { | |
| const updatedUser = Object.assign(Object.assign({}, user), { savedAccountTag: trimedText }); | |
| yield userController_1.UserController.updateByUserid(userid, updatedUser); | |
| yield ctx.reply(`اکانت شما با موفقیت ذخیره شد\n${trimedText}`, { | |
| reply_parameters: { message_id: ctx.msgId }, | |
| }); | |
| // SEND MESSAGE | |
| //tag && this.fetch(ctx, trimedText); | |
| } | |
| } | |
| catch (e) { | |
| console.error(e); | |
| return; | |
| } | |
| }); | |
| } | |
| } | |
| exports.default = TagController; | |