Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wynwxst/cooldowns
a custom discord.py cooldown module
https://github.com/wynwxst/cooldowns
Last synced: 20 days ago
JSON representation
a custom discord.py cooldown module
- Host: GitHub
- URL: https://github.com/wynwxst/cooldowns
- Owner: wynwxst
- Created: 2021-10-21T07:21:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-25T05:07:13.000Z (over 3 years ago)
- Last Synced: 2024-11-13T04:34:05.773Z (3 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cooldowns
a custom discord.py cooldown module# Usage:
### Example:
```python
import cooldowns
@bot.command(aliases=["e"])
async def hello(ctx):
if cooldowns.checkcd(ctx): # checks for cooldown
return
await ctx.send("command ran")
cooldowns.addcd(ctx,10) # starts cooldown must be in seconds!!!
```### Functions:
```python
import time
import os
import jsonclass utils:
def gettime(): # gets the current time in a list
current = time.asctime( time.localtime(time.time()))
current = current.split()
current = current[3]
current = current.replace(":"," ")
current = current.split()
hours = current[0]
minutes = current[1]
sec = current[2]
return currentdef getsecs(): # converts current time to seconds
current = utils.gettime()
hours = current[0]
minutes = current[1]
sec = current[2]
sec = int(sec)
e = int(hours)*360
sec += int(e)
f = int(minutes)*60sec += int(f)
return secdef roundcd(seconds): # returns rounded cooldown in text with unit
sec = utils.getsecs()
if int(sec) > int(seconds):
return
sec = int(seconds) - int(sec)
if sec < 60:
return f"{round(sec)} second(s)"
if sec < 360:
return f"{round(sec/60)} minute(s)"
if sec < 21600:
return f"{round(sec/360)} hour(s)"
if sec < 86400:
return f"{round(sec/21600)} day(s)"getkeys - get key data
loadcd - load cooldowns in key data
resetcd - delete cooldown from key data
getcdleft - get amount of cooldown left in secondsgetcd - get the time in seconds the cooldown stops
cooldown - check/reset for cooldown
checkcd - function to check for cooldown and send how much time is left in channel
```
### how is it better?
this cooldown saves even if the bot shuts down and does this using a key system. Is easier to use and can be reset easily with multiple commands. You can use json to edit the key storage and add your own cooldowns manually as well as being more flexable