millswelbeck148/SireimadeBotPublic · Bot Template
AIGift AI is a command‑based Telegram bot that offers a mix of moderation tools and light‑hearted features. It lets group admins ban, unban, and promote users by replying to messages, while also providing user‑ID lookup and a support link that enforces a forced‑join check. In addition, the bot includes simple games such as tic‑tac‑toe (commands /x and /o) and a Magic 8‑Ball (/8ball). The code uses the TeleBotHost TBL APIs (Bot, Api, db, etc.) and contains no long‑running listeners or external frameworks.
Moderationmoderationadminbanunbanpromoteuser-info
118 commands3 envUpdated 17d agoCreated Aug 27, 2026
commands/_lock.js
javascript · 502 lines
1/**#command2name: /lock3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// ==========================================================13// 👑 GIFT AI — /lock14// GROUP LOCK SYSTEM15//16// • Admin only17// • /lock = 1 hour18// • /lock 2 = 2 hours19// • /lock 6 = 6 hours20// • /lock 0.5 = 30 minutes21// • Automatically unlocks when time expires22// • Replies directly to /lock23// ==========================================================24 25 26// ----------------------------------------------------------27// BASIC CHECK28// ----------------------------------------------------------29 30if (!request || !chat || !chat.id) {31 return;32}33 34 35var chatId = chat.id;36var adminId = request.from.id;37 38 39// ----------------------------------------------------------40// ONLY GROUPS41// ----------------------------------------------------------42 43if (44 chat.type !== "group" &&45 chat.type !== "supergroup"46) {47 48 await Api.sendMessage({49 chat_id: chatId,50 text: "😐 <b>/lock only works inside groups.</b>",51 parse_mode: "HTML",52 reply_to_message_id: request.message_id53 });54 55 return;56}57 58 59// ----------------------------------------------------------60// CHECK ADMIN61// ----------------------------------------------------------62 63var adminCheck = await Api.getChatMember({64 chat_id: chatId,65 user_id: adminId66});67 68 69if (70 !adminCheck ||71 !adminCheck.ok ||72 !adminCheck.result73) {74 75 await Api.sendMessage({76 chat_id: chatId,77 text:78 "⚠️ <b>I couldn't verify your admin status.</b>",79 parse_mode: "HTML",80 reply_to_message_id: request.message_id81 });82 83 return;84}85 86 87var adminStatus =88 adminCheck.result.status;89 90 91// ----------------------------------------------------------92// ADMIN ONLY93// ----------------------------------------------------------94 95if (96 adminStatus !== "administrator" &&97 adminStatus !== "creator"98) {99 100 await Api.sendMessage({101 chat_id: chatId,102 text:103 "🚫 <b>Only group admins can lock the group.</b>",104 parse_mode: "HTML",105 reply_to_message_id: request.message_id106 });107 108 return;109}110 111 112// ----------------------------------------------------------113// READ HOURS114// ----------------------------------------------------------115//116// /lock117// /lock 2118// /lock 6119// /lock 0.5120//121// Default = 1 hour122// ----------------------------------------------------------123 124var hours = 1;125 126if (127 request.args &&128 request.args.length > 0129) {130 hours = parseFloat(131 String(request.args[0]).replace(",", ".")132 );133}134 135 136// ----------------------------------------------------------137// FALLBACK FOR PARAMS138// ----------------------------------------------------------139 140if (141 (!request.args || request.args.length === 0) &&142 typeof params !== "undefined" &&143 params144) {145 146 var rawParams = String(params).trim();147 148 if (rawParams) {149 hours = parseFloat(150 rawParams.split(/\s+/)[0].replace(",", ".")151 );152 }153}154 155 156// ----------------------------------------------------------157// VALIDATE HOURS158// ----------------------------------------------------------159 160if (161 isNaN(hours) ||162 hours <= 0163) {164 165 await Api.sendMessage({166 chat_id: chatId,167 text:168 "⚠️ <b>Invalid lock duration.</b>\n\n" +169 "Use:\n" +170 "• <code>/lock</code> → 1 hour\n" +171 "• <code>/lock 2</code> → 2 hours\n" +172 "• <code>/lock 6</code> → 6 hours\n" +173 "• <code>/lock 0.5</code> → 30 minutes",174 parse_mode: "HTML",175 reply_to_message_id: request.message_id176 });177 178 return;179}180 181 182// ----------------------------------------------------------183// MAXIMUM LOCK TIME184// ----------------------------------------------------------185//186// Maximum: 7 days187// ----------------------------------------------------------188 189if (hours > 168) {190 191 await Api.sendMessage({192 chat_id: chatId,193 text:194 "⚠️ <b>Maximum lock duration is 168 hours.</b>",195 parse_mode: "HTML",196 reply_to_message_id: request.message_id197 });198 199 return;200}201 202 203// ----------------------------------------------------------204// CHECK GIFT'S OWN PERMISSIONS205// ----------------------------------------------------------206 207var botId = null;208 209try {210 211 var me = await Api.getMe();212 213 if (214 me &&215 me.ok &&216 me.result217 ) {218 botId = me.result.id;219 }220 221} catch (e) {222 botId = null;223}224 225 226// ----------------------------------------------------------227// CHECK BOT ADMIN STATUS228// ----------------------------------------------------------229 230if (botId) {231 232 var botCheck = await Api.getChatMember({233 chat_id: chatId,234 user_id: botId235 });236 237 238 if (239 !botCheck ||240 !botCheck.ok ||241 !botCheck.result242 ) {243 244 await Api.sendMessage({245 chat_id: chatId,246 text:247 "❌ <b>Gift must be an admin to lock this group.</b>",248 parse_mode: "HTML",249 reply_to_message_id: request.message_id250 });251 252 return;253 }254 255 256 var botStatus =257 botCheck.result.status;258 259 260 if (261 botStatus !== "administrator" &&262 botStatus !== "creator"263 ) {264 265 await Api.sendMessage({266 chat_id: chatId,267 text:268 "❌ <b>Make Gift an admin first.</b>\n\n" +269 "I need permission to restrict members.",270 parse_mode: "HTML",271 reply_to_message_id: request.message_id272 });273 274 return;275 }276 277 278 if (279 botStatus === "administrator" &&280 botCheck.result.can_restrict_members === false281 ) {282 283 await Api.sendMessage({284 chat_id: chatId,285 text:286 "❌ <b>Gift can't lock this group.</b>\n\n" +287 "Give Gift permission to <b>Restrict Members</b>.",288 parse_mode: "HTML",289 reply_to_message_id: request.message_id290 });291 292 return;293 }294}295 296 297// ----------------------------------------------------------298// CALCULATE LOCK TIME299// ----------------------------------------------------------300 301var now =302 Math.floor(Date.now() / 1000);303 304var lockUntil =305 now + Math.floor(hours * 3600);306 307 308// ----------------------------------------------------------309// LOCK GROUP310// ----------------------------------------------------------311//312// Everybody loses permission to send messages.313// Administrators can still manage the group.314//315// ----------------------------------------------------------316 317var lockResult =318 await Api.setChatPermissions({319 chat_id: chatId,320 321 permissions: {322 can_send_messages: false,323 can_send_audios: false,324 can_send_documents: false,325 can_send_photos: false,326 can_send_videos: false,327 can_send_video_notes: false,328 can_send_voice_notes: false,329 can_send_polls: false,330 can_send_other_messages: false,331 can_add_web_page_previews: false332 }333 });334 335 336// ----------------------------------------------------------337// LOCK FAILED338// ----------------------------------------------------------339 340if (341 !lockResult ||342 !lockResult.ok343) {344 345 await Api.sendMessage({346 chat_id: chatId,347 text:348 "❌ <b>I couldn't lock this group.</b>\n\n" +349 "Make sure Gift is an admin with permission to change group permissions.",350 parse_mode: "HTML",351 reply_to_message_id: request.message_id352 });353 354 return;355}356 357 358// ----------------------------------------------------------359// FORMAT DURATION360// ----------------------------------------------------------361 362var durationText;363 364if (hours < 1) {365 366 var minutes =367 Math.round(hours * 60);368 369 durationText =370 minutes + " minute" +371 (minutes === 1 ? "" : "s");372 373} else {374 375 var wholeHours =376 Math.floor(hours);377 378 var remainingMinutes =379 Math.round((hours - wholeHours) * 60);380 381 durationText =382 wholeHours + " hour" +383 (wholeHours === 1 ? "" : "s");384 385 if (remainingMinutes > 0) {386 durationText +=387 " " +388 remainingMinutes +389 " minute" +390 (remainingMinutes === 1 ? "" : "s");391 }392}393 394 395// ----------------------------------------------------------396// SAVE LOCK STATE397// ----------------------------------------------------------398 399Bot.setProperty(400 "LOCKED_" + chatId,401 true,402 "boolean"403);404 405Bot.setProperty(406 "LOCK_UNTIL_" + chatId,407 lockUntil,408 "integer"409);410 411 412// ----------------------------------------------------------413// SUCCESS MESSAGE414// ----------------------------------------------------------415 416var adminName =417 String(418 request.from.first_name ||419 request.from.username ||420 "Admin"421 );422 423 424await Api.sendMessage({425 chat_id: chatId,426 text:427 "🔒 <b>GROUP LOCKED</b>\n\n" +428 "💜 Chat: <b>" +429 String(chat.title || "This group") +430 "</b>\n" +431 "⏱ Duration: <b>" +432 durationText +433 "</b>\n" +434 "👑 Locked by: <a href=\"tg://user?id=" +435 adminId +436 "\">" +437 adminName +438 "</a>\n\n" +439 "🤫 Everyone behave. Gift is watching.\n" +440 "🔓 The group will automatically reopen when the timer ends.",441 parse_mode: "HTML",442 reply_to_message_id: request.message_id443});444 445 446// ----------------------------------------------------------447// AUTOMATIC UNLOCK448// ----------------------------------------------------------449//450// TeleBotHost must execute this section after the timer.451// If your TeleBotHost version supports delayed execution,452// attach this code to a delayed/automation Logic block using453// the saved LOCK_UNTIL_<chatId> value.454//455// ----------------------------------------------------------456 457 458// Check current lock state459 460var currentLock =461 Bot.getProperty(462 "LOCK_UNTIL_" + chatId463 );464 465 466// If the lock time has already expired, unlock now467 468if (469 currentLock &&470 Math.floor(Date.now() / 1000) >= currentLock471) {472 473 await Api.setChatPermissions({474 chat_id: chatId,475 476 permissions: {477 can_send_messages: true,478 can_send_audios: true,479 can_send_documents: true,480 can_send_photos: true,481 can_send_videos: true,482 can_send_video_notes: true,483 can_send_voice_notes: true,484 can_send_polls: true,485 can_send_other_messages: true,486 can_add_web_page_previews: true487 }488 });489 490 491 Bot.setProperty(492 "LOCKED_" + chatId,493 false,494 "boolean"495 );496 497 Bot.setProperty(498 "LOCK_UNTIL_" + chatId,499 0,500 "integer"501 );502}