Added channel, allow using a mention on hackban and snowflake
This commit is contained in:
parent
56b382fce3
commit
628a002205
7 changed files with 117 additions and 67 deletions
35
commands/channel.js
Normal file
35
commands/channel.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
const db = require("../utils/database.js");
|
||||||
|
|
||||||
|
exports.run = async (message, args) => {
|
||||||
|
if (args.length === 0) return `${message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`;
|
||||||
|
if (args[0] !== "disable" && args[0] !== "enable") return `${message.author.mention}, that's not a valid option!`;
|
||||||
|
const guildDB = (await db.guilds.find({id: message.channel.guild.id}).exec())[0];
|
||||||
|
if (args[0].toLowerCase() === "disable") {
|
||||||
|
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
|
||||||
|
const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");
|
||||||
|
console.log(id);
|
||||||
|
if (guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
|
||||||
|
guildDB.disabledChannels.push(id);
|
||||||
|
} else {
|
||||||
|
if (guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
|
||||||
|
guildDB.disabledChannels.push(message.channel.id);
|
||||||
|
}
|
||||||
|
await guildDB.save();
|
||||||
|
return `${message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
|
||||||
|
} else if (args[0].toLowerCase() === "enable") {
|
||||||
|
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
|
||||||
|
const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");
|
||||||
|
if (!guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
|
||||||
|
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== id);
|
||||||
|
} else {
|
||||||
|
if (!guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm not disabled in this channel!`;
|
||||||
|
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== message.channel.id );
|
||||||
|
}
|
||||||
|
await guildDB.save();
|
||||||
|
return `${message.author.mention}, I have been re-enabled in this channel.`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.category = 1;
|
||||||
|
exports.help = "Enables/disables me in a channel";
|
||||||
|
exports.params = "[enable/disable] {id}";
|
|
@ -1,8 +1,9 @@
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (!args[0].match(/^\d+$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
|
if (!args[0].match(/^<?[@#]?[&!]?\d+>?$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
|
||||||
try {
|
try {
|
||||||
await message.channel.guild.banMember(args[0], 0, `hackban command used by @${message.author.username}#${message.author.discriminator}`);
|
const id = args[0].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");
|
||||||
return `Successfully banned user with ID \`${args[0]}\`.`;
|
await message.channel.guild.banMember(id, 0, `Hackban command used by @${message.author.username}#${message.author.discriminator}`);
|
||||||
|
return `Successfully banned user with ID \`${id}\`.`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
//return `${message.author.mention}, I was unable to ban the member. Have you given me permissions?`;
|
//return `${message.author.mention}, I was unable to ban the member. Have you given me permissions?`;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (!args[0]) return `${message.author.mention}, you need to provide a snowflake ID!`;
|
if (!args[0]) return `${message.author.mention}, you need to provide a snowflake ID!`;
|
||||||
if (!args[0].match(/^\d+$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
|
if (!args[0].match(/^<?[@#]?[&!]?\d+>?$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
|
||||||
return new Date((args[0] / 4194304) + 1420070400000).toUTCString();
|
return new Date((args[0].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "") / 4194304) + 1420070400000).toUTCString();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.aliases = ["timestamp", "snowstamp", "snow"];
|
exports.aliases = ["timestamp", "snowstamp", "snow"];
|
||||||
|
|
|
@ -10,7 +10,8 @@ module.exports = async (guild) => {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
tags: misc.tagDefaults,
|
tags: misc.tagDefaults,
|
||||||
prefix: "&",
|
prefix: "&",
|
||||||
warns: {}
|
warns: {},
|
||||||
|
disabledChannels: []
|
||||||
});
|
});
|
||||||
await guildDB.save();
|
await guildDB.save();
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,27 +14,12 @@ module.exports = async (message) => {
|
||||||
if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
|
if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
|
||||||
|
|
||||||
// prefix can be a mention or a set of special characters
|
// prefix can be a mention or a set of special characters
|
||||||
|
const guildDB = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||||
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
|
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
|
||||||
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : (await database.guilds.find({ id: message.channel.guild.id }).exec())[0].prefix;
|
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.prefix;
|
||||||
|
|
||||||
// ignore other stuff
|
// ignore other stuff
|
||||||
if (message.content.startsWith(prefix) === false) return;
|
if (message.content.startsWith(prefix) === false) return;
|
||||||
// && message.channel.id !== "573553254575898626"
|
|
||||||
|
|
||||||
// funny stuff
|
|
||||||
/*if (message.channel.id === "573553254575898626" && message.channel.guild.id === "433408970955423765") {
|
|
||||||
const generalChannel = client.guilds.get("631290275456745502").channels.get("631290275888627713");
|
|
||||||
if (message.attachments.length !== 0) {
|
|
||||||
const attachments = [];
|
|
||||||
for (const attachment of message.attachments) {
|
|
||||||
const res = await require("node-fetch")(attachment.url);
|
|
||||||
attachments.push({ file: await res.buffer(), name: attachment.filename });
|
|
||||||
}
|
|
||||||
await client.createMessage(generalChannel.id, message.content, attachments);
|
|
||||||
} else {
|
|
||||||
await client.createMessage(generalChannel.id, message.content);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// separate commands and args
|
// separate commands and args
|
||||||
const prefixRegex = new RegExp(`^(${misc.regexEscape(prefix)})`);
|
const prefixRegex = new RegExp(`^(${misc.regexEscape(prefix)})`);
|
||||||
|
@ -42,6 +27,9 @@ module.exports = async (message) => {
|
||||||
const args = content.split(/ +/g);
|
const args = content.split(/ +/g);
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
|
// don't run if message is in a disabled channel
|
||||||
|
if (guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
|
||||||
|
|
||||||
// check if command exists
|
// check if command exists
|
||||||
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
|
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
|
||||||
if (!cmd) return;
|
if (!cmd) return;
|
||||||
|
|
102
events/ready.js
102
events/ready.js
|
@ -5,29 +5,42 @@ const database = require("../utils/database.js");
|
||||||
const logger = require("../utils/logger.js");
|
const logger = require("../utils/logger.js");
|
||||||
const messages = require("../messages.json");
|
const messages = require("../messages.json");
|
||||||
const misc = require("../utils/misc.js");
|
const misc = require("../utils/misc.js");
|
||||||
const helpGenerator = process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
|
const helpGenerator =
|
||||||
const twitter = process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
|
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
|
||||||
|
const twitter =
|
||||||
|
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
|
||||||
|
|
||||||
// run when ready
|
// run when ready
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
// make sure settings/tags exist
|
// make sure settings/tags exist
|
||||||
for (const [id] of client.guilds) {
|
for (const [id] of client.guilds) {
|
||||||
const guildDB = (await database.guilds.find({
|
const guildDB = (
|
||||||
id: id
|
await database.guilds
|
||||||
}).exec())[0];
|
.find({
|
||||||
|
id: id,
|
||||||
|
})
|
||||||
|
.exec()
|
||||||
|
)[0];
|
||||||
if (!guildDB) {
|
if (!guildDB) {
|
||||||
logger.log(`Registering guild database entry for guild ${id}...`);
|
logger.log(`Registering guild database entry for guild ${id}...`);
|
||||||
const newGuild = new database.guilds({
|
const newGuild = new database.guilds({
|
||||||
id: id,
|
id: id,
|
||||||
tags: misc.tagDefaults,
|
tags: misc.tagDefaults,
|
||||||
prefix: "&",
|
prefix: "&",
|
||||||
warns: {}
|
warns: {},
|
||||||
|
disabledChannels: []
|
||||||
});
|
});
|
||||||
await newGuild.save();
|
await newGuild.save();
|
||||||
} else if (guildDB && !guildDB.warns) {
|
} else if (guildDB) {
|
||||||
|
if (!guildDB.warns) {
|
||||||
logger.log(`Creating warn object for guild ${id}...`);
|
logger.log(`Creating warn object for guild ${id}...`);
|
||||||
guildDB.set("warns", {});
|
guildDB.set("warns", {});
|
||||||
await guildDB.save();
|
await guildDB.save();
|
||||||
|
} else if (!guildDB.disabledChannels) {
|
||||||
|
logger.log(`Creating disabled channels object for guild ${id}...`);
|
||||||
|
guildDB.set("disabledChannels", []);
|
||||||
|
await guildDB.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +52,7 @@ module.exports = async () => {
|
||||||
// set activity (a.k.a. the gamer code)
|
// set activity (a.k.a. the gamer code)
|
||||||
(async function activityChanger() {
|
(async function activityChanger() {
|
||||||
client.editStatus("dnd", {
|
client.editStatus("dnd", {
|
||||||
name: `${misc.random(messages)} | @esmBot help`
|
name: `${misc.random(messages)} | @esmBot help`,
|
||||||
});
|
});
|
||||||
setTimeout(activityChanger, 900000);
|
setTimeout(activityChanger, 900000);
|
||||||
})();
|
})();
|
||||||
|
@ -49,11 +62,20 @@ module.exports = async () => {
|
||||||
gm.prototype.streamPromise = promisify(gm.prototype.stream);
|
gm.prototype.streamPromise = promisify(gm.prototype.stream);
|
||||||
gm.prototype.sizePromise = promisify(gm.prototype.size);
|
gm.prototype.sizePromise = promisify(gm.prototype.size);
|
||||||
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
|
gm.prototype.identifyPromise = promisify(gm.prototype.identify);
|
||||||
//gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
|
|
||||||
gm.prototype.bufferPromise = function(format, delay, type) {
|
gm.prototype.bufferPromise = function(format, delay, type) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (format) {
|
this.in(
|
||||||
this.in(delay ? "-delay" : "", delay ? delay.split("/").reverse().join("x") : "").out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").out("-limit", "memory", "64MB").out("-limit", "map", "128MB").stream(format, (err, stdout, stderr) => {
|
delay ? "-delay" : "",
|
||||||
|
delay ? delay.split("/").reverse().join("x") : ""
|
||||||
|
)
|
||||||
|
.out(
|
||||||
|
type !== "sonic" ? "-layers" : "",
|
||||||
|
type !== "sonic" ? "OptimizeTransparency" : ""
|
||||||
|
)
|
||||||
|
.out("-fuzz", "2%")
|
||||||
|
.out("-limit", "memory", "64MB")
|
||||||
|
.out("-limit", "map", "128MB")
|
||||||
|
.stream(format, (err, stdout, stderr) => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
stdout.on("data", (chunk) => {
|
stdout.on("data", (chunk) => {
|
||||||
|
@ -68,34 +90,20 @@ module.exports = async () => {
|
||||||
reject(data.toString());
|
reject(data.toString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.in(delay ? "-delay" : "", delay ? delay.split("/").reverse().join("x") : "").out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").out("-limit", "memory", "64MB").out("-limit", "map", "128MB").stream((err, stdout, stderr) => {
|
|
||||||
if (err) return reject(err);
|
|
||||||
const chunks = [];
|
|
||||||
stdout.on("data", (chunk) => {
|
|
||||||
chunks.push(chunk);
|
|
||||||
});
|
});
|
||||||
// these are 'once' because they can and do fire multiple times for multiple errors,
|
|
||||||
// but this is a promise so you'll have to deal with them one at a time
|
|
||||||
stdout.once("end", () => {
|
|
||||||
resolve(Buffer.concat(chunks));
|
|
||||||
});
|
|
||||||
stderr.once("data", (data) => {
|
|
||||||
reject(data.toString());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// tweet stuff
|
// tweet stuff
|
||||||
if (twitter !== null && twitter.active === false) {
|
if (twitter !== null && twitter.active === false) {
|
||||||
const blocks = await twitter.client.blocks.ids();
|
const blocks = await twitter.client.blocks.ids();
|
||||||
const tweet = async () => {
|
const tweet = async () => {
|
||||||
const tweets = (await database.tweets.find({
|
const tweets = (
|
||||||
enabled: true
|
await database.tweets
|
||||||
}).exec())[0];
|
.find({
|
||||||
|
enabled: true,
|
||||||
|
})
|
||||||
|
.exec()
|
||||||
|
)[0];
|
||||||
const tweetContent = await misc.getTweet(tweets);
|
const tweetContent = await misc.getTweet(tweets);
|
||||||
try {
|
try {
|
||||||
const info = await twitter.client.statuses.update(tweetContent);
|
const info = await twitter.client.statuses.update(tweetContent);
|
||||||
|
@ -115,19 +123,32 @@ module.exports = async () => {
|
||||||
twitter.active = true;
|
twitter.active = true;
|
||||||
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
||||||
stream.on("data", async (tweet) => {
|
stream.on("data", async (tweet) => {
|
||||||
if (tweet.user.screen_name !== "esmBot_" && !blocks.ids.includes(tweet.user.id_str)) {
|
if (
|
||||||
const tweets = (await database.tweets.find({
|
tweet.user.screen_name !== "esmBot_" &&
|
||||||
enabled: true
|
!blocks.ids.includes(tweet.user.id_str)
|
||||||
}).exec())[0];
|
) {
|
||||||
|
const tweets = (
|
||||||
|
await database.tweets
|
||||||
|
.find({
|
||||||
|
enabled: true,
|
||||||
|
})
|
||||||
|
.exec()
|
||||||
|
)[0];
|
||||||
let tweetContent;
|
let tweetContent;
|
||||||
if (tweet.text.includes("@this_vid") || tweet.text.includes("@DownloaderBot") || tweet.text.includes("@GetVideoBot") || tweet.text.includes("@DownloaderB0t") || tweet.text.includes("@thisvid_")) {
|
if (
|
||||||
|
tweet.text.includes("@this_vid") ||
|
||||||
|
tweet.text.includes("@DownloaderBot") ||
|
||||||
|
tweet.text.includes("@GetVideoBot") ||
|
||||||
|
tweet.text.includes("@DownloaderB0t") ||
|
||||||
|
tweet.text.includes("@thisvid_")
|
||||||
|
) {
|
||||||
tweetContent = await misc.getTweet(tweet, true, true);
|
tweetContent = await misc.getTweet(tweet, true, true);
|
||||||
} else {
|
} else {
|
||||||
tweetContent = await misc.getTweet(tweets, true);
|
tweetContent = await misc.getTweet(tweets, true);
|
||||||
}
|
}
|
||||||
const payload = {
|
const payload = {
|
||||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||||
in_reply_to_status_id: tweet.id_str
|
in_reply_to_status_id: tweet.id_str,
|
||||||
};
|
};
|
||||||
const info = await twitter.client.statuses.update(payload);
|
const info = await twitter.client.statuses.update(payload);
|
||||||
logger.log(`Reply with id ${info.id_str} has been posted.`);
|
logger.log(`Reply with id ${info.id_str} has been posted.`);
|
||||||
|
@ -136,5 +157,8 @@ module.exports = async () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.log("info", `Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
|
logger.log(
|
||||||
|
"info",
|
||||||
|
`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`
|
||||||
|
);
|
||||||
};
|
};
|
|
@ -5,7 +5,8 @@ const guildSchema = new mongoose.Schema({
|
||||||
id: String,
|
id: String,
|
||||||
tags: Map,
|
tags: Map,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
warns: Map
|
warns: Map,
|
||||||
|
disabledChannels: [String]
|
||||||
});
|
});
|
||||||
const Guild = mongoose.model("Guild", guildSchema);
|
const Guild = mongoose.model("Guild", guildSchema);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue