Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 json

class 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 current

def 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)*60

sec += int(f)
return sec

def 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 seconds

getcd - 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