Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Feb 19, 2024

ViBot

Changelog

closes #562
closes #563

mutes Table Restructured

CREATE TABLE `mutes` (
  `id` varchar(32) NOT NULL,
  `modid` varchar(32) NOT NULL,
  `guildid` varchar(32) NOT NULL,
  `reason` varchar(1024) NOT NULL,
  `appliedOn` int NOT NULL DEFAULT (unix_timestamp()),
  `duration` int NOT NULL,
  `removedOn` int DEFAULT NULL,
  `removedBy` varchar(32) DEFAULT NULL,
  `removeReason` varchar(1024) DEFAULT NULL
)
  • A permanent mute is denoted by duration being 0
  • An ended mute should have removedOn set
  • Mutes with duration equaling -1 are mutes that ended before the DB restructure, mostly used to identify in ;punishments when we can't know when a mute was set or how long it was
    • Before, uTime only signified when the mute was supposed to end. It never got updated during an unmute to the time of the unmute, so it's only consistent for those who lasted the entire duration. For mutes it's quite often that's not the case and I'm not comfortable giving an 'ended' time that essentially means nothing.

Conversion Script
The below has been tested to work correctly copy-pasting into an ;eval

(async () => {
    const [rows] = await db.promise().query('SELECT * FROM mutes');
    const now = Date.now();
    const newRows = rows.map(({ id, guildid, reason, modid, uTime, muted, perma })=> {
        perma = perma || (isNaN(uTime) && muted);
        const duration = perma ? 0 : !muted ? -1 : Math.max(-1, (parseInt(uTime) / 1000)^0 - Date.unix());
        const removedOn = perma || duration > 0 ? null : Date.unix();
        const removedBy = removedOn && bot.user.id;
        const removeReason = removedOn && `Removed before ${(new Date()).toLocaleString('en-US')}`;
        return [ id, modid, guildid, reason, duration, removedOn, removedBy, removeReason ];
    });
    await db.promise().query('DROP TABLE IF EXISTS `temp_mutes`');
    await db.promise().query('CREATE TABLE `temp_mutes` ( \
        `id` varchar(32) NOT NULL, \
        `modid` varchar(32) NOT NULL, \
        `guildid` varchar(32) NOT NULL, \
        `reason` varchar(1024) NOT NULL, \
        `appliedOn` int NOT NULL DEFAULT (unix_timestamp()), \
        `duration` int NOT NULL, \
        `removedOn` int DEFAULT NULL, \
        `removedBy` varchar(32) DEFAULT NULL, \
        `overwritten` boolean NOT NULL DEFAULT false, \
        `removeReason` varchar(1024) DEFAULT NULL \
        )');
    await db.promise().query('INSERT INTO temp_mutes (id, modid, guildid, reason, duration, removedOn, removedBy, removeReason) VALUES ?', [newRows]);
    await db.promise().query('RENAME TABLE mutes TO mutes_backup');
    await db.promise().query('RENAME TABLE temp_mutes TO mutes');
})()

If an issue occurs, old mutes will either still be in tact or under mutes_backup. If for whatever reason we need to revert:

use halls;
drop table mutes;
rename table mutes_backup to mutes;

Rewrote mute and unmute commands

  • Both are now usable as slash commands
  • Overwriting a mute now attaching a reason & who removed it to the old mute
  • Automatic unmutes and normal unmutes of temporary & permanent mutes all give the same embed as they now use the same unmute function
  • Confirmations for if a mute is not managed by ViBot & if there's already active mutes have full info and are button confirmations now when trying to mute again.
  • Unmute job will now reapply the muted role to anyone who had the role manually removed but has an active mute in the DB. This is to help avoid inconsistencies when they can be muted again and have multiple active mutes.
    • Disclaimer: I asked multiple upper staff & pinged Officer and got virtually no response so I'm assuming they at least read the message and are fine with it.
    • Automatic unmutes will properly log them being unmuted.
  • Role ping automod now mutes using the same function as ;mute does
  • Permanent mutes are now applied & removed the same as normal timed mutes

Bugs

  • Stops DB from having invalid 'still muted' rows for people who were manually removed from the role
  • Umute and mute, permanent/not, automatic/not all log the same way in #mod-logs channel
  • Overwriting mutes now properly attaches reason/mod details to the old mute & logs properly
  • Can now properly permanently mute
  • Can actually attach a reason to unmutes in general

Examples

Ignore the footers here, I changed it to just be moderator displayName & displayAvatarURL() for consistency. Just don't feel like retaking all of them for a minor change

  • normal 1 day mute
    image
    image
  • overwriting a mute confirmation & perma
    image
    image
  • confirmed overwrite
    image
  • Unmute
    image
  • What the raider sees for unmute
    image
  • Mute permanent slash command
    image
  • Unmute slash command
    image
  • Mute temporary slash command
    image
  • New punishments after db rework w/ an overwrite, active, and older mutes
    image

husky-rotmg added 12 commits February 16, 2024 11:17
😄 I'll fill out info later, need a couple small touches
Split up slashCommandExecute and execute to keep normal command (mostly) the same, no reason to have `permanent | temporary` as an arg when we can guess based on value of 2nd argument
- Remove dangerous code from `;test`, will be done in an `;eval` instead.
- Fixed up formatting for overwrites & old mutes
- initial old mutes have duration -1 since it's unknown so `;punushments` can clarify we aren't certain when or how long (uTime is a terrible field design)
Not doing legacy options extending in this PR.
- If settings.rolePermissions.removePermanentMute is defined, deny if lower role
- Slight unmute embed formatting
- mute reason default to `No reason provided` instead of empty string
set to moderator name + icon to help clarity (images are always nice)
@ghost ghost added Bug A fix for something that does not work as intended Quality of Life An improvement of something that exists Change A modification to something that exists labels Feb 19, 2024
@ghost ghost self-assigned this Feb 19, 2024
@ghost ghost marked this pull request as ready for review February 21, 2024 19:06
@ghost ghost self-requested a review as a code owner February 21, 2024 19:06
@ghost ghost changed the title [DEPENDENT ON #730] Husky/mute rewrite Husky/mute rewrite Feb 21, 2024
@Huntifer-RotMG Huntifer-RotMG self-requested a review February 21, 2024 21:50
@Thomasc33 Thomasc33 unassigned ghost Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug A fix for something that does not work as intended Change A modification to something that exists Quality of Life An improvement of something that exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Permanent ;mute Add Logs for ;unmute

0 participants