This commit is contained in:
Flummi 2016-08-16 19:55:44 +02:00
parent 362ed451be
commit cbf7ddafc1

View File

@ -53,7 +53,7 @@ bot.on('motd', (e) => {
bot.on('message', (e) => {
var orig = e.message;
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)/* && e.channel.getName() == "#f0ck"*/) { // shitpostcatcher
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi) && e.channel.getName() == "#f0ck") { // shitpostcatcher
if(!orig.match(/\!ignore$/)) {
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
tmp.forEach((entry,i,a) => {
@ -218,7 +218,7 @@ http.createServer((req, res) => {
});
}
else if(Number.isInteger(parseInt(url))) { // itempage
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1; select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?)", [url, url, url], (err, rows, fields) => {
sql.query("select * from `f0ck`.`items` where `id` = ? limit 1; select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); select `id` from `f0ck`.`items` where `id` = (select max(`id`) from `f0ck`.`items` where `id` < ?);", [url, url, url], (err, rows, fields) => {
var tpl = swig.compile(templates.item);
var data = {
id: '',
@ -229,10 +229,12 @@ http.createServer((req, res) => {
mime: '',
size: '',
userchannel: '',
usernetwork: ''
usernetwork: '',
next: null,
prev: null
};
if(rows.length && rows[0].id == parseInt(url)) {
var e = rows[0];
if(rows.length && rows[0][0].id == parseInt(url)) {
var e = rows[0][0];
switch(e.mime) {
case "image/png":
case "image/jpeg":
@ -255,16 +257,18 @@ http.createServer((req, res) => {
data.size = formatSize(e.size);
data.userchannel = e.userchannel;
data.usernetwork = e.usernetwork;
if(rows.length >= 2)
if(rows[1].id > parseInt(url))
data.next = rows[1].id;
if(rows.length >= 2) {
if(rows[1][0].id > parseInt(url))
data.next = rows[1][0].id;
else
data.prev = rows[1].id;
if(rows.length >= 3)
if(rows[2].id > parseInt(url))
data.next = rows[2].id;
data.prev = rows[1][0].id;
}
if(rows.length >= 3) {
if(rows[2][0].id > parseInt(url))
data.next = rows[2][0].id;
else
data.prev = rows[2].id;
data.prev = rows[2][0].id;
}
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(tpl(data), 'utf-8');