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

feat: Advanced logging system #527

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

imnaiyar
Copy link

@imnaiyar imnaiyar commented Jul 1, 2024

This PR introduces advanced logging to strange bot.

Can log

  • Channel update, create, delete
  • message update, delete, bulk message delete
  • role add, delete, update
  • member kicked, update
  • ban add, remove
  • emoji add, update, delete
  • voice channel join, move, left
  • invites created, deleted

/logging command to setup the log system

  • Command to setup logging could be improved, but i didn't focus on it much

This PR can be considered in the first draft, many things are not thoroughly tested, so any bug reports are welcomed.
If you wish to contribute to the pr, open a pr on the fork of this repo (of which the pr is based on)

@AikooNee
Copy link

AikooNee commented Jul 1, 2024

thx 😊

@AqeelFire
Copy link

Thanks ❤️

@MrTabaOfficial
Copy link

MrTabaOfficial commented Jul 11, 2024

Voice and Messages features not working, it worked voice Left at once when bot was with me in channel while playing music

@imnaiyar
Copy link
Author

imnaiyar commented Jul 11, 2024

Voice and Messages features not working, it worked voice Left at once when bot was with me in channel while playing music

Can you show your client constructor, with intents please,
Also what about messages and voice not working? Can you elaborate? Do note that sometimes structures are not cached, so we return if that's the case since there isn't enough data to compare, so for example, if you just restarted your bot, messages/members won't be cached, so edit/delete etc won't be logged as there is no data of it

@MrTabaOfficial
Copy link

MrTabaOfficial commented Jul 11, 2024

im using Discord 14.15.3 maybe about voice naming is different messages working now only Voice has issue

here is my voiceStateUpdate

const { trackVoiceStats } = require("@handlers/stats");
const { getSettings } = require("@schemas/Guild");
const { EmbedBuilder } = require("discord.js")

/**
 * @param {import('@src/structures').BotClient} client
 * @param {import('discord.js').VoiceState} oldState
 * @param {import('discord.js').VoiceState} newState
 */
module.exports = async (client, oldState, newState) => {
  // Track voice stats
  trackVoiceStats(oldState, newState);
  // Erela.js
  if (client.config.MUSIC.ENABLED) {
    const guild = oldState.guild;

    // if nobody left the channel in question, return.
    if (oldState.channelId !== guild.members.me.voice.channelId || newState.channel) return;

    // otherwise, check how many people are in the channel now
    if (oldState.channel.members.size === 1) {
      setTimeout(() => {
        // if 1 (you), wait 1 minute
        if (!oldState.channel.members.size - 1) {
          const player = client.musicManager.players.resolve(guild.id);
          if (player) client.musicManager.players.destroy(guild.id).then(player.voice.disconnect());
        }
      }, client.config.MUSIC.IDLE_TIME * 1000);
    }
  }
  // Logging
  const settings = await getSettings(newState.guild);
  if (!settings.logging?.voice) return;
  const logChannel = client.channels.cache.get(settings.logging.voice);

  const embed = new EmbedBuilder().setColor("Green").setTimestamp();

  // Member joins
  if (!oldState.channel && newState.channel) {
    embed
      .setAuthor({ name: "Member Joined Voice Channel" })
      .setThumbnail(newState.member.user.displayAvatarURL())
      .addFields(
        { name: "User", value: newState.member.toString(), inline: true },
        { name: "Channel", value: newState.channel.toString(), inline: true }
      )
      .setFooter({ text: `ID: ${newState.member.id}` });
  }

  // Member moved
  if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id) {
    embed
      .setAuthor({ name: "Member Moved Voice Channel" })
      .setThumbnail(newState.member.user.displayAvatarURL())
      .addFields(
        { name: "User", value: newState.member.toString(), inline: true },
        { name: "Old Channel", value: oldState.channel.toString(), inline: true },
        { name: "New Channel", value: newState.channel.toString(), inline: true }
      )
      .setFooter({ text: `ID: ${newState.member.id}` });
  }

  // Member Left
  if (oldState.channel && !newState.channel) {
    embed
      .setAuthor({ name: "Member Left Voice Channel" })
      .setThumbnail(oldState.member.user.displayAvatarURL())
      .addFields(
        { name: "User", value: oldState.member.toString(), inline: true },
        { name: "Channel", value: oldState.channel.toString(), inline: true }
      )
      .setColor("Red")
      .setFooter({ text: `ID: ${oldState.member.id}` });
  }


  if (embed.data.fields.length) logChannel.send({ embeds: [embed] })
};

@MrTabaOfficial
Copy link

i know now why is not working. its not working when Music Setting is Enabled. i Disabled it and it worked but when music feature is on its not working

@imnaiyar
Copy link
Author

i know now why is not working. its not working when Music Setting is Enabled. i Disabled it and it worked but when music feature is on its not working

Ah okay, I see the issue here, will fix it later

@imnaiyar
Copy link
Author

@MrTabaOfficial pushed a fix, try it out and lemme know if any further errors arises

@MrTabaOfficial
Copy link

Sorry i fixed it yesterday and did almost same thing Thanks ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants