Compare commits
No commits in common. "4dc8fb19fb9456ad968c39ddc38cc29843d24e9b" and "170bb431f502bac5b889717256703ea7d01bda05" have entirely different histories.
4dc8fb19fb
...
170bb431f5
@ -18,7 +18,7 @@ module.exports = {
|
||||
announcement_channel: "876010629490683955",
|
||||
archive_category: "887838689533771776",
|
||||
data_dir: process.cwd() + "/data/",
|
||||
base_uri: "https://ldb.owo69.me",
|
||||
web_hostname: "ldb.owo69.me",
|
||||
world_clock: [
|
||||
{
|
||||
timezone: "America/Los_Angeles",
|
||||
|
31
datastore.js
31
datastore.js
@ -1,31 +0,0 @@
|
||||
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,10 +1,9 @@
|
||||
var client = require("./client");
|
||||
var config = require("./config");
|
||||
var app = require("./www");
|
||||
var fs = require("fs");
|
||||
var {EventEmitter} = require("events");
|
||||
var DataStore = require("./datastore");
|
||||
|
||||
var ds = new DataStore("magic_channel");
|
||||
let p = u => `${config.data_dir}/magic-channels/${u}`
|
||||
|
||||
module.exports = class MagicChannel extends EventEmitter{
|
||||
constructor(guild, user, channelName) {
|
||||
@ -20,8 +19,10 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
});
|
||||
|
||||
|
||||
let channel_id = ds.get(this.user.id + "channel");
|
||||
if (channel_id) this.channel = client.channels.resolve(channel_id);
|
||||
if (fs.existsSync(p(this.user.id))) {
|
||||
let channel_id = fs.readFileSync(p(this.user.id));
|
||||
this.channel = client.channels.resolve(channel_id);
|
||||
}
|
||||
|
||||
if (!this.channel) {
|
||||
this.guild.channels.create(channelName || this.user.username, {
|
||||
@ -41,19 +42,14 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
]
|
||||
}).then(channel => {
|
||||
this.channel = channel;
|
||||
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);
|
||||
});
|
||||
fs.writeFileSync(p(this.user.id), channel.id);
|
||||
channel.send(`https://${config.web_hostname}/${this.user.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, {
|
||||
@ -67,17 +63,14 @@ module.exports = class MagicChannel extends EventEmitter{
|
||||
});
|
||||
}
|
||||
|
||||
async reset() {
|
||||
var message = await this.getMessage();
|
||||
await message.edit(`${config.base_uri}/${this.user.id}?${Math.random()}`);
|
||||
this.show();
|
||||
reset() {
|
||||
this.show()
|
||||
this.once("trigger", () => this.hide());
|
||||
}
|
||||
|
||||
destroy() {
|
||||
ds.del(this.user.id + "channel");
|
||||
ds.del(this.user.id + "message");
|
||||
return this.channel.delete();
|
||||
this.channel.delete();
|
||||
fs.unlinkSync(p(this.user.id));
|
||||
}
|
||||
|
||||
}
|
@ -65,7 +65,7 @@ async function doThing(message, user) {
|
||||
console.error("avatar download", error.message);
|
||||
}
|
||||
}
|
||||
avatarURL = `${config.base_uri}/avatars/${afn}`
|
||||
avatarURL = `https://${config.web_hostname}/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/", `${config.base_uri}/pixiv-proxy/`));
|
||||
let urls = images.map(image => image.url.replace("https://i.pximg.net/", `https://${config.web_hostname}/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: 40 KiB After Width: | Height: | Size: 2.6 KiB |
Loading…
Reference in New Issue
Block a user