blackmesadev / black-mesa

Black Mesa is a Discord Moderation bot designed with Performance, Reliability and Customisation in mind.
https://blackmesa.bot
MIT License
20 stars 4 forks source link

Stop an ongoing purge #4

Closed GenericNerd closed 2 years ago

RGBCube commented 2 years ago

i dont think this is possible because its one request... or is it?

damaredayo commented 2 years ago

This can be implemented using channels with goroutines and using a switch case there to check if the server is currently purging, perhaps a global map would be needed for ongoing jobs between guilds as storing this in mongo or redis would be painfully slow.

jobs[guild.id].Purge = make(chan struct{})

for foo {
    switch {
    case <- jobs[guild.id].Purge:
        break
    default:
    }

    // code here
}

then implement a command to cancel the purge by simply doing


func commandhandler() {
    close(jobs[guild.id].Purge)
}

of course this wouldnt work as there are missing parameters and whatnot but its a proof of concept