Advertisement
ArmFire1911

Untitled

Mar 18th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //使用者指令記錄模組
  2. let whoTrigger = {};
  3.  
  4. //指令設定區
  5. client.on('message', (msg) => {
  6.     let lit, command;
  7.     lit = msg.content;
  8.  
  9.     //偵測時間設定
  10.     function timerCleanWhoTrigger() {
  11.         whoTrigger[msg.author].timer = setTimeout(
  12.             function () {
  13.                 delete whoTrigger[msg.author];
  14.                 msg.reply('不說話就不要吵我!')
  15.             }
  16.             , 5000
  17.         );
  18.     };
  19.     function timerCleanWhoTriggerStop() {
  20.         clearTimeout(whoTrigger[msg.author].timer);
  21.     };
  22.  
  23.     //找出命令斷點
  24.     command = lit.split(/\s/)[0];
  25.  
  26.     //使用者限制載入
  27.     if (userLock.includes(command)) {
  28.         if (detect(msg.author)) {
  29.             return;
  30.         }
  31.     };
  32.     //頻道限制模組載入
  33.     if (channelLock.includes(command)) {
  34.         if (forbid(msg.channel)) {
  35.             return;
  36.         }
  37.     };
  38.     //第一層
  39.     if (messageData[command] !== undefined && whoTrigger[msg.author] === undefined) {
  40.         messageData[command].execute(msg);
  41.         if (whoTrigger[msg.author] !== undefined) {
  42.             timerCleanWhoTrigger();
  43.             //使用紀錄
  44.             console.log(
  45.                 `${msg.author.username}(${msg.author})在${msg.channel}使用了: ${command}!`
  46.             );
  47.         }
  48.     }
  49.     //其他層
  50.     else if (whoTrigger[msg.author] !== undefined && whoTrigger[msg.author].useWhat !== undefined) {
  51.         timerCleanWhoTriggerStop();
  52.         let commandHandler = messageData[whoTrigger[msg.author].useWhat[0]];
  53.         for (let i = 1; i < whoTrigger[msg.author].useWhat.length; i++) {
  54.             commandHandler = commandHandler.submessageData[whoTrigger[msg.author].useWhat[i]]
  55.         }
  56.         commandHandler = commandHandler.submessageData[command];
  57.         if (commandHandler !== undefined) {
  58.             commandHandler.execute(msg);
  59.         }
  60.         else {
  61.             msg.reply('沒有這個選項啦!');
  62.             delete whoTrigger[msg.author];
  63.             //使用紀錄
  64.             console.log(
  65.                 `${msg.author.username}(${msg.author})在${msg.channel}使用了: ${command}!`
  66.             );
  67.         }
  68.     }
  69.     //非法指令處理
  70.     else {
  71.         delete whoTrigger[msg.author];
  72.     }
  73. }
  74. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement