mirror of
https://github.com/Nick80835/microbot
synced 2025-08-31 14:38:04 +00:00
add privacy commands, command.private_only
This commit is contained in:
@@ -32,6 +32,7 @@ class Command:
|
|||||||
self.fun = args.get("fun", False)
|
self.fun = args.get("fun", False)
|
||||||
self.not_disableable = args.get("no_disable", False) or self.owner or self.sudo or self.admin
|
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.no_private = args.get("no_private", False)
|
||||||
|
self.private_only = args.get("private_only", False)
|
||||||
self.silent_bail = args.get("silent_bail", False)
|
self.silent_bail = args.get("silent_bail", False)
|
||||||
self.filter = args.get("filter", None)
|
self.filter = args.get("filter", None)
|
||||||
|
|
||||||
|
@@ -316,7 +316,10 @@ class CommandHandler():
|
|||||||
return (False, None)
|
return (False, None)
|
||||||
|
|
||||||
if event.is_private and command.no_private:
|
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):
|
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!")
|
return (False, None if command.silent_bail else "You lack the permissions to use that command!")
|
||||||
|
@@ -155,6 +155,13 @@ class Database():
|
|||||||
self.cached_chat_wrappers[chat_id] = (chat_db := ChatWrapper(chat))
|
self.cached_chat_wrappers[chat_id] = (chat_db := ChatWrapper(chat))
|
||||||
return chat_db
|
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
|
# sudo functions
|
||||||
def sudo_user(self, user_id: int):
|
def sudo_user(self, user_id: int):
|
||||||
try:
|
try:
|
||||||
|
@@ -4,6 +4,8 @@ from telethon import Button
|
|||||||
|
|
||||||
from ubot import ldr
|
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.")
|
@ldr.add("del", no_disable=True, help="Deletes messages from this bot, it's a safety feature.")
|
||||||
async def delete_message(event):
|
async def delete_message(event):
|
||||||
@@ -17,7 +19,7 @@ async def delete_message(event):
|
|||||||
async def start_cmd(event):
|
async def start_cmd(event):
|
||||||
await event.reply(
|
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"
|
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")]
|
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")
|
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)
|
@ldr.add("prefix", admin=True, no_private=True)
|
||||||
async def set_group_prefix(event):
|
async def set_group_prefix(event):
|
||||||
if not event.args:
|
if not event.args:
|
||||||
|
Reference in New Issue
Block a user