- Remove stupid db lock in `.e`
- Allow `.security` and `.inlinesec` only to owner by default
pull/1/head
hikariatama 2022-08-02 22:29:33 +00:00
parent cc09c8bdde
commit bef9968a74
4 changed files with 6 additions and 64 deletions

View File

@ -17,6 +17,8 @@
- Add uptime to `.info` - Add uptime to `.info`
- Refactor `.help`, add version to single mod help message - Refactor `.help`, add version to single mod help message
- Fix TypeError in `.e` when returning tl class instead of object - Fix TypeError in `.e` when returning tl class instead of object
- Remove stupid db lock in `.e`
- Allow `.security` and `.inlinesec` only to owner by default
## 🌑 Hikka 1.2.12 ## 🌑 Hikka 1.2.12

View File

@ -360,6 +360,7 @@ class HikkaSecurityMod(loader.Module):
return self._perms_map(config, is_inline) return self._perms_map(config, is_inline)
@loader.owner
async def securitycmd(self, message: Message): async def securitycmd(self, message: Message):
"""[command] - Configure command's security settings""" """[command] - Configure command's security settings"""
args = utils.get_args_raw(message).lower().strip() args = utils.get_args_raw(message).lower().strip()
@ -385,6 +386,7 @@ class HikkaSecurityMod(loader.Module):
ttl=5 * 60, ttl=5 * 60,
) )
@loader.owner
async def inlineseccmd(self, message: Message): async def inlineseccmd(self, message: Message):
"""[command] - Configure inline command's security settings""" """[command] - Configure inline command's security settings"""
args = utils.get_args_raw(message).lower().strip() args = utils.get_args_raw(message).lower().strip()

View File

@ -20,22 +20,11 @@ from telethon.errors.rpcerrorlist import MessageIdInvalidError
from telethon.tl.types import Message from telethon.tl.types import Message
from .. import loader, main, utils from .. import loader, main, utils
from ..inline.types import InlineCall
from ..log import HikkaException from ..log import HikkaException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class FakeDbException(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class FakeDb:
def __getattr__(self, *args, **kwargs):
raise FakeDbException("Database read-write permission required")
@loader.tds @loader.tds
class PythonMod(loader.Module): class PythonMod(loader.Module):
"""Evaluates python code""" """Evaluates python code"""
@ -44,27 +33,11 @@ class PythonMod(loader.Module):
"name": "Python", "name": "Python",
"eval": "<b>🎬 Code:</b>\n<code>{}</code>\n<b>🪄 Result:</b>\n<code>{}</code>", "eval": "<b>🎬 Code:</b>\n<code>{}</code>\n<b>🪄 Result:</b>\n<code>{}</code>",
"err": "<b>🎬 Code:</b>\n<code>{}</code>\n\n<b>🚫 Error:</b>\n{}", "err": "<b>🎬 Code:</b>\n<code>{}</code>\n\n<b>🚫 Error:</b>\n{}",
"db_permission": (
"⚠️ <b>Do not use </b><code>db.set</code><b>, </b><code>db.get</code><b> "
"and other db operations. You have core modules to control anything you "
"want</b>\n\n<i>Theses commands may <b><u>crash</u></b> your userbot or "
"even make it <b><u>unusable</u></b>! Do it on your own risk</i>\n\n<i>"
"If you issue any errors after allowing this option, <b><u>you will not "
"get any help in support chat</u></b>!</i>"
),
} }
strings_ru = { strings_ru = {
"eval": "<b>🎬 Код:</b>\n<code>{}</code>\n<b>🪄 Результат:</b>\n<code>{}</code>", "eval": "<b>🎬 Код:</b>\n<code>{}</code>\n<b>🪄 Результат:</b>\n<code>{}</code>",
"err": "<b>🎬 Код:</b>\n<code>{}</code>\n\n<b>🚫 Ошибка:</b>\n{}", "err": "<b>🎬 Код:</b>\n<code>{}</code>\n\n<b>🚫 Ошибка:</b>\n{}",
"db_permission": (
"⚠️ <b>Не используй </b><code>db.set</code><b>, </b><code>db.get</code><b>"
" и другие операции с базой данных. У тебя есть встроенные модуля для"
" управления ей</b>\n\n<i>Эти команды могут <b><u>нарушить работу</u></b>"
" юзербота, или вообще <b><u>сломать</u></b> его! Используй эти команды на"
" свой страх и риск</i>\n\n<i>Если появятся какие-либо проблемы, вызванные"
" после этой команды, <b><u>ты не получишь помощи в чате</u></b>!</i>"
),
"_cmd_doc_eval": "Алиас для команды .e", "_cmd_doc_eval": "Алиас для команды .e",
"_cmd_doc_e": "Выполняет Python кодировка", "_cmd_doc_e": "Выполняет Python кодировка",
"_cls_doc": "Выполняет Python код", "_cls_doc": "Выполняет Python код",
@ -78,11 +51,6 @@ class PythonMod(loader.Module):
"""Alias for .e command""" """Alias for .e command"""
await self.ecmd(message) await self.ecmd(message)
async def inline__allow(self, call: InlineCall):
await call.answer("Now you can access db through .e command", show_alert=True)
self._db.set(main.__name__, "enable_db_eval", True)
await call.delete()
@loader.owner @loader.owner
async def ecmd(self, message: Message): async def ecmd(self, message: Message):
"""Evaluates python code""" """Evaluates python code"""
@ -93,21 +61,6 @@ class PythonMod(loader.Module):
globals(), globals(),
**await self.getattrs(message), **await self.getattrs(message),
) )
except FakeDbException:
await self.inline.form(
self.strings("db_permission"),
message=message,
reply_markup=[
[
{
"text": "✅ Allow",
"callback": self.inline__allow,
},
{"text": "🚫 Cancel", "action": "close"},
]
],
)
return
except Exception: except Exception:
item = HikkaException.from_exc_info(*sys.exc_info()) item = HikkaException.from_exc_info(*sys.exc_info())
exc = ( exc = (
@ -192,16 +145,8 @@ class PythonMod(loader.Module):
"m": message, "m": message,
"lookup": self.lookup, "lookup": self.lookup,
"self": self, "self": self,
"db": self.db,
}, },
**(
{
"db": self._db,
}
if self._db.get(main.__name__, "enable_db_eval", False)
else {
"db": FakeDb(),
}
),
} }
def get_sub(self, obj: Any, _depth: int = 1) -> dict: def get_sub(self, obj: Any, _depth: int = 1) -> dict:

