🥅 - Added a limit rate on $issou command (and $rank)

This commit is contained in:
Florian SYLVAIN
2021-03-04 16:33:55 +01:00
parent 68b55fb4ec
commit 24995b4049
+14 -1
View File
@@ -5,6 +5,7 @@ import discord
from private import * from private import *
from osu_api import * from osu_api import *
from discord.ext import tasks, commands from discord.ext import tasks, commands
from discord.ext.commands.cooldowns import BucketType
from riot_api import rank_track, WATCHER, REGION from riot_api import rank_track, WATCHER, REGION
from riotwatcher import ApiError from riotwatcher import ApiError
from emoji import demojize from emoji import demojize
@@ -13,7 +14,7 @@ from twitch import TwitchClient
bot = commands.Bot(command_prefix='$') bot = commands.Bot(command_prefix='$')
twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH) twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH)
chats = dict() chats = dict()
CD_ISSOU = 0
class ChatObj: class ChatObj:
def __init__(self, twitch_user, discord_channel): def __init__(self, twitch_user, discord_channel):
@@ -120,6 +121,7 @@ async def chat_stop(ctx):
@bot.command() @bot.command()
@commands.cooldown(1, 2, commands.BucketType.user)
async def rank(ctx, arg, argf=None): async def rank(ctx, arg, argf=None):
if argf is None: if argf is None:
try: try:
@@ -145,6 +147,7 @@ async def rank(ctx, arg, argf=None):
@bot.command() @bot.command()
@commands.cooldown(1, 2, commands.BucketType.guild)
async def issou(ctx, arg1: discord.User = None): async def issou(ctx, arg1: discord.User = None):
if arg1 is not None: if arg1 is not None:
user = arg1 user = arg1
@@ -162,6 +165,8 @@ async def issou(ctx, arg1: discord.User = None):
if voice.is_playing(): if voice.is_playing():
await asyncio.sleep(1) await asyncio.sleep(1)
await voice.disconnect() await voice.disconnect()
global CD_ISSOU
CD_ISSOU = 0
else: else:
await ctx.send('You or the targeted person are not connected to any channel.') await ctx.send('You or the targeted person are not connected to any channel.')
@@ -241,4 +246,12 @@ async def osu_acc(ctx, arg, argF=None):
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.') await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
@issou.error
async def issou_error(ctx, error):
global CD_ISSOU
if isinstance(error, commands.CommandOnCooldown) and not CD_ISSOU:
await ctx.send(f'Please wait at least 2 seconds between each $issou.')
CD_ISSOU = 1
bot.run(TOKEN_BOT) bot.run(TOKEN_BOT)