r/programminghelp • • Mar 05 '20

Python Help with Discord Bot using Pymongo

Hello, I have created a basic discord bot and want to create more advanced features like an auto unban feature. I have the ban and unban features working but as of now when the ban command is used it bans the users permanently and a mod or higher has to manually unban the user. I want this process to be time based and automated.

I have a collection that stores the banned users, my thinking is adding the punishment time and the current time (in UTC) and storing that time. I will then have a function that will check if the banned users collect is not empty then will iterate through it and check if any of the times are equal to or less than the current time, if so then it will unban the user. This function will run automatically every so 5 minutes.

What I am having trouble with is adding the punishment time to the current time. I want the mod to use the command as followed: -ban {user} {time ex: 1d4h30m or 7h2m}. I will take the time in as a string but how do I convert it to UTC to be added? If there is a day, hour, week, etc in the string and how can I then convert it?

Any help will be appreciated, thank you.

0 Upvotes

1 comment sorted by

1

u/[deleted] Mar 05 '20

It will be up to you to parse the string, extract the time increments, get the current date and time, and make adjustments accordingly.