Update Ultroid v0.8

---------

Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: Dark <darkbeamer.official@gmail.com>
Co-authored-by: buddhhu <amitsharma123234@gmail.com>
Co-authored-by: Kaif <88398455+kaif-00z@users.noreply.github.com>
Co-authored-by: 1Danish-00 <danish@ultroid.tech>
Co-authored-by: TechiError <techierror@gmail.com>
Co-authored-by: Dark <59723913+DarkBeamerYT@users.noreply.github.com>
This commit is contained in:
Devesh Pal
2023-02-20 10:51:29 +05:30
parent 9746b48e46
commit 09971ca76d
95 changed files with 1857 additions and 3352 deletions

View File

@@ -1,38 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_all_users(key):
return udB.get_key(key) or []
def is_added(id_):
return id_ in get_all_users("BOT_USERS")
def add_user(id_):
users = get_all_users("BOT_USERS")
users.append(id_)
return udB.set_key("BOT_USERS", users)
def is_blacklisted(id_):
return id_ in get_all_users("BOT_BLS")
def blacklist_user(id_):
users = get_all_users("BOT_BLS")
users.append(id_)
return udB.set_key("BOT_BLS", users)
def rem_blacklist(id_):
users = get_all_users("BOT_BLS")
users.remove(id_)
return udB.set_key("BOT_BLS", users)

View File

@@ -1,55 +0,0 @@
from .. import udB
def get_all_channels() -> dict:
"""List all chats where channels are banned."""
return udB.get_key("AUTOBAN_CHANNELS") or {}
def is_autoban_enabled(chat_id: int) -> bool:
"""Check whether channels are banned in a specific chat or not."""
return chat_id in get_all_channels()
def add_channel(chat_id: int) -> bool:
"""Enable channel ban in a given chat."""
if not is_autoban_enabled(int(chat_id)):
channels = get_all_channels()
channels[int(chat_id)] = []
return udB.set_key("AUTOBAN_CHANNELS", channels)
def del_channel(chat_id: int) -> bool:
"""Disable channel ban in a given chat."""
if is_autoban_enabled(chat_id):
channels = get_all_channels()
channels.pop(int(chat_id))
return udB.set_key("AUTOBAN_CHANNELS", channels)
def get_whitelisted_channels(chat_id: int) -> list:
"""Get list of whitelisted channels in a given chat."""
return get_all_channels()[chat_id] if is_autoban_enabled(chat_id) else []
def is_whitelisted(chat_id: int, channel_id: int) -> bool:
"""Check whether given channel is whitelisted in given chat or not."""
return channel_id in get_whitelisted_channels(chat_id)
def add_to_whitelist(chat_id: int, channel_id: int) -> bool:
"""Add a channel in whitelist in a chat."""
if is_autoban_enabled(chat_id):
if not is_whitelisted(chat_id, channel_id):
channels = get_all_channels()
channels[int(chat_id)].append(int(channel_id))
return udB.set_key("AUTOBAN_CHANNELS", channels)
def del_from_whitelist(chat_id: int, channel_id: int) -> bool:
"""Remove a channel from whitelist in a chat."""
if is_autoban_enabled(chat_id):
if is_whitelisted(chat_id, channel_id):
channels = get_all_channels()
channels[int(chat_id)].remove(int(channel_id))
return udB.set_key("AUTOBAN_CHANNELS", channels)

44
pyUltroid/dB/base.py Normal file
View File

@@ -0,0 +1,44 @@
from .. import udB
class KeyManager:
def __init__(self, key, cast=None) -> None:
self._key = key
self._cast = cast
def get(self):
_data = udB.get_key(self._key)
if self._cast and not isinstance(_data, self._cast):
return [_data] if self._cast == list else self._cast(_data)
return _data or (self._cast() if callable(self._cast) else self._cast)
def get_child(self, key):
return self.get()[key]
def count(self):
return len(self.get())
def add(self, item):
content = self.get()
if content == None and callable(type(item)):
content = type(item)()
if isinstance(content, dict) and isinstance(item, dict):
content.update(item)
elif isinstance(content, list) and item not in content:
content.append(item)
else:
return
udB.set_key(self._key, content)
def remove(self, item):
content = self.get()
if isinstance(content, list) and item in content:
content.remove(item)
elif isinstance(content, dict) and content.get(item):
del content[item]
else:
return
udB.set_key(self._key, content)
def contains(self, item):
return item in self.get()

