2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 18:19:16 +00:00
microbot/ubot/modules/system.py

159 lines
5.6 KiB
Python
Raw Normal View History

2020-03-16 21:02:05 -04:00
# SPDX-License-Identifier: GPL-2.0-or-later
2023-10-16 09:46:31 -04:00
from time import time_ns
2020-06-19 14:40:41 -04:00
from ubot.micro_bot import ldr
2023-10-16 09:46:31 -04:00
2020-07-21 09:44:28 -04:00
@ldr.add("del", help="Deletes messages from this bot, it's a safety feature.")
2020-05-01 10:27:07 -04:00
async def delete_message(event):
message_to_delete = await event.get_reply_message()
2020-05-26 14:23:04 -04:00
if message_to_delete and message_to_delete.from_id == (await event.client.get_me()).id:
2020-05-01 10:27:07 -04:00
await message_to_delete.delete()
@ldr.add("help")
async def help_cmd(event):
2020-07-21 09:44:28 -04:00
if event.args:
for key, value in ldr.help_dict.items():
for info in value:
if event.args == info[0]:
if info[1]:
await event.reply(f"Help for **{info[0]}**: __{info[1]}__")
return
await event.reply(f"**{info[0]}** doesn't have a help string.")
return
2020-07-16 13:41:42 -04:00
prefix = ldr.prefix()
help_string = ""
for key, value in ldr.help_dict.items():
help_string += f"\n**{key}**: "
for info in value:
2020-07-21 09:44:28 -04:00
help_string += f"{prefix}{info[0]}, "
help_string = help_string.rstrip(", ")
2020-06-06 11:04:14 -04:00
await event.reply(f"**Available commands:**\n{help_string}")
@ldr.add("sudohelp", sudo=True)
async def sudohelp(event):
2020-07-21 09:44:28 -04:00
if event.args:
for key, value in ldr.help_hidden_dict.items():
for info in value:
if event.args == info[0]:
if info[1]:
await event.reply(f"Help for **{info[0]}**: __{info[1]}__")
return
await event.reply(f"**{info[0]}** doesn't have a help string.")
return
help_string = ""
for key, value in ldr.help_hidden_dict.items():
help_string += f"\n**{key}**: "
for info in value:
2020-07-21 09:44:28 -04:00
help_string += f"`{info[0]}`, "
help_string = help_string.rstrip(", ")
await event.reply(f"**Available (hidden) commands:**\n{help_string}")
@ldr.add("ping", hide_help=True)
2020-05-02 16:43:52 -04:00
async def ping(event):
start = time_ns()
2020-06-06 11:04:14 -04:00
ping_msg = await event.reply("Ping…")
2020-05-03 16:44:01 -04:00
time_taken_ms = int((time_ns() - start) / 1000000)
2020-06-06 11:04:14 -04:00
await ping_msg.edit(f"Ping… Pong! -> **{time_taken_ms}**ms")
2020-05-02 16:43:52 -04:00
@ldr.add("repo")
2023-10-16 09:46:31 -04:00
async def bot_repo(event):
await event.reply("https://github.com/Nick80835/microbot")
2020-08-24 12:07:23 -04:00
@ldr.add("disable", admin=True, help="Disables commands in the current chat, requires admin.")
async def disable_command(event):
if event.args:
for value in ldr.help_dict.values():
2020-08-24 17:02:08 -04:00
for info in value:
if event.args == info[0]:
if info[2]:
await event.reply(f"**{info[0]}** cannot be disabled!")
return
await event.reply(f"Disabling **{info[0]}** in chat **{event.chat.id}**!")
ldr.db.disable_command(event.chat.id, info[0])
2020-08-24 12:07:23 -04:00
return
await event.reply(f"**{event.args}** is not a command!")
else:
await event.reply(f"Specify a command to disable!")
@ldr.add("enable", admin=True, help="Enables commands in the current chat, requires admin.")
async def enable_command(event):
if event.args:
for value in ldr.help_dict.values():
for info in [i[0] for i in value]:
if event.args == info:
await event.reply(f"Enabling **{info}** in chat **{event.chat.id}**!")
ldr.db.enable_command(event.chat.id, info)
return
await event.reply(f"**{event.args}** is not a command!")
else:
await event.reply(f"Specify a command to enable!")
@ldr.add("showdisabled", admin=True, help="Shows disabled commands in the current chat.")
async def show_disabled(event):
disabled_list = ldr.db.get_disabled_commands(event.chat.id)
if disabled_list:
disabled_commands = "\n".join(ldr.db.get_disabled_commands(event.chat.id))
await event.reply(f"Disabled commands in **{event.chat.id}**:\n\n{disabled_commands}")
else:
await event.reply(f"There are no disabled commands in **{event.chat.id}**!")
2020-07-21 09:44:28 -04:00
@ldr.add("nsfw", admin=True, help="Enables or disables NSFW commands for a chat, requires admin.")
async def nsfw_toggle(event):
if not event.args or event.args not in ("on", "off"):
if str(event.chat.id) not in ldr.settings.get_list("nsfw_blacklist"):
current_config = 'On'
else:
current_config = 'Off'
2020-06-23 15:28:09 -04:00
await event.reply(f"Syntax: {ldr.prefix()}nsfw (on|off)\nCurrent config for this chat: {current_config}")
return
if event.args == "on":
ldr.settings.remove_from_list("nsfw_blacklist", event.chat.id)
2020-06-09 21:07:50 -04:00
await event.reply("NSFW commands enabled for this chat!")
elif event.args == "off":
ldr.settings.add_to_list("nsfw_blacklist", event.chat.id)
2020-06-09 21:07:50 -04:00
await event.reply("NSFW commands disabled for this chat!")
2020-08-04 07:06:11 -04:00
@ldr.add("fun", admin=True, help="Enables or disables fun commands for a chat, requires admin.")
async def fun_toggle(event):
if not event.args or event.args not in ("on", "off"):
if str(event.chat.id) not in ldr.settings.get_list("fun_blacklist"):
current_config = 'On'
else:
current_config = 'Off'
await event.reply(f"Syntax: {ldr.prefix()}fun (on|off)\nCurrent config for this chat: {current_config}")
return
if event.args == "on":
ldr.settings.remove_from_list("fun_blacklist", event.chat.id)
await event.reply("Fun commands enabled for this chat!")
elif event.args == "off":
ldr.settings.add_to_list("fun_blacklist", event.chat.id)
await event.reply("Fun commands disabled for this chat!")