SocksTheWolf / AntiScamBot

A Discord bot that shares ban lists of scammers across multiple Discord servers
https://scamguard.app/
MIT License
6 stars 3 forks source link

DM server owner to activate after bot addition #23

Closed SocksTheWolf closed 4 months ago

SocksTheWolf commented 1 year ago

If the bot gets added to a server but not activated after a set amount of time, dm the server owner to tell them about activation (if they are not already in the control server).

We can use a couple of checks to make this not invasive nor annoying.

user4752 commented 10 months ago

Example code which could be put into a loop to run every 5 minutes ( or any interval ) similar to the ScamGuard.PeriodicBackup

from datetime import datetime, timedelta

.....

unactivatedServers = self.Database.GetAllDeactivatedServers()

for server in unactivatedServers:
    currentTime = datetime.utcnow()
    rangeStart = server.created_at + timedelta(days=1, minutes=4)
    rangeEnd = server.created_at + timedelta(days=1, minutes=9, seconds=1)
    if ((currentTime > rangeStart) & (currentTime < rangeEnd)):
        # run discord message function

With this code, the "notification" would be sent out 1 day after the server entry has been made into the database.

The chosen timedelta is an offset 5 minute interval with an additional 1 second as a safety check. This is for it not occur at the same time frequency as the actual task loop in order to ensure no check will occur outside of the range on accident due to slow execution nor inside of it twice, as the likelyhood of the interval matching the extra 1 second grace interval should be small.

Additional messages can be sent by duplicating the code inside the for loop (to reduce iterations) and changing the timedelta interval day period (or any period)

Note: This code is using the created_at timestamp from my code in #45, and not the updated_at timestamp to ensure the notifications are only sent out on the initial entry of the database, and not due to subsequent changes which have occurred to the server for any of the variety of reasons the entry would be updated.

Another longer term alternative which may allow for more configurability would be to create a notifications table and record attempted communications there.

SocksTheWolf commented 4 months ago

Closing this issue, we're going to add slash commands instead, as this will be easier to use than having the bot directly message an user.