View File

@@ -1,33 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_channels(): # Returns List
return udB.get_key("BROADCAST") or []
def is_channel_added(id_):
return id_ in get_channels()
def add_channel(id_):
channels = get_channels()
if id_ not in channels:
channels.append(id_)
udB.set_key("BROADCAST", channels)
return True
def rem_channel(id_):
channels = get_channels()
if id_ in channels:
channels.remove(id_)
udB.set_key("BROADCAST", channels)
return True
return False

View File

@@ -1,71 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_source_channels(): # Returns List
return udB.get_key("CH_SOURCE") or []
def get_no_source_channels(): # Returns List
channels = udB.get_key("CH_SOURCE") or []
return len(channels)
def is_source_channel_added(id_):
channels = get_source_channels()
return id_ in channels
def add_source_channel(id_): # Take int or str with numbers only , Returns Boolean
channels = get_source_channels()
if id_ not in channels:
channels.append(id_)
udB.set_key("CH_SOURCE", channels)
return True
def rem_source_channel(id_):
channels = get_source_channels()
if id_ in channels:
channels.remove(id_)
udB.set_key("CH_SOURCE", channels)
return True
#########################
def get_destinations(): # Returns List
return udB.get_key("CH_DESTINATION") or []
def get_no_destinations(): # Returns List
channels = udB.get_key("CH_DESTINATION") or []
return len(channels)
def is_destination_added(id_):
channels = get_destinations()
return id_ in channels
def add_destination(id_): # Take int or str with numbers only , Returns Boolean
channels = get_destinations()
if id_ not in channels:
channels.append(id_)
udB.set_key("CH_DESTINATION", channels)
return True
def rem_destination(id_):
channels = get_destinations()
if id_ in channels:
channels.remove(id_)
udB.set_key("CH_DESTINATION", channels)
return True

View File

@@ -1,29 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_dnd_chats():
return udB.get_key("DND_CHATS") or []
def add_dnd(chat_id):
x = get_dnd_chats()
x.append(int(chat_id))
return udB.set_key("DND_CHATS", x)
def del_dnd(chat_id):
x = get_dnd_chats()
x.remove(int(chat_id))
return udB.set_key("DND_CHATS", x)
def chat_in_dnd(chat_id):
return int(chat_id) in get_dnd_chats()

View File

@@ -1,29 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_stuff():
return udB.get_key("GBLACKLISTS") or []
def add_gblacklist(id):
ok = get_stuff()
if id not in ok:
ok.append(id)
return udB.set_key("GBLACKLISTS", ok)
def rem_gblacklist(id):
ok = get_stuff()
if id in ok:
ok.remove(id)
return udB.set_key("GBLACKLISTS", ok)
def is_gblacklisted(id):
return id in get_stuff()

View File

@@ -1,28 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_logger():
return udB.get_key("LOGUSERS") or []
def is_logger(id_):
return id_ in get_logger()
def log_user(id_):
pmperm = get_logger()
pmperm.append(id_)
return udB.set_key("LOGUSERS", pmperm)
def nolog_user(id_):
pmperm = get_logger()
pmperm.remove(id_)
return udB.set_key("LOGUSERS", pmperm)

View File

@@ -1,27 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def night_grps():
return udB.get_key("NIGHT_CHATS") or []
def add_night(chat):
chats = night_grps()
if chat not in chats:
chats.append(chat)
return udB.set_key("NIGHT_CHATS", chats)
return
def rem_night(chat):
chats = night_grps()
if chat in chats:
chats.remove(chat)
return udB.set_key("NIGHT_CHATS", chats)

View File

@@ -1,31 +0,0 @@
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://github.com/TeamUltroid/pyUltroid/blob/main/LICENSE>.
from .. import udB
def get_approved():
return udB.get_key("PMPERMIT") or []
def approve_user(id):
ok = get_approved()
if id in ok:
return True
ok.append(id)
return udB.set_key("PMPERMIT", ok)
def disapprove_user(id):
ok = get_approved()
if id in ok:
ok.remove(id)
return udB.set_key("PMPERMIT", ok)
def is_approved(id):
return id in get_approved()