Compare commits

..

2 Commits

Author SHA1 Message Date
1188883f20 Merge branch 'master' of gitea.moe:lamp/lampdiscordbot 2021-09-29 11:39:01 -07:00
4fea681a5f magicchannel1 2021-09-29 11:38:46 -07:00
2 changed files with 67 additions and 0 deletions

67
magicchannel.js Normal file
View File

@ -0,0 +1,67 @@
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}`
module.exports = class MagicChannel extends EventEmitter{
constructor(guild, user, channelName) {
super();
this.guild = client.guilds.resolve(guild);
this.user = client.users.resolve(user);
app.get(`/${this.user.id}`, (req, res) => {
res.sendFile(process.cwd() + "/track-image.png");
if (req.headers["user-agent"].includes("Discordbot")) return;
this.emit("trigger");
});
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, {
permissionOverwrites: [
{
id: this.guild.roles.everyone,
deny: "VIEW_CHANNEL"
},
{
id: this.user,
allow: "VIEW_CHANNEL"
}
]
}).then(channel => {
this.channel = channel;
fs.writeFileSync(p(this.user.id), channel.id);
channel.send(`https://${config.web_hostname}/${this.user.id}`);
});
}
this.once("trigger", () => this.hide());
}
show() {
return this.channel.permissionOverwrites.edit(this.user, {
VIEW_CHANNEL: true
});
}
hide() {
return this.channel.permissionOverwrites.edit(this.user, {
VIEW_CHANNEL: false
});
}
reset() {
this.show()
this.once("trigger", () => this.hide());
}
}

BIN
track-image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB