M
M
MrZilla2019-03-23 11:25:13
JavaScript
MrZilla, 2019-03-23 11:25:13

How to make a time limit per team?

vk.updates.hear(/^(?:ping)\s?([^]+)?/i, async (message) => {
  if (!message.$match[1]) {
    return message.send(`⚠ Вы не указали IP!\n Например: 127.0.0.0:25565`);
  }  
    axios.get(`https://api.mcsrvstat.us/1/${message.$match[1]}`).then(res => {
    if(res.data && res.data.players) {
      let playerCount = res.data.players.online || 0
      let playerMax = res.data.players.max || 0
      let playerList = res.data.players.list || 'Нет игроков онлайн'
    if(res.data && res.data.version) {
      let version = res.data.version || 'Неизвестна'
    if(res.data && res.data.motd.clean) {
      let motd = res.data.motd.clean || 'Нет названия'
    if(res.data && res.data.software) {
      let core = res.data.software || 'Ядро неизвестно'
    return message.send (` ${motd}:\n Версия: ${version}\n‍♂ Игроков: ${playerCount}/${playerMax} ${playerList}\n Ядро: ${core}`)
      }
    }
    }
    }else message.send(`⚠ Неверный ip адрес!\n Либо информация о нём недоступна.`);
  }).catch(err => console.log('api.mcsrvstat.us ошибка:', err))
});

updates.startPolling()
.then(() => {
  console.log(`Ping started!`);
})

Let's say user 1 has executed a command, a 1-minute limit is imposed on him and he cannot execute the command, but at the same time user 2 can execute it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2019-03-23
@dollar

let can_do_commands = true;

......

can_do_commands = false;
setTimeout("can_do_commands = true", 60000);

Plus, the corresponding check where commands are received from the user. I hope it's clearer.

S
Stockholm Syndrome, 2019-03-23
@StockholmSyndrome

you can create an object, the keys of which will be the identifiers of users who have a restriction on sending
, then in the body of the command handler you need to add a check

if (!limits[message.senderId]) {
  limits[message.senderId] = true;
  setTimeout(() => {
    delete limits[message.senderId];
  }, 60000);
  // отправляем сообщение
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question