Compare commits

..

2 Commits

Author SHA1 Message Date
097d186f58 avatar server in app 2021-08-21 19:09:08 -07:00
cf3adae647 dockerfile volume dont persist rebuilds 2021-08-21 19:00:52 -07:00
5 changed files with 7 additions and 7 deletions

View File

@ -2,5 +2,4 @@ FROM node:latest
ADD . /app ADD . /app
WORKDIR /app WORKDIR /app
RUN npm ci RUN npm ci
VOLUME /app/data
CMD ["node", "main.js"] CMD ["node", "main.js"]

View File

@ -13,6 +13,4 @@ module.exports = {
porn_channel: "835734868427669574", porn_channel: "835734868427669574",
data_dir: process.cwd() + "/data/", data_dir: process.cwd() + "/data/",
web_hostname: "ldb.owo69.me", web_hostname: "ldb.owo69.me",
avatar_cache_dir: "/srv/www/ldb/avatars/",
avatar_cache_url: `https://${this.web_hostname}/avatars/`,
} }

View File

@ -3,4 +3,4 @@ cd `dirname "$0"`
docker stop ldb docker stop ldb
docker rm ldb docker rm ldb
docker build --no-cache -t ledlamp/lampdiscordbot . docker build --no-cache -t ledlamp/lampdiscordbot .
docker run -d --name ldb --restart=unless-stopped -p 127.0.0.1:9251:9251 --env-file=secrets.env -v /srv/www/ldb/:/srv/www/ldb/ ledlamp/lampdiscordbot docker run -d --name ldb --restart=unless-stopped -p 127.0.0.1:9251:9251 --env-file=secrets.env -v /srv/ldb/data:/app/data -v /srv/www/ldb/:/srv/www/ldb/ ledlamp/lampdiscordbot

View File

@ -29,6 +29,6 @@ client.on("guildMemberRemove", member => {
require('./commands.js'); require('./commands.js');
require('./colors.js'); require('./colors.js');
require('./pinboard.js');
global.app = require('./www.js'); global.app = require('./www.js');
require('./pinboard.js');
require('./pixiv-embedder.js'); require('./pixiv-embedder.js');

View File

@ -1,5 +1,6 @@
var fs = require("fs"); var fs = require("fs");
var fetch = require("node-fetch"); var fetch = require("node-fetch");
client.on("messageReactionAdd", async (reaction, user) => { client.on("messageReactionAdd", async (reaction, user) => {
if (reaction.emoji.name == '📍' || reaction.emoji.name == '📌') { if (reaction.emoji.name == '📍' || reaction.emoji.name == '📌') {
if (!reaction.message.guild) return; if (!reaction.message.guild) return;
@ -29,7 +30,7 @@ client.on("messageReactionAdd", async (reaction, user) => {
var avatarURL = reaction.message.author.avatarURL({dynamic: true}); var avatarURL = reaction.message.author.avatarURL({dynamic: true});
if (avatarURL) { if (avatarURL) {
let afn = avatarURL.split('/').pop(); let afn = avatarURL.split('/').pop();
let lapath = config.avatar_cache_dir + afn; let lapath = config.data_dir + "avatars/" + afn;
if (!fs.existsSync(lapath)) { if (!fs.existsSync(lapath)) {
try { try {
(await fetch(avatarURL)).body.pipe(fs.createWriteStream(lapath)); (await fetch(avatarURL)).body.pipe(fs.createWriteStream(lapath));
@ -37,7 +38,7 @@ client.on("messageReactionAdd", async (reaction, user) => {
console.error("avatar download", error.message); console.error("avatar download", error.message);
} }
} }
avatarURL = config.avatar_cache_url + afn; avatarURL = `https://${config.web_hostname}/avatars/${afn}`
} else avatarURL = reaction.message.author.defaultAvatarURL; } else avatarURL = reaction.message.author.defaultAvatarURL;
let imageCandidate = reaction.message.attachments.find(a => [".png",".jpg",".jpeg",".webp",".gif"].some(e => a.url.toLowerCase().endsWith(e))); let imageCandidate = reaction.message.attachments.find(a => [".png",".jpg",".jpeg",".webp",".gif"].some(e => a.url.toLowerCase().endsWith(e)));
@ -55,3 +56,5 @@ client.on("messageReactionAdd", async (reaction, user) => {
(await client.channels.fetch(config.archive_channel))?.send({content: `https://discord.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, embeds:[embed]}); (await client.channels.fetch(config.archive_channel))?.send({content: `https://discord.com/channels/${reaction.message.guild.id}/${reaction.message.channel.id}/${reaction.message.id}`, embeds:[embed]});
} }
}); });
app.use("/avatars/", require("express").static(config.data_dir + "avatars/"));