import sql from "../sql.js";

const data = {
  yiff: [],
  kill_templates: [],
  kill_parts: {},
  genders: [],
  woahs: [],
  slap: []
};

Object.keys(data).forEach(cur => {
  sql.exec(`select \`data\` from \`useless\` where \`trigger\` = '${cur}' limit 1`, (err, row) => {
    data[cur] = JSON.parse(row[0].data);
  });
});

module.exports = bot => {
  bot._trigger.set("kiss", {
    call: /^(.|\/)kiss/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.reply(`[b](づ。◕‿‿◕。)づ" 。。・゜゜・。。・゜❤ ${args.join(" ").trim()} ❤[/b]`);
    }
  });

  bot._trigger.set("hug", {
    call: /^(.|\/)hug/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.reply(`[b]♥♡❤♡♥ ${args.join(" ").trim()} ♥♡❤♡♥[/b]`);
    }
  });

  bot._trigger.set("kill", {
    call: /^(.|\/)kill/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];

      e.replyAction(data.kill_templates[~~(Math.random() * data.kill_templates.length)]
        .replace("{user}", `[b]${args[0]}[/b]`)
        .replace("{limbs}", data.kill_parts.limbs[~~(Math.random() * data.kill_parts.limbs.length)])
        .replace("{gun}", data.kill_parts.gun[~~(Math.random() * data.kill_parts.gun.length)])
        .replace("{weapon_stab}", data.kill_parts.weapon_stab[~~(Math.random() * data.kill_parts.weapon_stab.length)])
        .replace("{weapon_slice}", data.kill_parts.weapon_slice[~~(Math.random() * data.kill_parts.weapon_slice.length)])
        .replace("{weapon_crush}", data.kill_parts.weapon_crush[~~(Math.random() * data.kill_parts.weapon_crush.length)])
        .replace("{weapon_explosive}", data.kill_parts.weapon_explosive[~~(Math.random() * data.kill_parts.weapon_explosive.length)])
        .replace("{tall_thing}", data.kill_parts.tall_thing[~~(Math.random() * data.kill_parts.tall_thing.length)])
        .replace("{spiked_thing}", data.kill_parts.spiked_thing[~~(Math.random() * data.kill_parts.spiked_thing.length)])
        .replace("{bomb}", data.kill_parts.bomb[~~(Math.random() * data.kill_parts.bomb.length)])
      );
    }
  });

  bot._trigger.set("yiff", {
    call: /^(.|\/)yiff/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];

      e.replyAction(data.yiff[~~(Math.random() * data.yiff.length)]
        .replace("{user}", `[b]${args[0]}[/b]`)
        .replace("{yiffer}", `[b]${e.user.nick}[/b]`)
      );
    }
  });

  bot._trigger.set("bier", {
    call: /^(.|\/)bier/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.replyAction(`schenkt ein kühles Blondes an [b]${args[0]}[/b] aus.`);
    }
  });

  bot._trigger.set("fucken", {
    call: /^(.|\/)fucken/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.replyAction(`fuckt [b]${args[0]}[/b] und tötet [b]${args[0]}[/b] anschließend.`);
    }
  });

  bot._trigger.set("hack", {
    call: /^(.|\/)hack/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.reply(`hacking ${args[0]}...`);
    }
  });

  bot._trigger.set("spit", {
    call: /^(.|\/)spit/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.replyAction(`spits on [b]${args[0]}[/b] like a dirty whore.`);
    }
  });

  bot._trigger.set("assume", {
    call: /^(.|\/)assume/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.reply(`Assuming [b]${args[0]}'s[/b] gender... they're a ${data.genders[~~(Math.random() * data.genders.length)]}.`);
    }
  });

  bot._trigger.set("jn", {
    call: /^(.|\/)jn/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      e.reply(`${e.user.nick}: [b]${~~(Math.random() * 2) ? "Ja" : "Nein"}[/b]`);
    }
  });

  bot._trigger.set("choose", {
    call: /^(.|\/)choose .*/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      const args = e.message.substring(8).trim().split(",");
      if (args.length < 2)
        return e.reply(`${e.user.nick}: Ob du behindert bist?`);
      e.reply(`${e.user.nick}: ${args[~~(Math.random() * args.length)].trim()}`);
    }
  });

  bot._trigger.set("huehuehue", {
    call: /^huehuehue$/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      e.reply("huehuehue");
    }
  });

  bot._trigger.set("woah", {
    call: /woah/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      if (~~(Math.random() * 4))
        e.reply(data.woahs[~~(Math.random() * data.woahs.length)]);
    }
  });

  bot._trigger.set("REEE", {
    call: /re+$/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      e.reply("R".padEnd(~~(Math.random() * 20 + 10), "E"));
    }
  });

  bot._trigger.set("meme", {
    call: /^(.|\/)meme .*/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      const args = e.message.trim().substring(6).split("/");
      //if(args.length < 3)
        return e.reply("[WIP] too few arguments: .meme [meme] / [line 1] / [line 2]");

    }
  });

  bot._trigger.set("slap", {
    call: /^(.|\/)slap/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      let args = e.message.trim().split(" ");
      args.shift();
      args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
      e.replyAction(data.slap[~~(Math.random() * data.slap.length)]
        .replace("{user}", `[b]${args[0]}[/b]`)
      );
    }
  });

  bot._trigger.set("fw", {
    call: /^(.|\/)fw .*/i,
    level: 0,
    active: true,
    clients: ["irc", "tg"],
    f: e => {
      const args = e.message.substring(4).trim();
      e.reply(args.toUpperCase().split``.map(c => String.fromCharCode(65312 + (c.charCodeAt(0) - 64))).join``);
    }
  });
};