2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 01:58:17 +00:00

add privacy commands, command.private_only

This commit is contained in:
Nick80835 2024-07-03 15:51:22 -04:00
parent 2e31cf7e3e
commit fd4266ae7c
4 changed files with 37 additions and 2 deletions

View File

@ -32,6 +32,7 @@ class Command:
self.fun = args.get("fun", False)
self.not_disableable = args.get("no_disable", False) or self.owner or self.sudo or self.admin
self.no_private = args.get("no_private", False)
self.private_only = args.get("private_only", False)
self.silent_bail = args.get("silent_bail", False)
self.filter = args.get("filter", None)

View File

@ -316,7 +316,10 @@ class CommandHandler():
return (False, None)
if event.is_private and command.no_private:
return (False, "That command can't be used in private!")
return (False, None if command.silent_bail else "That command can't be used in private!")
if not event.is_private and command.private_only:
return (False, None if command.silent_bail else "That command can only be used in private!")
if command.owner and not self.is_owner(event):
return (False, None if command.silent_bail else "You lack the permissions to use that command!")

View File

@ -155,6 +155,13 @@ class Database():
self.cached_chat_wrappers[chat_id] = (chat_db := ChatWrapper(chat))
return chat_db
# deletes the database entry associated with a given chat ID
def del_chat(self, chat_id: int) -> None:
if chat_id in self.cached_chat_wrappers:
del self.cached_chat_wrappers[chat_id]
Chat.delete_by_id(chat_id)
# sudo functions
def sudo_user(self, user_id: int):
try:

View File

@ -4,6 +4,8 @@ from telethon import Button
from ubot import ldr
bot_name = ldr.settings.get_config("bot_name") or "bot"
@ldr.add("del", no_disable=True, help="Deletes messages from this bot, it's a safety feature.")
async def delete_message(event):
@ -17,7 +19,7 @@ async def delete_message(event):
async def start_cmd(event):
await event.reply(
f"Hi I'm {ldr.settings.get_config('bot_name') or 'μBot'}, use /help to see what commands I have!\n\n"
"You can toggle NSFW commands using /nsfw [on|off].",
"You can toggle NSFW commands using /nsfw [on|off] and view what I store using /privacy.",
buttons=[Button.url("Creator", "https://t.me/Nick80835"), Button.url("Source", "https://github.com/Nick80835/microbot/tree/bot")]
)
@ -52,6 +54,28 @@ async def help_cmd(event):
await event.reply(f"{prefix_help}<b>Available commands:</b>\n\n{help_string}", parse_mode="html")
@ldr.add("privacy")
async def privacy_policy(event):
await event.reply(
f"This bot (\"**{bot_name}**\") stores the IDs of chats in which it receives messages as well as configurations associated with those chats such as command prefixes and disabled commands. "
"This includes private 1-on-1 chats, private groups, public groups and channels.\n\n"
f"You may delete this chat (with ID `{event.chat.id}`) and data associated with it from my database using `{ldr.prefix()}clearconfig` if you have sufficient permissions. "
"If a message is received in this chat after the configuration for this chat is deleted, a new database entry for this chat will be created."
)
@ldr.add("clearconfig", admin=True, hide_help=True, no_disable=True, no_private=True, silent_bail=True)
async def clear_config(event):
ldr.db.del_chat(event.chat.id)
await event.reply("Group config cleared.")
@ldr.add("clearconfig", no_disable=True, private_only=True, silent_bail=True)
async def clear_config_private(event):
ldr.db.del_chat(event.chat.id)
await event.reply("Private config cleared.")
@ldr.add("prefix", admin=True, no_private=True)
async def set_group_prefix(event):
if not event.args: