// Komandy nebo handelery který se nikam jinam nehodí

const role = { online: '684443816383610916', idle: '684444083065978941', dnd: '684444020558135399', offline: '684443903759614049', onlinephone: '777989420728975390' };
const spoustece = ['mares', 'mareš', 'purfie', 'denim', '<@!477202009066438668>'];
const emouty = ['purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfiek3:616026189269696512', 'purfieUchyl:576487602203525138', 'bafW:574646319696576532', 'purfiek4:616026180889477258'];
const rand = max => Math.floor(Math.random() * max);

module.exports = {
  more_komand: (mes, komand, celArgs) => {
    switch (komand) {
      case 'debug_log':
        console.log('log: ', celArgs);
        mes.channel.send('je to v konzoli');
        break;
      default:
        return false;
    }
    return true;
  },

  // Změna rolí podle statusu
  on_presenceUpdate: (bef, aft) => {
    if (aft.guild.id !== '555779161067749446' || process.env.IGNORE_PRESENCE) return;

    if (!bef) bef = { status: 'offline', clientStatus: {} };
    if (bef.clientStatus.mobile === 'online' && bef.clientStatus.desktop !== 'online') bef.status = 'onlinephone';
    if (aft.clientStatus.mobile === 'online' && aft.clientStatus.desktop !== 'online') aft.status = 'onlinephone';
    if (bef.status === aft.status) return;

    aft.member.roles.add(role[aft.status]);
    aft.member.roles.remove(role[bef.status]);
  },

  // Zareaguje na zprávu pokud obsahuje spouštěče a pokud RNG
  on_message: mes => {
    let sance = 0;
    spoustece.forEach(sp => {
      if (mes.content.toLowerCase().includes(sp)) sance++;
    });
    if (rand(3) < sance) mes.react(emouty[rand(emouty.length)]);
  }
}
