Giter VIP home page Giter VIP logo

Comments (2)

user4752 avatar user4752 commented on September 28, 2024

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.

from antiscambot.

SocksTheWolf avatar SocksTheWolf commented on September 28, 2024

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.

from antiscambot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.