diff --git a/ubot/command_handler.py b/ubot/command_handler.py index 1433d42..7bf2a74 100644 --- a/ubot/command_handler.py +++ b/ubot/command_handler.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import asyncio +from random import randint from re import escape, search from telethon import events, functions, types @@ -68,19 +69,35 @@ class CommandHandler(): await event.reply(f"That command is currently locked: {value['lockreason']}") continue else: - value["lockreason"] = f"In use by **{event.from_id}** (`{event.raw_text}`)" - await value["function"](event) - value["lockreason"] = None + if value["chance"]: + if randint(0, 100) <= value["chance"]: + value["lockreason"] = f"In use by **{event.from_id}** (`{event.raw_text}`)" + await value["function"](event) + value["lockreason"] = None + else: + value["lockreason"] = f"In use by **{event.from_id}** (`{event.raw_text}`)" + await value["function"](event) + value["lockreason"] = None elif value["userlocking"]: if event.from_id in value["lockedusers"]: await event.reply(f"Please don't spam that command.") continue else: - value["lockedusers"].append(event.from_id) - await value["function"](event) - value["lockedusers"].remove(event.from_id) + if value["chance"]: + if randint(0, 100) <= value["chance"]: + value["lockedusers"].append(event.from_id) + await value["function"](event) + value["lockedusers"].remove(event.from_id) + else: + value["lockedusers"].append(event.from_id) + await value["function"](event) + value["lockedusers"].remove(event.from_id) else: - await value["function"](event) + if value["chance"]: + if randint(0, 100) <= value["chance"]: + await value["function"](event) + else: + await value["function"](event) except Exception as exception: value["lockreason"] = None diff --git a/ubot/loader.py b/ubot/loader.py index 34983ec..ac32340 100644 --- a/ubot/loader.py +++ b/ubot/loader.py @@ -83,7 +83,8 @@ class Loader(): "locking": args.get('locking', False), "lockreason": None, "userlocking": args.get('userlocking', False), - "lockedusers": [] + "lockedusers": [], + "chance": args.get('chance', None) }) return func diff --git a/ubot/modules/fun.py b/ubot/modules/fun.py index a24e805..c239ddb 100644 --- a/ubot/modules/fun.py +++ b/ubot/modules/fun.py @@ -65,12 +65,12 @@ async def floor(event): await event.reply("FLOOOOOOOOOOOOOOOOOOR") -@ldr.add(f"bruh", simple_pattern=True, hide_help=True) +@ldr.add(f"bruh", simple_pattern=True, hide_help=True, chance=50) async def bruh_moment(event): if not event.args: await event.reply("moment") -@ldr.add(f"(^| )moo( |$)", raw_pattern=True, hide_help=True) +@ldr.add(f"(^| )moo( |$)", raw_pattern=True, hide_help=True, chance=50) async def moo(event): await event.reply(choice(moo_answers))