McFehliaC
This commit is contained in:
parent
6d0c1c5ef5
commit
d7abf6a5b2
56
src/inc/trigger/mcmaniac.js
Normal file
56
src/inc/trigger/mcmaniac.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
import sql from "../sql.js";
|
||||
|
||||
module.exports = bot => {
|
||||
bot._trigger.set("mcmaniac_add", {
|
||||
call: /Mc.*iaC/,
|
||||
level: 0,
|
||||
active: false,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const match = e.message.match(/.*(Mc\S+iaC?).*/)[0];
|
||||
console.log(match);
|
||||
sql.exec("insert into `mcmaniacs` (`item`) values (?)", [match])
|
||||
.then()
|
||||
.catch(err => {});
|
||||
}
|
||||
});
|
||||
|
||||
bot._trigger.set("mcmaniac_get", {
|
||||
call: /^(\.|\/)mcmaniac/i,
|
||||
level: 0,
|
||||
active: false,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const args = e.message.trim().substring(10);
|
||||
let query = "select id, item, (select count(*) from mcmaniacs) as sum from mcmaniacs order by {order} limit 1";
|
||||
let order = "id asc"
|
||||
, offset;
|
||||
|
||||
if (args.length > 0) {
|
||||
if (isNaN(parseInt(args)))
|
||||
return e.reply("Mayonnaise ist keine Zahl du Pfosten.");
|
||||
const index = parseInt(args);
|
||||
if (index < 0)
|
||||
order = "id desc";
|
||||
else if(index === 0)
|
||||
offset = 1;
|
||||
else
|
||||
offset = index;
|
||||
offset = Math.abs(index) - 1;
|
||||
query += " offset {offset}";
|
||||
}
|
||||
else
|
||||
order = "rand()";
|
||||
query = query
|
||||
.split("{order}").join(order)
|
||||
.split("{offset}").join(offset);
|
||||
sql.exec(query)
|
||||
.then(rows => {
|
||||
e.reply(`[${rows[0].id}/${rows[0].sum}] ${rows[0].item}`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user