fixed waifu/husbando for tg

This commit is contained in:
Flummi 2017-12-17 13:10:05 +01:00
parent 20c5ea20de
commit b8bc1c28b0

View File

@ -179,18 +179,21 @@ export default bot => {
bot._trigger.set("waifu_husbando", new bot.trigger({
call: /^(\.|\/)(waifu|husbando)/i,
f: e => {
let nick = e.args[0] || e.user.nick;
let nick = e.args[0] || (e.type === "tg"?e.user.username || e.user.nick:e.user.nick)
let mode = e.cmd;
nick = nick.split("@").join("");
if(e.args.length > 0 && e.args[0].charAt(0) === "=") {
let tmp = e.args[0].slice(1);
sql.any(`insert into nxy_users (nick, ${mode}) values (lower($1), $2) on conflict (nick) do update set ${mode} = excluded.${mode}`, [e.user.nick, tmp])
sql.any(
`insert into nxy_users (nick, ${mode}) values (lower($1), $2) on conflict (nick) do update set ${mode} = excluded.${mode}`, [
(e.type === "tg"?e.user.username || e.user.nick:e.user.nick),
tmp
])
.then(rows => {
e.reply(`${mode.charAt(0).toUpperCase()+mode.slice(1)} set to: [b]${tmp}[/b]`)
})
.catch(err => {
console.log(err);
});
.catch(err => console.log(err));
}
else {
sql.any(`select ${mode} from nxy_users where lower(nick) = lower($1) limit 1`, [nick])
@ -199,9 +202,7 @@ export default bot => {
return e.reply(`[b]${mode.charAt(0).toUpperCase() + mode.slice(1)}[/b]: none`);
e.reply(`${mode.charAt(0).toUpperCase() + mode.slice(1)}: [b]${rows[0][mode]}[/b]`);
})
.catch(err => {
console.log(err);
});
.catch(err => console.log(err));
}
}
}));