* [PATCH v1 0/4] Add admin configuration @ 2022-08-11 8:26 Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 1/4] Add config.py.example Muhammad Rizki ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: Muhammad Rizki @ 2022-08-11 8:26 UTC (permalink / raw) To: Ammar Faizi Cc: Muhammad Rizki, GNU/Weeb Mailing List, Alviro Iskandar Setiawan Afternoon sir, In this series, I create config.py for handling the bot commands and callbacks which is only admins who can use these. How to configure it? 1. Search any of Telegram bot who has User ID extractor 2. Copy your User ID 3. Then, paste it in the ADMINS list variable in config.py file There are 4 patches in this series: - Patch 1 is to add config.py.example so other devs know what to do - Patch 2 is to add config.py into the .gitignore - Patch 3 is to use config.admin_only into the commands and callbacks - Patch 4 is just remove some unused codes. Tested and works as I expected, please give it a test too if there is any errors, bugs, or unexpected results. Signed-off-by: Muhammad Rizki <[email protected]> --- Muhammad Rizki (4): Add config.py.example Add config.py in .gitignore Use created filter for admin-only Remove unused codes in some files .gitignore | 3 +++ daemon/config.py.example | 11 +++++++++++ daemon/packages/plugins/callbacks/del_atom.py | 3 ++- daemon/packages/plugins/callbacks/del_chat.py | 3 ++- daemon/packages/plugins/commands/debugger.py | 4 +++- daemon/packages/plugins/commands/manage_atom.py | 8 +++++--- daemon/packages/plugins/commands/manage_broadcast.py | 5 +++-- daemon/packages/plugins/commands/scrape.py | 3 ++- daemon/scraper/db.py | 1 - 9 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 daemon/config.py.example base-commit: a6280937ce9623e961bb66a76fad2c2f5cd10244 -- Muhammad Rizki ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/4] Add config.py.example 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki @ 2022-08-11 8:26 ` Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 2/4] Add config.py in .gitignore Muhammad Rizki ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: Muhammad Rizki @ 2022-08-11 8:26 UTC (permalink / raw) To: Ammar Faizi Cc: Muhammad Rizki, GNU/Weeb Mailing List, Alviro Iskandar Setiawan I want to filter specific command with admin-only access, which will be add to add_atom and add_bc commands and callbacks. Signed-off-by: Muhammad Rizki <[email protected]> --- daemon/config.py.example | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 daemon/config.py.example diff --git a/daemon/config.py.example b/daemon/config.py.example new file mode 100644 index 0000000..3818d27 --- /dev/null +++ b/daemon/config.py.example @@ -0,0 +1,11 @@ +from pyrogram import filters +from pyrogram.types import Message + +# Insert Telegram admin id in the list below +ADMINS = [] + + +async def adm_flt(_, __, m: Message): + return m.from_user.id in ADMINS + +admin_only = filters.create(adm_flt) -- Muhammad Rizki ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 2/4] Add config.py in .gitignore 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 1/4] Add config.py.example Muhammad Rizki @ 2022-08-11 8:26 ` Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 3/4] Use created filter for admin-only Muhammad Rizki ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: Muhammad Rizki @ 2022-08-11 8:26 UTC (permalink / raw) To: Ammar Faizi Cc: Muhammad Rizki, GNU/Weeb Mailing List, Alviro Iskandar Setiawan I want to config.py file will not be committed, so I add it into .gitignore Signed-off-by: Muhammad Rizki <[email protected]> --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index eae515c..4de282d 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,6 @@ data.json # PATCH files *.patch + +# configuration file +daemon/config.py -- Muhammad Rizki ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 3/4] Use created filter for admin-only 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 1/4] Add config.py.example Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 2/4] Add config.py in .gitignore Muhammad Rizki @ 2022-08-11 8:26 ` Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 4/4] Remove unused codes in some files Muhammad Rizki 2022-08-11 22:29 ` [PATCH v1 0/4] Add admin configuration Ammar Faizi 4 siblings, 0 replies; 6+ messages in thread From: Muhammad Rizki @ 2022-08-11 8:26 UTC (permalink / raw) To: Ammar Faizi Cc: Muhammad Rizki, GNU/Weeb Mailing List, Alviro Iskandar Setiawan Use created filter into the command and callback plugins, which is only admins can use the callback buttons and bot commands. Signed-off-by: Muhammad Rizki <[email protected]> --- daemon/packages/plugins/callbacks/del_atom.py | 3 ++- daemon/packages/plugins/callbacks/del_chat.py | 3 ++- daemon/packages/plugins/commands/debugger.py | 4 +++- daemon/packages/plugins/commands/manage_atom.py | 6 ++++-- daemon/packages/plugins/commands/manage_broadcast.py | 5 +++-- daemon/packages/plugins/commands/scrape.py | 3 ++- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/daemon/packages/plugins/callbacks/del_atom.py b/daemon/packages/plugins/callbacks/del_atom.py index 0595e67..1510d60 100644 --- a/daemon/packages/plugins/callbacks/del_atom.py +++ b/daemon/packages/plugins/callbacks/del_atom.py @@ -6,9 +6,10 @@ from packages import DaemonClient from scraper import utils from pyrogram.types import CallbackQuery +import config [email protected]_callback_query(group=1) [email protected]_callback_query(config.admin_only, group=1) async def on_del_atom(c: DaemonClient, cb: CallbackQuery): if not "del_atom" in cb.data: return diff --git a/daemon/packages/plugins/callbacks/del_chat.py b/daemon/packages/plugins/callbacks/del_chat.py index 54545af..26c6dd8 100644 --- a/daemon/packages/plugins/callbacks/del_chat.py +++ b/daemon/packages/plugins/callbacks/del_chat.py @@ -6,9 +6,10 @@ from packages import DaemonClient from scraper import utils from pyrogram.types import CallbackQuery +import config [email protected]_callback_query(group=2) [email protected]_callback_query(config.admin_only, group=2) async def on_del_chat(c: DaemonClient, cb: CallbackQuery): if not "del_chat" in cb.data: return diff --git a/daemon/packages/plugins/commands/debugger.py b/daemon/packages/plugins/commands/debugger.py index e0f145e..ae2d31d 100644 --- a/daemon/packages/plugins/commands/debugger.py +++ b/daemon/packages/plugins/commands/debugger.py @@ -7,10 +7,12 @@ from pyrogram import Client, filters, enums from pyrogram.types import Message from textwrap import indent import io, import_expression, contextlib, traceback +import config + @Client.on_message( filters.command(['d','debug']) & - filters.user(["nekoha", "kiizuah"]) + config.admin_only ) async def execute_v2(c: Client, m: Message): sep = m.text.split('\n') diff --git a/daemon/packages/plugins/commands/manage_atom.py b/daemon/packages/plugins/commands/manage_atom.py index 387c70c..3dcd616 100644 --- a/daemon/packages/plugins/commands/manage_atom.py +++ b/daemon/packages/plugins/commands/manage_atom.py @@ -7,10 +7,12 @@ from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton from pyrogram import filters from packages import DaemonClient from scraper import utils +import config + @DaemonClient.on_message( filters.command("add_atom") & - filters.chat(["kiizuah", "nekoha", -1001673279485]) + config.admin_only ) async def add_atom_url(c: DaemonClient, m: Message): if len(m.command) <= 1: @@ -32,7 +34,7 @@ async def add_atom_url(c: DaemonClient, m: Message): @DaemonClient.on_message( filters.command("del_atom") & - filters.chat(["kiizuah", "nekoha", -1001673279485]) + config.admin_only ) async def del_atom_url(c: DaemonClient, m: Message): atoms = c.db.get_atom_urls() diff --git a/daemon/packages/plugins/commands/manage_broadcast.py b/daemon/packages/plugins/commands/manage_broadcast.py index 3f9154c..ffb5a6b 100644 --- a/daemon/packages/plugins/commands/manage_broadcast.py +++ b/daemon/packages/plugins/commands/manage_broadcast.py @@ -7,11 +7,12 @@ from pyrogram.types import Message from pyrogram import filters, enums from packages import DaemonClient from scraper import utils +import config @DaemonClient.on_message( filters.command("add_bc") & - (filters.private | filters.group) + config.admin_only ) async def add_broadcast(c: DaemonClient, m: Message): if m.chat.type == enums.ChatType.PRIVATE: @@ -38,7 +39,7 @@ async def add_broadcast(c: DaemonClient, m: Message): @DaemonClient.on_message( filters.command("del_bc") & - filters.chat(["kiizuah", "nekoha", -1001673279485]) + config.admin_only ) async def del_broadcast(c: DaemonClient, m: Message): if "--list" in m.text: diff --git a/daemon/packages/plugins/commands/scrape.py b/daemon/packages/plugins/commands/scrape.py index 280c3f9..45b1581 100644 --- a/daemon/packages/plugins/commands/scrape.py +++ b/daemon/packages/plugins/commands/scrape.py @@ -9,6 +9,7 @@ from pyrogram import filters from packages import DaemonClient from scraper import Scraper from scraper import utils +import config import shutil import re import asyncio @@ -23,7 +24,7 @@ import asyncio LORE_CMD_URL_PATTERN = r"^(?:\/|\.|\!)lore\s+(https?:\/\/lore\.kernel\.org\/\S+)" @DaemonClient.on_message( filters.regex(LORE_CMD_URL_PATTERN) & - filters.chat(["kiizuah", "nekoha", -1001673279485]) + config.admin_only ) async def scrap_email(c: DaemonClient, m: Message): p = re.search(LORE_CMD_URL_PATTERN, m.text) -- Muhammad Rizki ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 4/4] Remove unused codes in some files 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki ` (2 preceding siblings ...) 2022-08-11 8:26 ` [PATCH v1 3/4] Use created filter for admin-only Muhammad Rizki @ 2022-08-11 8:26 ` Muhammad Rizki 2022-08-11 22:29 ` [PATCH v1 0/4] Add admin configuration Ammar Faizi 4 siblings, 0 replies; 6+ messages in thread From: Muhammad Rizki @ 2022-08-11 8:26 UTC (permalink / raw) To: Ammar Faizi Cc: Muhammad Rizki, GNU/Weeb Mailing List, Alviro Iskandar Setiawan Just remove some unused codes. Signed-off-by: Muhammad Rizki <[email protected]> --- daemon/packages/plugins/commands/manage_atom.py | 2 +- daemon/scraper/db.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/packages/plugins/commands/manage_atom.py b/daemon/packages/plugins/commands/manage_atom.py index 3dcd616..bcb2f35 100644 --- a/daemon/packages/plugins/commands/manage_atom.py +++ b/daemon/packages/plugins/commands/manage_atom.py @@ -3,7 +3,7 @@ # Copyright (C) 2022 Muhammad Rizki <[email protected]> # -from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton +from pyrogram.types import Message from pyrogram import filters from packages import DaemonClient from scraper import utils diff --git a/daemon/scraper/db.py b/daemon/scraper/db.py index 15b0f99..58601d1 100644 --- a/daemon/scraper/db.py +++ b/daemon/scraper/db.py @@ -5,7 +5,6 @@ # from datetime import datetime -from typing import Union import mysql -- Muhammad Rizki ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 0/4] Add admin configuration 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki ` (3 preceding siblings ...) 2022-08-11 8:26 ` [PATCH v1 4/4] Remove unused codes in some files Muhammad Rizki @ 2022-08-11 22:29 ` Ammar Faizi 4 siblings, 0 replies; 6+ messages in thread From: Ammar Faizi @ 2022-08-11 22:29 UTC (permalink / raw) To: Muhammad Rizki Cc: Ammar Faizi, GNU/Weeb Mailing List, Alviro Iskandar Setiawan On Thu, 11 Aug 2022 15:26:52 +0700, Muhammad Rizki wrote: > Afternoon sir, > > In this series, I create config.py for handling the bot commands and > callbacks which is only admins who can use these. > > How to configure it? > 1. Search any of Telegram bot who has User ID extractor > 2. Copy your User ID > 3. Then, paste it in the ADMINS list variable in config.py file > > [...] Applied, thanks! [1/4] dameon: Add config.py.example commit: 8abd2d42476d04064ca58d3d2042ec5fdcea41fa [2/4] dameon: Add config.py in .gitignore commit: caa8ab645b4ca5cc99bf9e845ffd8ffd37fb879f [3/4] dameon: Use created filter for admin-only commit: fb97f3a3cecec3fefc2c516045cd719c441406cf [4/4] dameon: Remove unused codes in some files commit: 55916829028915bc69032e812aa37a026ab8da82 Best regards, -- Ammar Faizi ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-08-11 22:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-08-11 8:26 [PATCH v1 0/4] Add admin configuration Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 1/4] Add config.py.example Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 2/4] Add config.py in .gitignore Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 3/4] Use created filter for admin-only Muhammad Rizki 2022-08-11 8:26 ` [PATCH v1 4/4] Remove unused codes in some files Muhammad Rizki 2022-08-11 22:29 ` [PATCH v1 0/4] Add admin configuration Ammar Faizi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox