Compare commits
2 Commits
513a9f76aa
...
1188883f20
Author | SHA1 | Date | |
---|---|---|---|
1188883f20 | |||
4fea681a5f |
67
magicchannel.js
Normal file
67
magicchannel.js
Normal 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
BIN
track-image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Loading…
Reference in New Issue
Block a user