From 24995b4049c853e6ffcbb9daa6ebcda6aa14ef73 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Thu, 4 Mar 2021 16:28:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20-=20Added=20a=20limit=20rate=20o?= =?UTF-8?q?n=20$issou=20command=20(and=20$rank)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/main.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/main.py b/python/main.py index 328a063..4bfff51 100644 --- a/python/main.py +++ b/python/main.py @@ -5,6 +5,7 @@ import discord from private import * from osu_api import * from discord.ext import tasks, commands +from discord.ext.commands.cooldowns import BucketType from riot_api import rank_track, WATCHER, REGION from riotwatcher import ApiError from emoji import demojize @@ -13,7 +14,7 @@ from twitch import TwitchClient bot = commands.Bot(command_prefix='$') twitch_client = TwitchClient(client_id=ID_TWITCH, oauth_token=TOKEN_TWITCH) chats = dict() - +CD_ISSOU = 0 class ChatObj: def __init__(self, twitch_user, discord_channel): @@ -120,6 +121,7 @@ async def chat_stop(ctx): @bot.command() +@commands.cooldown(1, 2, commands.BucketType.user) async def rank(ctx, arg, argf=None): if argf is None: try: @@ -145,6 +147,7 @@ async def rank(ctx, arg, argf=None): @bot.command() +@commands.cooldown(1, 2, commands.BucketType.guild) async def issou(ctx, arg1: discord.User = None): if arg1 is not None: user = arg1 @@ -162,6 +165,8 @@ async def issou(ctx, arg1: discord.User = None): if voice.is_playing(): await asyncio.sleep(1) await voice.disconnect() + global CD_ISSOU + CD_ISSOU = 0 else: 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.') +@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)