Compare commits
2 Commits
170bb431f5
...
4dc8fb19fb
Author | SHA1 | Date | |
---|---|---|---|
4dc8fb19fb | |||
bcfd056790 |
@ -18,7 +18,7 @@ module.exports = {
|
||||
announcement_channel: "876010629490683955",
|
||||
archive_category: "887838689533771776",
|
||||
data_dir: process.cwd() + "/data/",
|
||||
web_hostname: "ldb.owo69.me",
|
||||
base_uri: "https://ldb.owo69.me",
|
||||
world_clock: [
|
||||
{
|
||||
timezone: "America/Los_Angeles",
|
||||
|
31
datastore.js
Normal file
31
datastore.js
Normal file
@ -0,0 +1,31 @@
|
||||
var fs = require("fs");
|
||||
var config = require("./config");
|
||||
|
||||
module.exports = class DataStore {
|
||||
constructor(id) {
|
||||
if (id.includes('/')) throw new Error("NO");
|
||||
this.dir = `${config.data_dir}/${id}/`;
|
||||
if (!fs.existsSync(this.dir)) fs.mkdirSync(this.dir);
|
||||
}
|
||||
get(key) {
|
||||
if (key.includes('/')) throw new Error("NO");
|
||||
try {
|
||||
return fs.readFileSync(this.dir + key, "utf8") || true;
|
||||
} catch (error) {
|
||||
if (error.code == "ENOENT") return false;
|
||||
else throw error;
|
||||
}
|
||||
}
|
||||
put(key, value) {
|
||||
if (key.includes('/')) throw new Error("NO");
|
||||
return fs.writeFileSync(this.dir + key, value || '');
|
||||
}
|
||||
del(key) {
|
||||
if (key.includes('/')) throw new Error("NO");
|
||||
try {
|
||||
return fs.unlinkSync(this.dir + key);
|
||||
} catch (error) {
|
||||
if (error.code != "ENOENT") throw error;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
var client = require("./client");
|
||||
var config = require("./config");
|
||||
var app = require("./www");
|
||||
var fs = require("fs");
|
||||
var {EventEmitter} = require("events");
|
||||
let p = u => `${config.data_dir}/magic-channels/${u}`
|
||||
var DataStore = require("./datastore");
|
||||
|
||||
var ds = new DataStore("magic_channel");
|
||||
|
||||
module.exports = class MagicChannel extends EventEmitter{
|
||||
constructor(guild, user, channelName) {
|
||||
@ -19,10 +20,8 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
});
|
||||
|
||||
|
||||
if (fs.existsSync(p(this.user.id))) {
|
||||
let channel_id = fs.readFileSync(p(this.user.id));
|
||||
this.channel = client.channels.resolve(channel_id);
|
||||
}
|
||||
let channel_id = ds.get(this.user.id + "channel");
|
||||
if (channel_id) this.channel = client.channels.resolve(channel_id);
|
||||
|
||||
if (!this.channel) {
|
||||
this.guild.channels.create(channelName || this.user.username, {
|
||||
@ -42,14 +41,19 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
]
|
||||
}).then(channel => {
|
||||
this.channel = channel;
|
||||
fs.writeFileSync(p(this.user.id), channel.id);
|
||||
channel.send(`https://${config.web_hostname}/${this.user.id}`);
|
||||
ds.put(this.user.id + "channel", channel.id);
|
||||
channel.send(`${config.base_uri}/${this.user.id}`).then(message => {
|
||||
ds.put(this.user.id + "message", message.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.once("trigger", () => this.hide());
|
||||
}
|
||||
|
||||
getMessage() {
|
||||
return this.channel.messages.fetch(ds.get(this.user.id + "message"));
|
||||
}
|
||||
|
||||
show() {
|
||||
return this.channel.permissionOverwrites.edit(this.user, {
|
||||
@ -63,14 +67,17 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
});
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.show()
|
||||
async reset() {
|
||||
var message = await this.getMessage();
|
||||
await message.edit(`${config.base_uri}/${this.user.id}?${Math.random()}`);
|
||||
this.show();
|
||||
this.once("trigger", () => this.hide());
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.channel.delete();
|
||||
fs.unlinkSync(p(this.user.id));
|
||||
ds.del(this.user.id + "channel");
|
||||
ds.del(this.user.id + "message");
|
||||
return this.channel.delete();
|
||||
}
|
||||
|
||||
}
|
@ -65,7 +65,7 @@ async function doThing(message, user) {
|
||||
console.error("avatar download", error.message);
|
||||
}
|
||||
}
|
||||
avatarURL = `https://${config.web_hostname}/avatars/${afn}`
|
||||
avatarURL = `${config.base_uri}/avatars/${afn}`
|
||||
} else avatarURL = message.author.defaultAvatarURL;
|
||||
|
||||
let imageCandidate = message.attachments.find(a => [".png",".jpg",".jpeg",".webp",".gif"].some(e => a.url.toLowerCase().endsWith(e)));
|
||||
|
@ -73,7 +73,7 @@ async function embedPixiv(/*message*/ channel, /*array of*/ links, send /* chann
|
||||
function fallback() {
|
||||
// save the data already downloaded
|
||||
for (let image of images) if (image.data) fs.writeFileSync(config.data_dir + "pixiv-cache/" + image.url.split('?')[0].replace(/\//g, '\\'), image.data);
|
||||
let urls = images.map(image => image.url.replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`));
|
||||
let urls = images.map(image => image.url.replace("https://i.pximg.net/", `${config.base_uri}/pixiv-proxy/`));
|
||||
if (illust.xRestrict && !channel.nsfw) urls = urls.map(url => `||${url} ||`);
|
||||
urls = urls.join('\n');
|
||||
if (urls.length > 2000) {
|
||||
|
BIN
track-image.png
BIN
track-image.png
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 40 KiB |
Loading…
Reference in New Issue
Block a user