View File

@ -48,7 +48,7 @@ class TestMod(loader.Module):
"logs_caption": ( "logs_caption": (
"🌘 <b>Hikka logs with verbosity </b><code>{}</code>\n\n👩‍🎤 <b>Hikka" "🌘 <b>Hikka logs with verbosity </b><code>{}</code>\n\n👩‍🎤 <b>Hikka"
" version: {}.{}.{}</b>{}\n⏱ <b>Uptime:" " version: {}.{}.{}</b>{}\n⏱ <b>Uptime:"
" {}</b>\n<b>{}</b>\n\n<b>{}</b>\n\n<b>{} NoNick</b>\n<b>{} Grep</b>\n<b>{}" " {}</b>\n<b>{}</b>\n\n<b>{} NoNick</b>\n<b>{} Grep</b>\n<b>{}"
" InlineLogs</b>" " InlineLogs</b>"
), ),
"suspend_invalid_time": "🚫 <b>Invalid time to suspend</b>", "suspend_invalid_time": "🚫 <b>Invalid time to suspend</b>",
@ -71,8 +71,6 @@ class TestMod(loader.Module):
" ignore this warning</b>" " ignore this warning</b>"
), ),
"choose_loglevel": "💁‍♂️ <b>Choose log level</b>", "choose_loglevel": "💁‍♂️ <b>Choose log level</b>",
"database_unlocked": "🚫 DB eval unlocked",
"database_locked": "✅ DB eval locked",
"bad_module": "🚫 <b>Module not found</b>", "bad_module": "🚫 <b>Module not found</b>",
"debugging_enabled": ( "debugging_enabled": (
"🧑‍💻 <b>Debugging mode enabled for module </b><code>{0}</code>\n<i>Go to" "🧑‍💻 <b>Debugging mode enabled for module </b><code>{0}</code>\n<i>Go to"
@ -92,8 +90,6 @@ class TestMod(loader.Module):
" {}.{}.{}</b>{}\n⏱ <b>Uptime: {}</b>\n<b>{}</b>\n\n<b>{}</b>\n\n<b>{}" " {}.{}.{}</b>{}\n⏱ <b>Uptime: {}</b>\n<b>{}</b>\n\n<b>{}</b>\n\n<b>{}"
" NoNick</b>\n<b>{} Grep</b>\n<b>{} InlineLogs</b>" " NoNick</b>\n<b>{} Grep</b>\n<b>{} InlineLogs</b>"
), ),
"database_unlocked": "🚫 База скомпрометирована",
"database_locked": "✅ База защищена",
"bad_module": "🚫 <b>Модуль не найден</b>", "bad_module": "🚫 <b>Модуль не найден</b>",
"debugging_enabled": ( "debugging_enabled": (
"🧑‍💻 <b>Режим разработчика включен для модуля" "🧑‍💻 <b>Режим разработчика включен для модуля"
@ -428,9 +424,6 @@ class TestMod(loader.Module):
else "", else "",
utils.formatted_uptime(), utils.formatted_uptime(),
utils.get_named_platform(), utils.get_named_platform(),
self.strings(
f"database_{'un' if self._db.get(main.__name__, 'enable_db_eval', False) else ''}locked"
),
"" if self._db.get(main.__name__, "no_nickname", False) else "🚫", "" if self._db.get(main.__name__, "no_nickname", False) else "🚫",
"" if self._db.get(main.__name__, "grep", False) else "🚫", "" if self._db.get(main.__name__, "grep", False) else "🚫",
"" if self._db.get(main.__name__, "inlinelogs", False) else "🚫", "" if self._db.get(main.__name__, "inlinelogs", False) else "🚫",