Code Monkey home page Code Monkey logo

cooldowns's Introduction

cooldowns

a custom discord.py cooldown module

Usage:

Example:

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:

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

cooldowns's People

Contributors

wynwxst avatar

Watchers

 avatar

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.