millswelbeck148/SireimadeBotPublic · Bot Template

AISireImade appears to be a Telegram automation bot. Commands include /start, /about, /support, /id, /admin, /ban, /unban, /x. Observed in code: messaging, keyboards, games.

Utilityutility
ProfileTelegram
112 commands3 envUpdated 2h agoCreated Aug 27, 2026
Back to folder

commands/_gift_database.js

javascript · 943 lines

Raw
1/**#command2name: /gift_database3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// ==========================================================13// 💜 GIFT AI — AUTOMATIC USER + GROUP DATABASE14// + ACTIVITY TRACKER15// ==========================================================16//17// Automatically saves:18//19// 👤 USERS20// • Telegram ID21// • First name22// • Last name23// • Username24// • First seen25// • Last seen26// • Interaction count27// • Message count28// • Groups interacted with29//30// 👥 GROUPS31// • Chat ID32// • Group name33// • Username34// • Chat type35// • First seen36// • Last seen37// • Interaction count38// • Message count39//40// DATABASE KEYS:41//42// GIFT_USERS_DATABASE43// GIFT_GROUPS_DATABASE44//45// Safe • Duplicate-free • Automatic46// Compatible with /trace + /legacy47// ==========================================================48 49 50// ==========================================================51// GET USER DATA52// ==========================================================53 54var dbUserId = "";55var dbFirstName = "";56var dbLastName = "";57var dbUsername = "";58 59try {60 61  if (62    request &&63    request.from &&64    request.from.id !== undefined65  ) {66 67    dbUserId =68      String(69        request.from.id70      );71 72  }73 74} catch (e) {}75 76 77try {78 79  if (80    request &&81    request.from &&82    request.from.first_name83  ) {84 85    dbFirstName =86      String(87        request.from.first_name88      );89 90  }91 92} catch (e) {}93 94 95try {96 97  if (98    request &&99    request.from &&100    request.from.last_name101  ) {102 103    dbLastName =104      String(105        request.from.last_name106      );107 108  }109 110} catch (e) {}111 112 113try {114 115  if (116    request &&117    request.from &&118    request.from.username119  ) {120 121    dbUsername =122      String(123        request.from.username124      );125 126  }127 128} catch (e) {}129 130 131// ==========================================================132// FALLBACK USER OBJECT133// ==========================================================134 135if (!dbUserId) {136 137  try {138 139    if (140      user &&141      user.telegramid !== undefined142    ) {143 144      dbUserId =145        String(146          user.telegramid147        );148 149    }150 151  } catch (e) {}152 153}154 155 156if (!dbFirstName) {157 158  try {159 160    if (161      user &&162      user.first_name163    ) {164 165      dbFirstName =166        String(167          user.first_name168        );169 170    }171 172  } catch (e) {}173 174}175 176 177if (!dbLastName) {178 179  try {180 181    if (182      user &&183      user.last_name184    ) {185 186      dbLastName =187        String(188          user.last_name189        );190 191    }192 193  } catch (e) {}194 195}196 197 198if (!dbUsername) {199 200  try {201 202    if (203      user &&204      user.username205    ) {206 207      dbUsername =208        String(209          user.username210        );211 212    }213 214  } catch (e) {}215 216}217 218 219// ==========================================================220// GET CHAT DATA221// ==========================================================222 223var dbChatId = "";224var dbChatType = "";225var dbChatTitle = "";226var dbChatUsername = "";227 228try {229 230  if (231    request &&232    request.chat233  ) {234 235    if (236      request.chat.id !== undefined237    ) {238 239      dbChatId =240        String(241          request.chat.id242        );243 244    }245 246 247    if (248      request.chat.type249    ) {250 251      dbChatType =252        String(253          request.chat.type254        );255 256    }257 258 259    if (260      request.chat.title261    ) {262 263      dbChatTitle =264        String(265          request.chat.title266        );267 268    }269 270 271    if (272      request.chat.username273    ) {274 275      dbChatUsername =276        String(277          request.chat.username278        );279 280    }281 282  }283 284} catch (e) {}285 286 287// ==========================================================288// FALLBACK CHAT OBJECT289// ==========================================================290 291if (!dbChatId) {292 293  try {294 295    if (296      chat &&297      chat.id !== undefined298    ) {299 300      dbChatId =301        String(302          chat.id303        );304 305    }306 307  } catch (e) {}308 309}310 311 312if (!dbChatType) {313 314  try {315 316    if (317      chat &&318      chat.type319    ) {320 321      dbChatType =322        String(323          chat.type324        );325 326    }327 328  } catch (e) {}329 330}331 332 333if (!dbChatTitle) {334 335  try {336 337    if (338      chat &&339      chat.title340    ) {341 342      dbChatTitle =343        String(344          chat.title345        );346 347    }348 349  } catch (e) {}350 351}352 353 354if (!dbChatUsername) {355 356  try {357 358    if (359      chat &&360      chat.username361    ) {362 363      dbChatUsername =364        String(365          chat.username366        );367 368    }369 370  } catch (e) {}371 372}373 374 375// ==========================================================376// CURRENT TIME377// ==========================================================378 379var now =380  new Date().toISOString();381 382 383// ==========================================================384// DETERMINE IF THIS IS A REAL MESSAGE385// ==========================================================386//387// Commands and ordinary messages both count as activity.388// The tracker runs whenever this database collector runs.389// ==========================================================390 391var isActivity =392  true;393 394 395// ==========================================================396// SAVE USER397// ==========================================================398 399if (400  dbUserId401) {402 403  try {404 405    var users =406      Bot.getProperty(407        "GIFT_USERS_DATABASE"408      );409 410 411    if (412      !Array.isArray(users)413    ) {414 415      users = [];416 417    }418 419 420    var existingUser =421      null;422 423 424    var existingUserIndex =425      -1;426 427 428    // ------------------------------------------------------429    // FIND USER430    // ------------------------------------------------------431 432    for (433      var i = 0;434      i < users.length;435      i++436    ) {437 438      if (439        String(440          users[i].id441        ) ===442        String(443          dbUserId444        )445      ) {446 447        existingUser =448          users[i];449 450        existingUserIndex =451          i;452 453        break;454 455      }456 457    }458 459 460    // ------------------------------------------------------461    // NEW USER462    // ------------------------------------------------------463 464    if (!existingUser) {465 466      existingUser = {467 468        id:469          dbUserId,470 471        first_name:472          dbFirstName || "Unknown",473 474        last_name:475          dbLastName || "",476 477        username:478          dbUsername || "",479 480        first_seen:481          now,482 483        last_seen:484          now,485 486        interactions:487          1,488 489        messages:490          1,491 492        groups:493          []494 495      };496 497 498      // ----------------------------------------------------499      // SAVE CURRENT GROUP500      // ----------------------------------------------------501 502      if (503        dbChatId &&504        (505          dbChatType === "group" ||506          dbChatType === "supergroup"507        )508      ) {509 510        existingUser.groups.push({511 512          id:513            dbChatId,514 515          title:516            dbChatTitle || "Unknown Group",517 518          username:519            dbChatUsername || "",520 521          first_seen:522            now,523 524          last_seen:525            now,526 527          messages:528            1529 530        });531 532      }533 534 535      users.push(536        existingUser537      );538 539    }540 541 542    // ------------------------------------------------------543    // EXISTING USER544    // ------------------------------------------------------545 546    else {547 548      // ----------------------------------------------------549      // UPDATE NAME550      // ----------------------------------------------------551 552      if (553        dbFirstName554      ) {555 556        existingUser.first_name =557          dbFirstName;558 559      }560 561 562      if (563        dbLastName564      ) {565 566        existingUser.last_name =567          dbLastName;568 569      }570 571 572      if (573        dbUsername574      ) {575 576        existingUser.username =577          dbUsername;578 579      }580 581 582      // ----------------------------------------------------583      // LAST SEEN584      // ----------------------------------------------------585 586      existingUser.last_seen =587        now;588 589 590      // ----------------------------------------------------591      // INTERACTIONS592      // ----------------------------------------------------593 594      existingUser.interactions =595        Number(596          existingUser.interactions || 0597        ) + 1;598 599 600      // ----------------------------------------------------601      // MESSAGE COUNT602      // ----------------------------------------------------603 604      existingUser.messages =605        Number(606          existingUser.messages || 0607        ) + 1;608 609 610      // ----------------------------------------------------611      // GROUP HISTORY612      // ----------------------------------------------------613 614      if (615        dbChatId &&616        (617          dbChatType === "group" ||618          dbChatType === "supergroup"619        )620      ) {621 622        if (623          !Array.isArray(624            existingUser.groups625          )626        ) {627 628          existingUser.groups = [];629 630        }631 632 633        var userGroup =634          null;635 636 637        // --------------------------------------------------638        // FIND GROUP IN USER HISTORY639        // --------------------------------------------------640 641        for (642          var ug = 0;643          ug < existingUser.groups.length;644          ug++645        ) {646 647          if (648            String(649              existingUser.groups[ug].id650            ) ===651            String(652              dbChatId653            )654          ) {655 656            userGroup =657              existingUser.groups[ug];658 659            break;660 661          }662 663        }664 665 666        // --------------------------------------------------667        // NEW GROUP FOR USER668        // --------------------------------------------------669 670        if (!userGroup) {671 672          existingUser.groups.push({673 674            id:675              dbChatId,676 677            title:678              dbChatTitle || "Unknown Group",679 680            username:681              dbChatUsername || "",682 683            first_seen:684              now,685 686            last_seen:687              now,688 689            messages:690              1691 692          });693 694        }695 696 697        // --------------------------------------------------698        // EXISTING GROUP FOR USER699        // --------------------------------------------------700 701        else {702 703          if (704            dbChatTitle705          ) {706 707            userGroup.title =708              dbChatTitle;709 710          }711 712 713          if (714            dbChatUsername715          ) {716 717            userGroup.username =718              dbChatUsername;719 720          }721 722 723          userGroup.last_seen =724            now;725 726 727          userGroup.messages =728            Number(729              userGroup.messages || 0730            ) + 1;731 732        }733 734      }735 736    }737 738 739    // ------------------------------------------------------740    // SAVE USER DATABASE741    // ------------------------------------------------------742 743    Bot.setProperty(744      "GIFT_USERS_DATABASE",745      users,746      "json"747    );748 749  } catch (e) {}750 751}752 753 754// ==========================================================755// SAVE GROUP756// ==========================================================757 758if (759  dbChatId &&760  (761    dbChatType === "group" ||762    dbChatType === "supergroup"763  )764) {765 766  try {767 768    var groups =769      Bot.getProperty(770        "GIFT_GROUPS_DATABASE"771      );772 773 774    if (775      !Array.isArray(groups)776    ) {777 778      groups = [];779 780    }781 782 783    var existingGroup =784      null;785 786 787    // ------------------------------------------------------788    // FIND GROUP789    // ------------------------------------------------------790 791    for (792      var g = 0;793      g < groups.length;794      g++795    ) {796 797      if (798        String(799          groups[g].id800        ) ===801        String(802          dbChatId803        )804      ) {805 806        existingGroup =807          groups[g];808 809        break;810 811      }812 813    }814 815 816    // ------------------------------------------------------817    // NEW GROUP818    // ------------------------------------------------------819 820    if (!existingGroup) {821 822      groups.push({823 824        id:825          dbChatId,826 827        title:828          dbChatTitle ||829          "Unknown Group",830 831        username:832          dbChatUsername || "",833 834        type:835          dbChatType,836 837        first_seen:838          now,839 840        last_seen:841          now,842 843        interactions:844          1,845 846        messages:847          1848 849      });850 851    }852 853 854    // ------------------------------------------------------855    // EXISTING GROUP856    // ------------------------------------------------------857 858    else {859 860      // ----------------------------------------------------861      // UPDATE GROUP NAME862      // ----------------------------------------------------863 864      if (865        dbChatTitle866      ) {867 868        existingGroup.title =869          dbChatTitle;870 871      }872 873 874      // ----------------------------------------------------875      // UPDATE USERNAME876      // ----------------------------------------------------877 878      if (879        dbChatUsername880      ) {881 882        existingGroup.username =883          dbChatUsername;884 885      }886 887 888      // ----------------------------------------------------889      // UPDATE TYPE890      // ----------------------------------------------------891 892      existingGroup.type =893        dbChatType;894 895 896      // ----------------------------------------------------897      // LAST SEEN898      // ----------------------------------------------------899 900      existingGroup.last_seen =901        now;902 903 904      // ----------------------------------------------------905      // INTERACTIONS906      // ----------------------------------------------------907 908      existingGroup.interactions =909        Number(910          existingGroup.interactions || 0911        ) + 1;912 913 914      // ----------------------------------------------------915      // MESSAGE COUNT916      // ----------------------------------------------------917 918      existingGroup.messages =919        Number(920          existingGroup.messages || 0921        ) + 1;922 923    }924 925 926    // ------------------------------------------------------927    // SAVE GROUP DATABASE928    // ------------------------------------------------------929 930    Bot.setProperty(931      "GIFT_GROUPS_DATABASE",932      groups,933      "json"934    );935 936  } catch (e) {}937 938}939 940 941// ==========================================================942// END DATABASE + ACTIVITY TRACKER943// ==========================================================