2
0
mirror of https://github.com/Nick80835/microbot synced 2025-09-01 15:05:48 +00:00

add chance parameter

This commit is contained in:
Nick80835
2020-06-29 15:29:20 -04:00
parent 3fc02581bd
commit 1edcc581b4
3 changed files with 28 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import asyncio import asyncio
from random import randint
from re import escape, search from re import escape, search
from telethon import events, functions, types from telethon import events, functions, types
@@ -68,19 +69,35 @@ class CommandHandler():
await event.reply(f"That command is currently locked: {value['lockreason']}") await event.reply(f"That command is currently locked: {value['lockreason']}")
continue continue
else: else:
value["lockreason"] = f"In use by **{event.from_id}** (`{event.raw_text}`)" if value["chance"]:
await value["function"](event) if randint(0, 100) <= value["chance"]:
value["lockreason"] = None 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"]: elif value["userlocking"]:
if event.from_id in value["lockedusers"]: if event.from_id in value["lockedusers"]:
await event.reply(f"Please don't spam that command.") await event.reply(f"Please don't spam that command.")
continue continue
else: else:
value["lockedusers"].append(event.from_id) if value["chance"]:
await value["function"](event) if randint(0, 100) <= value["chance"]:
value["lockedusers"].remove(event.from_id) 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: 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: except Exception as exception:
value["lockreason"] = None value["lockreason"] = None

View File

@@ -83,7 +83,8 @@ class Loader():
"locking": args.get('locking', False), "locking": args.get('locking', False),
"lockreason": None, "lockreason": None,
"userlocking": args.get('userlocking', False), "userlocking": args.get('userlocking', False),
"lockedusers": [] "lockedusers": [],
"chance": args.get('chance', None)
}) })
return func return func

View File

@@ -65,12 +65,12 @@ async def floor(event):
await event.reply("FLOOOOOOOOOOOOOOOOOOR") 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): async def bruh_moment(event):
if not event.args: if not event.args:
await event.reply("moment") 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): async def moo(event):
await event.reply(choice(moo_answers)) await event.reply(choice(moo_answers))