Added snowflake and experimental xp system, made logger easier to use
This commit is contained in:
parent
606c1ea1dc
commit
171253c52c
12 changed files with 137 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
|||
const database = require("../utils/database.js");
|
||||
|
||||
exports.run = async (message) => {
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
return `${message.author.mention}, my command list can be found here: https://essem.space/esmBot/commands.html?dev=true\nThis server's prefix is \`${guild.prefix}\`.`;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const database = require("../utils/database.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
if (args.length !== 0) {
|
||||
if (!message.member.permission.has("administrator") && message.member.id !== "198198681982205953") return `${message.author.mention}, you need to be an administrator to change the bot prefix!`;
|
||||
guild.set("prefix", args[0]);
|
||||
|
|
|
@ -5,12 +5,7 @@ exports.run = async (message, args) => {
|
|||
if (!message.channel.guild.members.get(client.user.id).permission.has("manageMessages") && !message.channel.permissionsOf(client.user.id).has("manageMessages")) return `${message.author.mention}, I don't have the \`Manage Messages\` permission!`;
|
||||
if (args.length === 0 || !args[0].match(/^\d+$/)) return `${message.author.mention}, you need to provide the number of messages to purge!`;
|
||||
const numberOfMessages = parseInt(args[0]) + 1;
|
||||
const messageCollection = await message.channel.getMessages(numberOfMessages);
|
||||
const messages = [];
|
||||
for (const messageObject of messageCollection) {
|
||||
messages.push(messageObject.id);
|
||||
}
|
||||
await message.channel.deleteMessages(messages);
|
||||
await message.channel.purge(numberOfMessages);
|
||||
const purgeMessage = await message.channel.createMessage(`Successfully purged ${args[0]} messages.`);
|
||||
await require("util").promisify(setTimeout)(10000);
|
||||
await purgeMessage.delete();
|
||||
|
|
6
commands/snowflake.js
Normal file
6
commands/snowflake.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
exports.run = async (message, args) => {
|
||||
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();
|
||||
};
|
||||
|
||||
exports.aliases = ["timestamp", "snowstamp", "snow"];
|
|
@ -5,28 +5,28 @@ const paginator = require("../utils/pagination/pagination.js");
|
|||
const { random } = require("../utils/misc.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const tags = guild.tags;
|
||||
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "add":
|
||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`;
|
||||
if (blacklist.indexOf(args[1].toLowerCase()) > -1) return `${message.author.mention}, you can't make a tag with that name!`;
|
||||
if (tags.exists(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
||||
if (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
|
||||
case "delete":
|
||||
case "remove":
|
||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`;
|
||||
if (!tags.exists(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags[args[1].toLowerCase()].author !== message.author.id && tags[args[1].toLowerCase()].author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags.get(args[1].toLowerCase()).author !== message.author.id && tags.get(args[1].toLowerCase()).author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
tags.set(args[1].toLowerCase(), undefined);
|
||||
await guild.save();
|
||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
|
||||
case "edit":
|
||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to edit!`;
|
||||
if (!tags.exists(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags[args[1].toLowerCase()].author !== message.author.id && tags[args[1].toLowerCase()].author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags.get(args[1].toLowerCase()).author !== message.author.id && tags.get(args[1].toLowerCase()).author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
||||
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
|
||||
case "list":
|
||||
|
@ -34,11 +34,11 @@ exports.run = async (message, args) => {
|
|||
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
||||
var pageSize = 15;
|
||||
var embeds = [];
|
||||
console.log(Array.from(tags.keys()));
|
||||
var groups = Array.from(tags.keys()).map((item, index) => {
|
||||
return index % pageSize === 0 ? Array.from(tags.keys()).slice(index, index + pageSize) : null;
|
||||
}).filter((item) => {
|
||||
return item;
|
||||
});
|
||||
console.log(groups);
|
||||
for (const [i, value] of groups.entries()) {
|
||||
embeds.push({
|
||||
"embed": {
|
||||
|
@ -61,8 +61,8 @@ exports.run = async (message, args) => {
|
|||
return tags[random(Object.keys(tags))].content;
|
||||
default:
|
||||
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
|
||||
if (!tags.exists(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
return tags[`${args[0].toLowerCase()}.content`];
|
||||
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
return tags.get(args[0].toLowerCase()).content;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const Guild = require("../utils/database.js");
|
||||
const db = require("../utils/database.js");
|
||||
const logger = require("../utils/logger.js");
|
||||
const misc = require("../utils/misc.js");
|
||||
const client = require("../utils/client.js");
|
||||
|
@ -6,10 +6,23 @@ const client = require("../utils/client.js");
|
|||
// run when the bot is added to a guild
|
||||
module.exports = async (guild) => {
|
||||
logger.log("info", `[GUILD JOIN] ${guild.name} (${guild.id}) added the bot. Owner: ${client.users.get(guild.ownerID).username}#${client.users.get(guild.ownerID).discriminator} (${guild.ownerID})`);
|
||||
const guildDB = new Guild({
|
||||
const guildDB = new db.guilds({
|
||||
id: guild.id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: "&"
|
||||
});
|
||||
await guildDB.save();
|
||||
const memberInfo = {};
|
||||
for (const member of guild.members) {
|
||||
memberInfo[member.id] = {
|
||||
xpAmount: 0,
|
||||
level: 0
|
||||
};
|
||||
}
|
||||
const xpDB = new db.xp({
|
||||
id: guild.id,
|
||||
members: memberInfo,
|
||||
enabled: false
|
||||
});
|
||||
await guildDB.save();
|
||||
await xpDB.save();
|
||||
};
|
||||
|
|
|
@ -12,16 +12,58 @@ module.exports = async (message) => {
|
|||
|
||||
// prefix can be a mention or a set of special characters
|
||||
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
|
||||
const guildConf = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const guildConf = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildConf.prefix;
|
||||
|
||||
// xp stuff
|
||||
const xp = (await database.xp.find({ id: message.channel.guild.id }).exec())[0];
|
||||
if (xp.enabled === true) {
|
||||
//console.log(xp.members);
|
||||
const info = xp.members.get(message.author.id);
|
||||
if (!info) {
|
||||
logger.log("Member not in XP database, adding");
|
||||
const memberInfo = {
|
||||
xpAmount: 1,
|
||||
level: 0
|
||||
};
|
||||
xp.members.set(message.author.id, memberInfo);
|
||||
await xp.save();
|
||||
} else {
|
||||
let newLevel;
|
||||
const newAmount = info.xpAmount + 1;
|
||||
//xp.members[message.author.id].xpAmount++;
|
||||
const level = Math.floor(0.1 * Math.sqrt(newAmount));
|
||||
if (info.level < level) {
|
||||
newLevel = info.level++;
|
||||
//xp.members[message.author.id].level++;
|
||||
logger.log(`${message.author.username} has leveled up`);
|
||||
if (message.channel.guild.id === "631290275456745502" && level === 5) {
|
||||
await message.author.addRole("638759280752853022", "level 5");
|
||||
await message.channel.createMessage(`${message.author.mention} just leveled up to level ${level}... AND unlocked the better members role!`);
|
||||
} else if (message.channel.guild.id === "631290275456745502" && level === 10) {
|
||||
await message.author.addRole("638822807626711078", "level 10");
|
||||
await message.channel.createMessage(`${message.author.mention} just leveled up to level ${level}... AND unlocked the even better members role!`);
|
||||
} else if (message.channel.guild.id === "631290275456745502" && level === 25) {
|
||||
await message.author.addRole("631299545657114645", "level 25");
|
||||
await message.channel.createMessage(`${message.author.mention} just leveled up to level ${level}... AND unlocked the best members role!`);
|
||||
} else {
|
||||
await message.channel.createMessage(`${message.author.mention} just leveled up to level ${level}!`);
|
||||
}
|
||||
}
|
||||
xp.members.set(message.author.id, {
|
||||
xpAmount: newAmount,
|
||||
level: newLevel ? newLevel : info.level
|
||||
});
|
||||
await xp.save();
|
||||
}
|
||||
}
|
||||
|
||||
// ignore other stuff
|
||||
// && !message.attachments && message.attachments[0].filename !== "1561668913236-3.gif"
|
||||
if (message.content.startsWith(prefix) === false && message.mentions.indexOf(client.user) <= -1 && message.channel.id !== "573553254575898626" && (!message.content.match(/https?:\/\/(media|cdn)\.discordapp\.(net|com)\/attachments\/596766080014221373\/606176845871972383\/1561668913236-3.gif/))) return;
|
||||
|
||||
// funny stuff
|
||||
if (message.channel.id === "573553254575898626" && message.channel.guild.id === "433408970955423765") {
|
||||
const generalChannel = client.guilds.get("322114245632327703").channels.get("322114245632327703");
|
||||
const generalChannel = client.guilds.get("631290275456745502").channels.get("631290275888627713");
|
||||
if (message.attachments.length !== 0) {
|
||||
const attachments = [];
|
||||
for (const attachment of message.attachments) {
|
||||
|
|
|
@ -7,22 +7,43 @@ const misc = require("../utils/misc.js");
|
|||
// run when ready
|
||||
module.exports = async () => {
|
||||
// make sure settings/tags exist
|
||||
for (const guild of client.guilds) {
|
||||
const guildDB = (await database.find({ id: guild.id }).exec())[0];
|
||||
for (const [id, guild] of client.guilds) {
|
||||
const guildDB = (await database.guilds.find({ id: id }).exec())[0];
|
||||
const xpDB = (await database.xp.find({ id: id }).exec())[0];
|
||||
// .length === 0 && guildDB.constructor === Object
|
||||
// !Object.entries(guildDB)
|
||||
if (!guildDB) {
|
||||
console.log(`Registering database entry for ${guild.id}...`);
|
||||
const newGuild = new database({
|
||||
id: guild.id,
|
||||
console.log(`Registering guild database entry for guild ${id}...`);
|
||||
const newGuild = new database.guilds({
|
||||
id: id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: "&"
|
||||
});
|
||||
await newGuild.save();
|
||||
}
|
||||
// .length === 0 && xpDB.constructor === Object
|
||||
// !Object.entries(xpDB)
|
||||
if (!xpDB) {
|
||||
console.log(`Registering xp database entry for guild ${id}...`);
|
||||
const memberInfo = {};
|
||||
for (const [id] of guild.members) {
|
||||
memberInfo[id] = {
|
||||
xpAmount: 0,
|
||||
level: 0
|
||||
};
|
||||
}
|
||||
const newXP = new database.xp({
|
||||
id: id,
|
||||
members: memberInfo,
|
||||
enabled: false
|
||||
});
|
||||
await newXP.save();
|
||||
}
|
||||
}
|
||||
|
||||
// set activity (a.k.a. the gamer code)
|
||||
(async function activityChanger() {
|
||||
client.editStatus("dnd", { name: `${misc.random(config.activityMessages)} | @esmBot help` });
|
||||
client.editStatus("dnd", { name: `${misc.random(config.activityMessages)} | @esmBot help`, url: "https://essem.space/esmBot/commands.html?dev=true" });
|
||||
setTimeout(activityChanger, 900000);
|
||||
})();
|
||||
|
||||
|
|
27
package-lock.json
generated
27
package-lock.json
generated
|
@ -25,9 +25,9 @@
|
|||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.7.tgz",
|
||||
"integrity": "sha512-JNbGaHFCLwgHn/iCckiGSOZ1XYHsKFwREtzPwSGCVld1SGhOlmZw2D4ZI94HQCrBHbADzW9m4LER/8olJTRGHA=="
|
||||
"version": "12.12.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.5.tgz",
|
||||
"integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A=="
|
||||
},
|
||||
"abort-controller": {
|
||||
"version": "3.0.0",
|
||||
|
@ -290,6 +290,11 @@
|
|||
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
|
||||
"integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw="
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
|
||||
},
|
||||
"bufferutil": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.1.tgz",
|
||||
|
@ -661,7 +666,7 @@
|
|||
"integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA=="
|
||||
},
|
||||
"eris": {
|
||||
"version": "github:abalabahaha/eris#e484725f88896bfcb22dbdb6683138c0ba36e1da",
|
||||
"version": "github:abalabahaha/eris#152784360098beb27c1847bff1807615fa2cc185",
|
||||
"from": "github:abalabahaha/eris#dev",
|
||||
"requires": {
|
||||
"opusscript": "^0.0.4",
|
||||
|
@ -1978,10 +1983,12 @@
|
|||
"dev": true
|
||||
},
|
||||
"qrcode": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.4.2.tgz",
|
||||
"integrity": "sha512-eR6RgxFYPDFH+zFLTJKtoNP/RlsHANQb52AUmQ2bGDPMuUw7jJb0F+DNEgx7qQGIElrbFxWYMc0/B91zLZPF9Q==",
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.4.3.tgz",
|
||||
"integrity": "sha512-a2T3TwrzIW6Zbfe+h4mI9awWgLmW9OyyUQzF5ra0EAKCcXscHEKMrBPGku+jIlNh9YkwgjVOsf25HdU6+TJ2tw==",
|
||||
"requires": {
|
||||
"buffer-alloc": "^1.2.0",
|
||||
"buffer-from": "^1.1.1",
|
||||
"dijkstrajs": "^1.0.1",
|
||||
"isarray": "^2.0.1",
|
||||
"pngjs": "^3.3.0",
|
||||
|
@ -2769,9 +2776,9 @@
|
|||
}
|
||||
},
|
||||
"zlib-sync": {
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.5.tgz",
|
||||
"integrity": "sha512-+i+0BAu0fGs9hjImLWGJ6UXCLVj7VS9XBEYRot/pdFbVoUgqV2CFBRdrgsKLjIbbwHVXxHyESLhZcCx3eoFH5w==",
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.6.tgz",
|
||||
"integrity": "sha512-B2XGrhlXs/izEks+705vn/aL+nWyPgnS1glyCeH8wgZdOvztRn3ZEdqclj6GoJSeA/iRSqaTlznG2KO1M/GuWg==",
|
||||
"requires": {
|
||||
"nan": "^2.14.0"
|
||||
},
|
||||
|
|
|
@ -31,12 +31,12 @@
|
|||
"mongoose": "^5.7.7",
|
||||
"node-fetch": "^2.6.0",
|
||||
"node-opus": "^0.3.3",
|
||||
"qrcode": "^1.4.2",
|
||||
"qrcode": "^1.4.3",
|
||||
"retrotext": "github:TheEssem/retrotext",
|
||||
"sharp": "^0.22.1",
|
||||
"uws": "^10.148.1",
|
||||
"winston": "^3.2.1",
|
||||
"zlib-sync": "^0.1.5"
|
||||
"zlib-sync": "^0.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.15.2",
|
||||
|
|
|
@ -8,4 +8,14 @@ const guildSchema = new mongoose.Schema({
|
|||
prefix: String
|
||||
});
|
||||
const Guild = mongoose.model("Guild", guildSchema);
|
||||
module.exports = Guild;
|
||||
/*const membersSchema = new mongoose.Schema({
|
||||
|
||||
});*/
|
||||
const xpSchema = new mongoose.Schema({
|
||||
id: String,
|
||||
members: Map,
|
||||
enabled: Boolean
|
||||
});
|
||||
const XP = mongoose.model("XP", xpSchema);
|
||||
exports.guilds = Guild;
|
||||
exports.xp = XP;
|
|
@ -9,7 +9,7 @@ const logger = winston.createLogger({
|
|||
format: winston.format.printf(log => `[${moment().format("YYYY-MM-DD HH:mm:ss")}]: [${log.level.toUpperCase()}] - ${log.message}`)
|
||||
});
|
||||
|
||||
exports.log = (type = "info", content) => logger.log(type, content);
|
||||
exports.log = (type, content) => content ? logger.log(type, content) : logger.log("info", content);
|
||||
|
||||
exports.error = (...args) => this.log("error", ...args);
|
||||
|
||||
|
|
Loading…
Reference in a new issue