Skip to content

Commit

Permalink
Merge branch 'master' into 733-mm-ui-fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
tro2 committed Feb 28, 2024
2 parents d4923c7 + c5f719a commit 8afa12c
Show file tree
Hide file tree
Showing 27 changed files with 923 additions and 945 deletions.
6 changes: 0 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ commands/changename.js
commands/check.js
commands/commands.js
commands/commend.js
commands/complete.js
commands/crasherList.js
commands/emoji.js
commands/eval.js
commands/excuse.js
commands/glape.js
commands/headcount.js
commands/id.js
commands/keyRoles.js
commands/leaderboard.js
commands/leaveGuild.js
commands/list.js
Expand All @@ -25,7 +23,6 @@ commands/manualVetVerify.js
commands/memes.js
commands/modmailBlacklist.js
commands/mute.js
commands/mutes.js
commands/parsemembers.js
commands/permaSuspend.js
commands/poll.js
Expand All @@ -44,20 +41,17 @@ commands/setStatus.js
commands/status.js
commands/suspend.js
commands/suspendremove.js
commands/suspends.js
commands/sysinfo.js
commands/test.js
commands/unlock.js
commands/unmute.js
commands/unsuspend.js
commands/unverify.js
commands/unvetverify.js
commands/updateIP.js
commands/verification.js
commands/vetVerification.js
commands/vibotChannels.js
commands/warnRemove.js
commands/warns.js
jobs/runner.js
lib/API.js
lib/extensions.js
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ data/restart_channel.json
debug.log
.DS_Store
ml/save/
ml/models/
ml/models/
build/
59 changes: 25 additions & 34 deletions botMeta.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
const Discord = require('discord.js');
const fs = require('fs');
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { rateLimitLogger } = require('./lib/rateLimitLogger');
const bot = new Discord.Client({

const bot = new Client({
intents: [ // Discord moment
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildBans,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildWebhooks,
Discord.GatewayIntentBits.GuildInvites,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildPresences,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMessageTyping,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.DirectMessageTyping,
Discord.GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
],
partials: [
Discord.Partials.User,
Discord.Partials.Channel,
Discord.Partials.GuildMember,
Discord.Partials.Message,
Discord.Partials.Reaction
Partials.User,
Partials.Channel,
Partials.GuildMember,
Partials.Message,
Partials.Reaction
]
});

rateLimitLogger(bot);

bot.commands = new Discord.Collection();
bot.afkChecks = {};
bot.afkModules = {};
bot.settings = moduleIsAvailable('./guildSettings.json') ? require('./guildSettings.json') : {};
Expand All @@ -49,14 +48,6 @@ bot.emojiServers = moduleIsAvailable('./data/emojiServers.json') ? require('./da
bot.devServers = ['739623118833713214'];
bot.storedEmojis = moduleIsAvailable('./data/emojis.json') ? require('./data/emojis.json') : {};

function loadCommands() {
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
}

function moduleIsAvailable(path) {
try {
require.resolve(path);
Expand All @@ -67,4 +58,4 @@ function moduleIsAvailable(path) {
}
}

module.exports = { bot, loadCommands };
module.exports = { bot };
3 changes: 2 additions & 1 deletion botSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const redisConnect = require('./redis.js').setup;
const botSettings = require('./settings.json');
const ErrorLogger = require('./lib/logError');
// Commands
const { commands } = require('./lib/commands');
const emoji = require('./commands/emoji.js');
const afkCheck = require('./commands/afkCheck.js');
const vibotChannels = require('./commands/vibotChannels');
Expand All @@ -27,7 +28,7 @@ const dbSetup = require('./dbSetup.js');

async function deployCommands(bot, guild) {
// Organize commands
const slashCommands = bot.commands.filter(c => c.getSlashCommandData).map(c => c.getSlashCommandData(guild)).filter(c => c).flat();
const slashCommands = commands.filter(c => c.getSlashCommandData).map(c => c.getSlashCommandData(guild)).filter(c => c).flat();

// Deploy commands
const rest = new Discord.REST({ version: '10' }).setToken(require('./settings.json').key);
Expand Down
55 changes: 38 additions & 17 deletions commands/afkCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const extensions = require(`../lib/extensions`)
const consumablePopTemplates = require(`../data/keypop.json`);
const popCommand = require('./pop.js');
const AfkButton = require('../lib/afk/AfkButton');
const { writePoint } = require('../metrics.js');
const { Point } = require('@influxdata/influxdb-client');

module.exports = {
name: 'afk',
Expand Down Expand Up @@ -80,6 +82,9 @@ module.exports = {
console.log(afkTemplate.message())
continue
}
writePoint(new Point('afkchecksmodules')
.tag('raidID', currentStoredAfkCheck.raidID)
.stringField('module', 'insert'))
bot.afkModules[currentStoredAfkCheck.raidID] = new afkCheck(afkTemplate, bot, db, message, currentStoredAfkCheck.location)
await bot.afkModules[currentStoredAfkCheck.raidID].loadBotAfkCheck(currentStoredAfkCheck)
}
Expand Down Expand Up @@ -120,8 +125,7 @@ class afkCheck {
this.#pointlogMid = null

this.members = [] // All members in the afk
this.earlyLocationMembers = [] // All members with early location in the afk
this.earlySlotMembers = [] // All members with early slots in the afk
this.staffEarlyMembers = [] // Staff members who clicked nitro to join the AFK
this.buttons = afkTemplate.buttons.map(button => new AfkButton(this.#botSettings, this.#bot.storedEmojis, this.#guild, button))
this.reactRequests = {} // {messageId => AfkButton}
this.cap = afkTemplate.cap
Expand Down Expand Up @@ -182,6 +186,9 @@ class afkCheck {
async start() {
if (this.phase === 0) this.phase = 1
this.timer = new Date(Date.now() + (this.#body[this.phase].timeLimit * 1000))
writePoint(new Point('afkchecksmodules')
.tag('raidID', this.#raidID)
.stringField('module', 'insert'))
this.#bot.afkModules[this.#raidID] = this
await Promise.all([this.sendStatusMessage(), this.sendCommandsMessage(), this.sendChannelsMessage()])
this.startTimers()
Expand All @@ -194,10 +201,17 @@ class afkCheck {

saveBotAfkCheck(deleteCheck = false) {
if (deleteCheck) {
writePoint(new Point('afkchecksmodules')
.tag('raidID', this.#raidID)
.stringField('check', 'delete')
.stringField('module', 'delete'))
delete this.#bot.afkChecks[this.#raidID]
delete this.#bot.afkModules[this.#raidID]
}
else {
writePoint(new Point('afkchecksmodules')
.tag('raidID', this.#raidID)
.stringField('check', 'create'))
this.#bot.afkChecks[this.#raidID] = {
afkTemplateName: this.afkTemplateName,
message: this.#message,
Expand All @@ -206,8 +220,7 @@ class afkCheck {
leader: this.#leader,
raidID: this.#raidID,
members: this.members,
earlyLocationMembers: this.earlyLocationMembers,
earlySlotMembers: this.earlySlotMembers,
staffEarlyMembers: this.staffEarlyMembers,
buttons: this.buttons.map(button => button.toJSON()),
reactRequests: Object.fromEntries(Object.entries(this.reactRequests).map(([messageId, button]) => [messageId, {name: button.name, ...button.toJSON()}])),
body: this.#body,
Expand All @@ -229,6 +242,9 @@ class afkCheck {
raidChannelsMessage: this.raidChannelsMessage,
}
}
writePoint(new Point('afkchecksmodules')
.tag('raidID', this.#raidID)
.booleanField('fileWrite', true))
fs.writeFileSync('./data/afkChecks.json', JSON.stringify(this.#bot.afkChecks, null, 4), err => { if (err) ErrorLogger.log(err, this.#bot, this.#guild) })
}

Expand All @@ -237,8 +253,7 @@ class afkCheck {
this.#raidID = storedAfkCheck.raidID

this.members = storedAfkCheck.members
this.earlyLocationMembers = storedAfkCheck.earlyLocationMembers
this.earlySlotMembers = storedAfkCheck.earlySlotMembers
this.staffEarlyMembers = this.staffEarlyMembers
this.buttons = storedAfkCheck.buttons.map(button => new AfkButton(this.#botSettings, this.#bot.storedEmojis, this.#guild, {...this.#afkTemplate.getButton(button.name), ...button}))
this.reactRequests = Object.fromEntries(Object.entries(storedAfkCheck.reactRequests).map(([messageId, button]) => [messageId, new AfkButton(this.#botSettings, this.#bot.storedEmojis, this.#guild, {...this.#afkTemplate.getButton(button.name), ...button})]))
this.#body = storedAfkCheck.body
Expand Down Expand Up @@ -303,7 +318,7 @@ class afkCheck {
}

async moveInEarlys() {
for (let i of this.earlySlotMembers) {
for (let i of this.earlySlotMembers()) {
let member = this.#guild.members.cache.get(i)
if (!member.voice.channel) continue
if (member.voice.channel.name.includes('lounge') || member.voice.channel.name.includes('Lounge') || member.voice.channel.name.includes('drag')) await member.voice.setChannel(this.#channel.id).catch(er => { })
Expand Down Expand Up @@ -630,11 +645,8 @@ class afkCheck {
for (let i of button.parent) {
const parentButton = this.getButton(i);
if (!parentButton.members.includes(interaction.member.id)) parentButton.members.push(interaction.member.id)
if (parentButton.location && !this.earlyLocationMembers.includes(interaction.member.id)) this.earlyLocationMembers.push(interaction.member.id)
}
}
if (!this.earlySlotMembers.includes(interaction.member.id)) this.earlySlotMembers.push(interaction.member.id)
if (button.location && !this.earlyLocationMembers.includes(interaction.member.id)) this.earlyLocationMembers.push(interaction.member.id)
await Promise.all([
this.raidCommandsMessage.edit(this.#genRaidCommands(), this.#bot, this.#guild),
this.raidInfoMessage.edit(this.#genRaidInfo())
Expand All @@ -653,6 +665,15 @@ class afkCheck {
}
}

earlyLocationMembers() {
const locationButtons = this.buttons.filter(button => button.location || this.buttons.some(parent => button.parent?.includes(parent.name) && parent.location));
return locationButtons.map(button => button.members).flat()
}

earlySlotMembers() {
return this.buttons.map(button => button.members).flat().concat(this.staffEarlyMembers);
}

async processPhaseControl(interaction) {
switch (interaction.customId) {
case "abort":
Expand Down Expand Up @@ -977,7 +998,7 @@ class afkCheck {
}

async processReconnect(interaction) {
if (this.members.includes(interaction.member.id) || this.earlySlotMembers.includes(interaction.member.id) || this.earlyLocationMembers.includes(interaction.member.id)) {
if (this.members.includes(interaction.member.id) || this.earlySlotMembers().includes(interaction.member.id)) {
if (!interaction.member.voice.channel) return interaction.reply({ embeds: [extensions.createEmbed(interaction, `Join lounge to be moved into the channel. You can dismiss this message.`, null)], ephemeral: true })
else if (interaction.member.voice.channel.id == this.#channel.id) return interaction.reply({ content: 'It looks like you are already in the channel ඞ. You can dismiss this message.', ephemeral: true })
else if (interaction.member.voice.channel.name.includes('lounge') || interaction.member.voice.channel.name.includes('Lounge') || interaction.member.voice.channel.name.includes('drag')) {
Expand Down Expand Up @@ -1018,13 +1039,13 @@ class afkCheck {
}

async processReactableSupporter(interaction, button) {
if (this.earlySlotMembers.includes(interaction.member.id)) {
if (this.earlySlotMembers().includes(interaction.member.id)) {
await interaction.reply({ embeds: [extensions.createEmbed(interaction, `Supporter Perks in \`${interaction.guild.name}\` only gives a guaranteed slot in the raid and you already have this from another react.\nYour Supporter Perks have not been used.${this.#afkTemplate.vcOptions != AfkTemplate.TemplateVCOptions.NO_VC ? ` Join lounge to be moved into the channel.` : ``}`, null)], ephemeral: true })
return false
}
if (interaction.member.roles.highest.position >= interaction.guild.roles.cache.get(this.#botSettings.roles.trialrl).position) {
await interaction.reply({ embeds: [extensions.createEmbed(interaction, `The location for this run has been set to \`${this.location}\``, null)], ephemeral: true })
if (!this.earlySlotMembers.includes(interaction.member.id)) this.earlySlotMembers.push(interaction.member.id)
if (!this.staffEarlyMembers.includes(interaction.member.id)) this.staffEarlyMembers.push(interaction.member.id);
return false
}
for (let i of this.#botSettings.lists.earlyLocation) { //custom early location roles
Expand Down Expand Up @@ -1123,11 +1144,11 @@ class afkCheck {
])

if (this.#channel) this.#channel.members.forEach(m => this.members.push(m.id));
this.members = [...new Set([...this.members, ...this.earlySlotMembers, this.#leader.id])];
this.members = [...new Set([...this.members, ...this.earlySlotMembers(), this.#leader.id])];


if (this.#channel && this.#botSettings.backend.giveLocationToEarlyVConStart){
const lateLocationMembers = this.earlySlotMembers.filter(u => !this.earlyLocationMembers.includes(u))
const lateLocationMembers = this.earlySlotMembers().filter(u => !this.earlyLocationMembers().includes(u))
const hearingImpairedMembers = this.#botSettings.lists.hearingImpairedMembers
const dmMembers = [...new Set(lateLocationMembers.concat(hearingImpairedMembers))]
const earlyLocEmbed = new Discord.EmbedBuilder()
Expand Down Expand Up @@ -1176,7 +1197,7 @@ class afkCheck {
}

async loggingAfk() {
let members = this.#channel && this.#channel.members.size != 0 ? this.#channel.members.map(m => m.id) : this.earlySlotMembers
let members = this.#channel && this.#channel.members.size != 0 ? this.#channel.members.map(m => m.id) : this.earlySlotMembers()
members.push(this.#leader.id);
members = [...new Set(members)];
if (members.length > 0) {
Expand Down Expand Up @@ -1256,7 +1277,7 @@ class afkCheck {
async updateLocation(location) {
this.location = location
await Promise.all([this.sendStatusMessage(), this.sendCommandsMessage(), this.sendChannelsMessage()])
for (let i of this.earlyLocationMembers) {
for (let i of this.earlyLocationMembers()) {
let member = this.#guild.members.cache.get(i)
await member.send(`The location for this run has been changed to \`${this.location}\`, get there ASAP!`)
}
Expand Down
Loading

0 comments on commit 8afa12c

Please sign in to comment.