Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving XP boost event from local #300

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add xp boost system
kdspa committed Nov 28, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 893cd598150eb79a572a1fc6975749e47c595482
1 change: 1 addition & 0 deletions src/modules/Events/Events.js
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ module.exports = {
FakeBan: require('./Misc/FakeBan'),
JoinMessages: require('./Misc/JoinMessages'),
// LevelUp: require('./Misc/LevelUp'),
XPBoost: require('./Misc/XPBoost'),
// UpdateScore: require('./Misc/UpdateScore'),

// === Role Handling ===
65 changes: 65 additions & 0 deletions src/modules/Events/Misc/XPBoost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { Tatsu } = require('tatsu');
const tatsu = new Tatsu(process.env.TATSU_KEY);

const { Listener } = require('axoncore');

class XPBoost extends Listener {
/**
* @param {import('axoncore').Module} module
* @param {import('axoncore').ListenerData} data
*/
constructor(module, data = {} ) {
super(module, data);

/** Event Name (Discord name) */
this.eventName = 'messageCreate';
/** Event name (Function name) */
this.label = 'XPBoost';

this.enabled = true;

this.avatarGuild = '370708369951948800';

this.allowedUsers = [];
this.allowedChannels = [];
this.allowedRoles = [];

this.info = {
description: 'Experimental feature to grant XP multipliers to random users.',
};
}

/**
* @description Checks if a given member is whitelisted for the XP bonus.
* @param {import('eris').Member} member
* @returns boolean
*/
async isAllowed(m) {
if (
this.allowedChannels.includes(m.channel.id) ||
this.allowedUsers.includes(m.member.id) || // checks if user is whitelisted
this.allowedRoles.some(r => m.member.roles.includes(r)) // checks if user has a whitelisted role
) return true;

// TEST FLAGS
if (m.member.user.id.startsWith('2')) return true; // accounts created between July 2016 and April 2017.
return false; // no whitelist? no bonus.
}

/**
* @param {import('eris').Message} msg
*/
async execute(msg) { // eslint-disable-line
const MAX = 20;
const MIN = 10;
let ranking = await tatsu.getMemberRanking(this.avatarGuild, msg.author.id);

if (msg.author.bot) return;
if (await this.isAllowed(msg)) {
let xp = Math.floor(Math.random() * (MAX - MIN + 1) + MIN);
await tatsu.addGuildMemberScore(this.avatarGuild, msg.author.id, xp)
}
}
}

module.exports = XPBoost;