make bot worse
This commit is contained in:
parent
5452cc79db
commit
991c46786f
|
@ -27,7 +27,7 @@ module.exports.run = async (message, args) => new Promise(async (resolve, reject
|
||||||
|
|
||||||
const response = `${target ? `${target.username} is` : 'You are'} level **${level}** with **${xp}** XP. `
|
const response = `${target ? `${target.username} is` : 'You are'} level **${level}** with **${xp}** XP. `
|
||||||
+ `XP required for level up: **${levelups.find(l => l > xp) - xp}**.\n`
|
+ `XP required for level up: **${levelups.find(l => l > xp) - xp}**.\n`
|
||||||
+ (process.env.DISABLE_LEVELS ? '**Warning:** You can\'t currently gain XP on this instance.' : '');
|
+ (process.env.DISABLE_LEVELS === 'true' ? '**Warning:** You can\'t currently gain XP on this instance.' : '');
|
||||||
|
|
||||||
client.channels.sendMessage(message.channel, response)
|
client.channels.sendMessage(message.channel, response)
|
||||||
.catch(console.warn);
|
.catch(console.warn);
|
||||||
|
|
1198
package-lock.json
generated
1198
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -9,6 +9,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"bad-words": "^3.0.4",
|
||||||
"better-sqlite3": "^7.1.2",
|
"better-sqlite3": "^7.1.2",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"log75": "^2.0.1",
|
"log75": "^2.0.1",
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
const Enmap = require('enmap');
|
const Enmap = require('enmap');
|
||||||
const { client, logger, config, db } = require('..');
|
const { client, logger, config, db } = require('..');
|
||||||
|
let Filter = require('bad-words'),
|
||||||
|
filter = new Filter();
|
||||||
|
|
||||||
const levels = new Enmap({ name: "levels" });
|
const levels = new Enmap({ name: "levels" });
|
||||||
let cooldowns = {}
|
let cooldowns = {}
|
||||||
|
|
||||||
if (process.env.DISABLE_LEVELS) logger.info('DISABLE_LEVELS is set, users won\'t be able to gain XP.');
|
if (process.env.DISABLE_LEVELS === 'true') logger.info('DISABLE_LEVELS is set, users won\'t be able to gain XP.');
|
||||||
|
|
||||||
client.on('message', async message => {
|
client.on('message', async message => {
|
||||||
if (process.env.DISABLE_LEVELS) return;
|
if (process.env.DISABLE_LEVELS === 'true') return;
|
||||||
|
|
||||||
if (message.author === client.user._id) return;
|
if (message.author === client.user._id) return;
|
||||||
try {
|
try {
|
||||||
|
@ -18,14 +20,22 @@ client.on('message', async message => {
|
||||||
let userLevels = levels.get(message.author);
|
let userLevels = levels.get(message.author);
|
||||||
if (!userLevels) userLevels = { xp: 0, level: 0 }
|
if (!userLevels) userLevels = { xp: 0, level: 0 }
|
||||||
|
|
||||||
if (userLevels.enabled === false) return;
|
let xpDiff = 0;
|
||||||
|
if (process.env.DISABLE_PROFANITY_FILTER !== 'true' && filter.isProfane(message.content)) {
|
||||||
|
// Take a random amount of XP between 5 and 15
|
||||||
|
xpDiff = (5 + Math.round(Math.random() * 10)) * -1;
|
||||||
|
}
|
||||||
|
else if (cooldowns[message.author] <= Date.now()) {
|
||||||
|
// Ensure users only get XP once a minute
|
||||||
|
cooldowns[message.author] = Date.now() + 1000 * 60;
|
||||||
|
// Give a random amount of XP between 15 and 25
|
||||||
|
xpDiff += 15 + Math.round(Math.random() * 10);
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure users only get XP once a minute
|
if (xpDiff !== 0) {
|
||||||
if (cooldowns[message.author] > Date.now()) return;
|
logger.debug(`${message.author} => ${xpDiff} XP`);
|
||||||
cooldowns[message.author] = Date.now() + 1000 * 60;
|
userLevels.xp += xpDiff;
|
||||||
|
}
|
||||||
// Give a random amount of XP between 15 and 25
|
|
||||||
userLevels.xp += 15 + Math.round(Math.random() * 10);
|
|
||||||
|
|
||||||
let newLevel = 0;
|
let newLevel = 0;
|
||||||
for (const i of levelups) userLevels.xp >= i && newLevel++;
|
for (const i of levelups) userLevels.xp >= i && newLevel++;
|
||||||
|
@ -35,10 +45,15 @@ client.on('message', async message => {
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
.then(msg => setTimeout(() =>
|
.then(msg => setTimeout(() =>
|
||||||
client.channels.deleteMessage(channel._id, msg?._id).catch(console.warn), 15000));
|
client.channels.deleteMessage(channel._id, msg?._id).catch(console.warn), 15000));
|
||||||
|
}
|
||||||
userLevels.level = newLevel;
|
else if (newLevel < userLevels.level) {
|
||||||
|
client.channels.sendMessage(message.channel, `> GG <@${message.author}>, you posted so much cringe that you just lost a level! You are now level **${newLevel}**.`)
|
||||||
|
.catch(console.error)
|
||||||
|
.then(msg => setTimeout(() =>
|
||||||
|
client.channels.deleteMessage(channel._id, msg?._id).catch(console.warn), 15000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userLevels.level = newLevel;
|
||||||
levels.set(message.author, userLevels);
|
levels.set(message.author, userLevels);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
Loading…
Reference in a new issue