Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
4ecf70c
cron_jobs: backup the database daily
itsLuuke Dec 23, 2021
8d37b7e
gitignore: add shell_output.txt to ignore
Astrako Dec 23, 2021
812a085
ptb: telegram deprecation
Astrako Dec 27, 2021
72cd5c6
Solution for stickers giving same results two times (#40)
cullobsidian7 Dec 30, 2021
2c07617
locks: Added anonchannel & fixes
soulr344 Dec 11, 2021
7b3f350
userinfo: fix `/info` when replying or invoked as a channel
itsLuuke Dec 29, 2021
b175641
feds: telegram deprecation
Astrako Jan 3, 2022
6cd5293
feds: fedadmins: handle deleted accounts
Dank-del Jan 3, 2022
f5db48c
notes: minor fixes and formatting
Astrako Jan 3, 2022
3460b38
welcome: minor fix and formatting
Astrako Jan 4, 2022
263c0f9
requirements: bump ptb version to 3.10
Astrako Jan 4, 2022
d5e5106
README: update ptb badge
Astrako Jan 4, 2022
bfdbb0a
locks: add missing context for bot
Astrako Jan 5, 2022
9f9bb9f
welcome: disable web_page_preview when bot is added to group
Astrako Jan 9, 2022
5fb31de
user_info: add missingh run_async for about_bio
Astrako Jan 9, 2022
68590f3
user_info: ugly workaround to fix getting about info from user
Astrako Jan 9, 2022
32f51f4
android: fix orangefox mirror again
Astrako Jan 14, 2022
0453b17
muting: fixup problem while checking if user is muted (#41)
Gabriel2392 Jan 15, 2022
957c91a
Must provide reason for fbanning & gbanning. (#42)
el0xren Jan 23, 2022
a1c9dcd
super_users: fix bug for sudos (#43)
itsLuuke Jan 23, 2022
3c99517
super_users: bug fixes (#44)
itsLuuke Jan 23, 2022
c34118b
requirements: bump ptb version to 3.11
Astrako Feb 3, 2022
917f1a0
README: update ptb badge
Astrako Feb 3, 2022
509845c
welcome: fix getting the noformat version of the welcome-goodbye
itsLuuke Feb 9, 2022
e6943ec
admin: remove bots from list and fix creator not being showed
Astrako Feb 17, 2022
d282d0c
Added Air Quality Index (#45)
aaisalu Feb 22, 2022
d4d406e
feds: add except when chat is not found for fedadmins
Astrako Mar 25, 2022
d826410
feds: add except when chat is not found for fechats
Astrako Mar 28, 2022
1409f42
feds: fix wrong indent in feds
itsLuuke Apr 13, 2022
569c339
feds: refractor fed_ban
itsLuuke Apr 13, 2022
8278f6c
feds: start working on enforcing fed bans
itsLuuke Apr 13, 2022
d8a1dff
admin_status: new module
itsLuuke Apr 13, 2022
a482291
admin_status: use chat instead of update in user_is_admin func
itsLuuke Apr 13, 2022
acf6ee5
feds: enforce_fban uses funcs from new admin_status module
itsLuuke Apr 13, 2022
e1313bc
global_bans: refractor enforce_gban and uses funcs from new admin_sta…
itsLuuke Apr 13, 2022
02f4ac3
feds: fix minor conditional in enforce_fed
itsLuuke Apr 13, 2022
801d0e6
users: add more logging to log_user
itsLuuke Apr 13, 2022
3a4507f
feds: fix missing arg for check_and_ban
itsLuuke Apr 13, 2022
200bd91
feds: more refractoring
itsLuuke Apr 13, 2022
d7b94c0
main: specify the allowed updates
itsLuuke Apr 13, 2022
32ca12e
requirements: bump ptb version to 13.13
Astrako Jul 15, 2022
a4be0d3
requirements: bump ptb version to 13.14
Astrako Sep 16, 2022
82a6fa4
requirements: replace old markdown2 repo
Astrako Sep 16, 2022
2d2bf28
requirements.: revert to old emoji pip package
Astrako Oct 6, 2022
e9ae91c
add DROP_UPDATES var and startup script
itsLuuke Oct 12, 2022
088053f
bans: Fix roar
Gabriel2392 Mar 3, 2023
44a3340
muting: add s-mute s-unmute and s-tmute
Gabriel2392 Mar 3, 2023
5f43179
warns: check if the value is within an acceptable range before setting
Gabriel2392 Mar 4, 2023
ac259f4
super_users: Fix typo
Gabriel2392 Mar 4, 2023
e7573db
wallpapers: use pixabay api
Gabriel2392 Mar 4, 2023
8c67994
github: repository should have a release file in order to use the cmd
Gabriel2392 Mar 4, 2023
5148bea
gtranslator: Rewrite
Gabriel2392 Mar 4, 2023
3078dbd
youtube: Rework using pytube
Gabriel2392 Mar 4, 2023
7afbe00
ud: send message as plain text if markdown failed
Gabriel2392 Mar 5, 2023
1cf0a0a
requirements: add moviepy
Gabriel2392 Mar 6, 2023
b279c9f
youtube: allow audio-only
Gabriel2392 Mar 7, 2023
ce3ead8
gtranslator: default to english if no args
Gabriel2392 Mar 7, 2023
d85e7bc
warns: add rmwarn
Gabriel2392 Mar 7, 2023
65c1162
super_users: don't print deleted accounts
Gabriel2392 Mar 7, 2023
5179271
global_bans: fix deprecated call
Gabriel2392 Mar 7, 2023
81856f6
cron: split the backup file into 45mb since bots can't send files lar…
itsLuuke Mar 20, 2023
8a99d89
warns: do not reply to non-existent messages (#51)
Gabriel2392 Apr 3, 2023
3997467
userinfo: Don't fail when there is no username
Gabriel2392 May 7, 2023
c887216
antiflood: Don't try to mute group's linked channel
Gabriel2392 May 7, 2023
16e8610
warns: allow_sending_without_reply=True on warn
itsLuuke May 7, 2023
f38dae3
specify sqlalchemy version in requirements
itsLuuke May 7, 2023
5302b2c
android: Fix getfw and checkfw
Gabriel2392 Aug 19, 2023
647368c
use chatmember updates for welcome/goodbye
itsLuuke Jul 19, 2023
1a013bd
make regex work for sudo users only
itsLuuke Oct 12, 2023
4df3e4e
approvals: fix /approved when user is deleted
itsLuuke Nov 24, 2023
1a6e6a2
fix regex to work with python 3.11
itsLuuke Apr 23, 2024
650b1ee
update stickers to support new BotAPI version
itsLuuke Apr 23, 2024
4ea0e6c
cash: Change API
Gabriel2392 Mar 15, 2025
fa06aa4
super_users: Fix BadRequest
Gabriel2392 Mar 15, 2025
59d26f6
modules: Add linux
Gabriel2392 Mar 15, 2025
df8f0a3
android: Add kernelsu
Gabriel2392 Mar 16, 2025
fd2bab4
modules: Add QR Code En/Decoder
Gabriel2392 Mar 16, 2025
57dc844
qr_code: Check file size before downloading
Gabriel2392 Mar 16, 2025
3feddc4
status: Add network usage
Gabriel2392 Mar 16, 2025
843d988
status: Fix ram percentage
Gabriel2392 Mar 16, 2025
30e4bf5
temp_mute: Always mute
Gabriel2392 Mar 16, 2025
36e274e
paste: change API to dpaste
Gabriel2392 Mar 18, 2025
d14fbd1
quotly: Also accept /q
Gabriel2392 Mar 18, 2025
d33a4b4
welcome: Stickers do not have caption
Gabriel2392 Mar 19, 2025
a9b5bde
msg_types: Fix list index out of range
Gabriel2392 Mar 20, 2025
dc23887
msg_types: Fix replying to plain text
Gabriel2392 Mar 20, 2025
a56f480
global_bans: Fix Message to be replied not found
Gabriel2392 Mar 20, 2025
4b10733
welcome: Fix typo
Gabriel2392 Mar 20, 2025
bcdbccf
tts: Fix some issues
Gabriel2392 Mar 20, 2025
5b0271a
fun: Remove duplicated weebify module
Gabriel2392 Mar 20, 2025
d886209
weebify: Fix invalid text parsing
Gabriel2392 Mar 20, 2025
969e1a3
extract_time: Fix overflow
Gabriel2392 Mar 20, 2025
13b5ebe
sanitize: Update gifs IDs
Gabriel2392 Mar 20, 2025
fc50875
users_sql: Fix attribute error
Gabriel2392 Mar 20, 2025
f0db182
backups: Handle invalid/corrupted backups
Gabriel2392 Mar 20, 2025
4de1b36
chat_checker: Ignore TimedOut
Gabriel2392 Mar 20, 2025
ecf94fa
ungban: Use effective_chat
Gabriel2392 Mar 20, 2025
c877fba
feds: Check for current federation
Gabriel2392 Mar 20, 2025
03983c9
fpromote/fdemote: Fix user parsing
Gabriel2392 Mar 20, 2025
339fba5
chat_checker: Use admin_status module
Gabriel2392 Mar 20, 2025
2f69f87
muting: Handle insufficient permissions
Gabriel2392 Mar 20, 2025
02ab6d3
modules: Make use of admin_status module
Gabriel2392 Mar 20, 2025
304b58b
backups: Handle non-json files
Gabriel2392 Mar 20, 2025
84d90eb
fun: Remove duplicated shout cmd
Gabriel2392 Mar 20, 2025
a817915
shout: Check for input text
Gabriel2392 Mar 20, 2025
9f550c7
modules: Empty strings are considered falsy
Gabriel2392 Mar 20, 2025
632826f
newfed: Properly check for fed name
Gabriel2392 Mar 20, 2025
831238c
plet: Misc error fixes
Gabriel2392 Mar 21, 2025
2f326bf
super_users: Print deleted accounts as zombies
Gabriel2392 Mar 21, 2025
92faa81
clear_cmd: Parse time
Gabriel2392 Mar 21, 2025
f7ab64c
logs: Don't crash when log is too big
Gabriel2392 Mar 21, 2025
66f3699
github: phh -> TrebleDroid
Gabriel2392 Mar 22, 2025
b0adb17
orangefox: Fix mirror
Gabriel2392 Mar 22, 2025
f9c4c37
orangefox: Fix crash if device isn't supported
Gabriel2392 Mar 22, 2025
7f3fb97
tts: Return detailed error
Gabriel2392 Mar 23, 2025
d343ec0
wiki: Correct variable name
Gabriel2392 Mar 23, 2025
c7984c7
tts: Fix file removal
Gabriel2392 Mar 23, 2025
794466d
Remove useless logs
Gabriel2392 Mar 23, 2025
b117174
chat_status: Handle no user
Gabriel2392 Mar 23, 2025
c48ec75
welcome: Check if bot can restrict first
Gabriel2392 Mar 23, 2025
519c0f2
welcome: Stickers do not have caption [2]
Gabriel2392 Mar 23, 2025
36369c5
welcome: Fix bugs
Gabriel2392 Mar 23, 2025
6779284
admin_status: Return falsy member to avoid crashes related to bot member
Gabriel2392 Mar 23, 2025
f8f6d59
welcome: No need to check for welcome type
Gabriel2392 Mar 24, 2025
be264d6
feds: Fix crash when fed owner has blocked bot
Gabriel2392 Mar 24, 2025
2fedd84
notes: Fix infinite newlines
Gabriel2392 Mar 24, 2025
87f91df
github: first -> first_name
Gabriel2392 Mar 24, 2025
6485279
warns: Uncomment reply
Gabriel2392 Mar 25, 2025
605a674
muting/warns: Check if user is ban protected instead
Gabriel2392 Mar 25, 2025
45206fe
muting: Use decorator
Gabriel2392 Mar 25, 2025
51e8f67
warns/muting: Check if user can restrict
Gabriel2392 Mar 25, 2025
b5ec164
welcome: Fix mistake
Gabriel2392 Mar 26, 2025
f49fd76
orangefox: Find first mirror
Gabriel2392 Apr 6, 2025
68703f4
welcome: Fix /welcome for documents and stickers
Gabriel2392 Apr 6, 2025
f372e5d
cust_filters: Format only chat name
Gabriel2392 Apr 6, 2025
5e6e6a7
log_channel: Handle bot removal
Gabriel2392 Apr 6, 2025
dafbf75
welcome: Handle topic closed
Gabriel2392 Apr 6, 2025
42bf7eb
init: Reduce log spam even more
Gabriel2392 Apr 6, 2025
520ca0b
quotly: Fix replying to channels
Gabriel2392 Apr 6, 2025
15a123f
bans: Handle insufficient 'delete messages' permission
Gabriel2392 Apr 6, 2025
fb6d1a5
quotly: Handle members that left chat
Gabriel2392 Apr 6, 2025
7caef2e
quotly: Fix sending as channel
Gabriel2392 Apr 6, 2025
b3df7cf
quotly: Add fonts to repo
Gabriel2392 Apr 6, 2025
8d84f90
fedadmins: Fixes
Gabriel2392 Apr 12, 2025
d6a4b55
feds: Escape federation name when HTML is used
Gabriel2392 Apr 21, 2025
10d21f5
purge: Remove duplicated call
Gabriel2392 Apr 21, 2025
387c7bc
Revert "quotly: Also accept /q"
Gabriel2392 Apr 21, 2025
a447036
disable: Handle no id
Gabriel2392 Apr 21, 2025
7faf16b
userinfo: Fix ginfo
Gabriel2392 Apr 21, 2025
015a511
feds: Escape some more calls
Gabriel2392 Apr 21, 2025
e14d574
chat_status: Do not reply to unprivileged users
Gabriel2392 Apr 25, 2025
2d30efd
feds: Remove admin check for fedinfo
Gabriel2392 May 7, 2025
528a5cc
Allow disabling android cmds
Gabriel2392 May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ dmypy.json
.vscode

# Others
backups/
*.mp3
*.mp4
*.otf
*.png
*.ttf
shell_output.txt
error.txt
9 changes: 9 additions & 0 deletions AstrakoBot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
)

LOGGER = logging.getLogger(__name__)
log_warning_only = ["telethon.client.updates", "apscheduler.scheduler", "apscheduler.executors.default", "telethon.network.mtprotosender", "telethon.client"]

for i in log_warning_only:
logging.getLogger(i).setLevel(logging.WARNING)

# if version < 3.6, stop bot.
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
Expand Down Expand Up @@ -83,6 +87,8 @@
WEATHER_API = os.environ.get("WEATHER_API", None)

ALLOW_CHATS = os.environ.get("ALLOW_CHATS", True)
BACKUP_PASS = os.environ.get("BACKUP_PASS", True)
DROP_UPDATES = os.environ.get("DROP_UPDATES", False)

try:
BL_CHATS = set(int(x) for x in os.environ.get("BL_CHATS", "").split())
Expand Down Expand Up @@ -129,6 +135,7 @@
API_HASH = Config.API_HASH

DB_URI = Config.SQLALCHEMY_DATABASE_URI
DB_NAME = Config.DB_NAME
DONATION_LINK = Config.DONATION_LINK
LOAD = Config.LOAD
NO_LOAD = Config.NO_LOAD
Expand All @@ -146,6 +153,8 @@
SPAMWATCH_API = Config.SPAMWATCH_API
INFOPIC = Config.INFOPIC
WEATHER_API = Config.WEATHER_API
BACKUP_PASS = Config.BACKUP_PASS
DROP_UPDATES = Config.DROP_UPDATES

try:
BL_CHATS = set(int(x) for x in Config.BL_CHATS or [])
Expand Down
67 changes: 18 additions & 49 deletions AstrakoBot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
StartTime,
telethn,
updater,
DROP_UPDATES,
)

# needed to dynamically load modules
# NOTE: Module order is not guaranteed, specify that in the config file!
from AstrakoBot.modules import ALL_MODULES
from AstrakoBot.modules.helper_funcs.chat_status import is_user_admin
from AstrakoBot.modules.helper_funcs.admin_status import user_is_admin
from AstrakoBot.modules.helper_funcs.misc import paginate_modules
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ParseMode, Update
from telegram.error import (
Expand Down Expand Up @@ -169,13 +170,6 @@ def send_help(chat_id, text, keyboard=None):
)


def test(update: Update, context: CallbackContext):
# pprint(eval(str(update)))
# update.effective_message.reply_text("Hola tester! _I_ *have* `markdown`", parse_mode=ParseMode.MARKDOWN)
update.effective_message.reply_text("This person edited a message")
print(update.effective_message)


def start(update: Update, context: CallbackContext):
args = context.args
uptime = get_readable_time((time.time() - StartTime))
Expand All @@ -202,7 +196,7 @@ def start(update: Update, context: CallbackContext):
match = re.match("stngs_(.*)", args[0].lower())
chat = dispatcher.bot.getChat(match.group(1))

if is_user_admin(chat, update.effective_user.id):
if user_is_admin(chat, update.effective_user.id):
send_settings(match.group(1), update.effective_user.id, False)
else:
send_settings(match.group(1), update.effective_user.id, True)
Expand Down Expand Up @@ -256,43 +250,23 @@ def start(update: Update, context: CallbackContext):
),
)
else:
update.effective_message.reply_text(
"I'm awake already!\n<b>Haven't slept since:</b> <code>{}</code>".format(
uptime
),
parse_mode=ParseMode.HTML,
)

try:
update.effective_message.reply_text(
"I'm awake already!\n<b>Haven't slept since:</b> <code>{}</code>".format(
uptime
),
parse_mode=ParseMode.HTML,
)
except BadRequest:
pass # chat_checker will take care of it, just don't error

# for test purposes
def error_callback(update: Update, context: CallbackContext):
error = context.error
try:
raise error
except Unauthorized:
print("no nono1")
print(error)
# remove update.message.chat_id from conversation list
except BadRequest:
print("no nono2")
print("BadRequest caught")
print(error)

# handle malformed requests - read more below!
except TimedOut:
print("no nono3")
# handle slow connection problems
except NetworkError:
print("no nono4")
# handle other connection problems
except ChatMigrated as err:
print("no nono5")
print(err)
# the chat_id of a group has changed, use e.new_chat_id instead
except TelegramError:
except:
print(error)
# handle all other telegram related errors


def help_button(update: Update, context: CallbackContext):
query = update.callback_query
Expand All @@ -301,8 +275,6 @@ def help_button(update: Update, context: CallbackContext):
next_match = re.match(r"help_next\((.+?)\)", query.data)
back_match = re.match(r"help_back", query.data)

print(query.message.chat.id)

try:
if mod_match:
module = mod_match.group(1)
Expand Down Expand Up @@ -548,7 +520,7 @@ def get_settings(update: Update, context: CallbackContext):

# ONLY send settings in PM
if chat.type != chat.PRIVATE:
if is_user_admin(chat, user.id):
if user_is_admin(chat, user.id):
text = "Click here to get this chat's settings, as well as yours."
msg.reply_text(
text,
Expand Down Expand Up @@ -626,7 +598,6 @@ def migrate_chats(update: Update, context: CallbackContext):


def main():
test_handler = CommandHandler("test", test, run_async=True)
start_handler = CommandHandler("start", start, run_async=True)

help_handler = CommandHandler("help", get_help, run_async=True)
Expand All @@ -638,7 +609,6 @@ def main():
donate_handler = CommandHandler("donate", donate, run_async=True)
migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats)

# dispatcher.add_handler(test_handler)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(help_handler)
dispatcher.add_handler(settings_handler)
Expand All @@ -660,12 +630,11 @@ def main():

else:
LOGGER.info("Using long polling.")
updater.start_polling(timeout=15, read_latency=4, drop_pending_updates=True)
allowed_updates = ['message', 'edited_message', 'callback_query', 'callback_query', 'my_chat_member',
'chat_member', 'chat_join_request', 'channel_post', 'edited_channel_post', 'inline_query']
updater.start_polling(timeout=15, read_latency=4, drop_pending_updates=DROP_UPDATES, allowed_updates = allowed_updates)

if len(argv) not in (1, 3, 4):
telethn.disconnect()
else:
telethn.run_until_disconnected()
telethn.run_until_disconnected()

updater.idle()

Expand Down
27 changes: 7 additions & 20 deletions AstrakoBot/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
user_admin,
ADMIN_CACHE,
)

from AstrakoBot.modules.helper_funcs.admin_status import get_bot_member
from AstrakoBot.modules.helper_funcs.extraction import (
extract_user,
extract_user_and_text,
Expand Down Expand Up @@ -68,7 +68,7 @@ def promote(update: Update, context: CallbackContext) -> str:
return

# set same perms as bot - bot can't assign higher perms than itself!
bot_member = chat.get_member(bot.id)
bot_member = get_bot_member(chat.id)

try:
bot.promoteChatMember(
Expand Down Expand Up @@ -358,7 +358,7 @@ def invite(update: Update, context: CallbackContext):
if chat.username:
update.effective_message.reply_text(f"https://t.me/{chat.username}")
elif chat.type in [chat.SUPERGROUP, chat.CHANNEL]:
bot_member = chat.get_member(bot.id)
bot_member = get_bot_member(chat.id)
if bot_member.can_invite_users:
invitelink = bot.exportChatInviteLink(chat.id)
update.effective_message.reply_text(invitelink)
Expand Down Expand Up @@ -399,14 +399,12 @@ def adminlist(update: Update, context: CallbackContext):
administrators = bot.getChatAdministrators(chat_id)
text = "Admins in <b>{}</b>:".format(html.escape(update.effective_chat.title))

bot_admin_list = []

for admin in administrators:
user = admin.user
status = admin.status
custom_title = admin.custom_title

if user.first_name == "":
if not user.first_name:
name = "☠ Deleted Account"
else:
name = "{}".format(
Expand All @@ -415,19 +413,12 @@ def adminlist(update: Update, context: CallbackContext):
)
)

if user.is_bot:
bot_admin_list.append(name)
administrators.remove(admin)
continue

# if user.username:
# name = escape_markdown("@" + user.username)
if status == "creator":
text += "\n 👑 Creator:"
text += "\n<code> • </code>{}\n".format(name)

if custom_title:
text += f"<code> ┗━ {html.escape(custom_title)}</code>\n"
# if user.username:
# name = escape_markdown("@" + user.username)

text += "\n🔱 Admins:"

Expand All @@ -439,7 +430,7 @@ def adminlist(update: Update, context: CallbackContext):
status = admin.status
custom_title = admin.custom_title

if user.first_name == "":
if not user.first_name:
name = "☠ Deleted Account"
else:
name = "{}".format(
Expand Down Expand Up @@ -475,10 +466,6 @@ def adminlist(update: Update, context: CallbackContext):
text += "\n<code> • </code>{}".format(admin)
text += "\n"

text += "\n🤖 Bots:"
for each_bot in bot_admin_list:
text += "\n<code> • </code>{}".format(each_bot)

try:
msg.edit_text(text, parse_mode=ParseMode.HTML)
except BadRequest: # if original message is deleted
Expand Down
2 changes: 1 addition & 1 deletion AstrakoBot/modules/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def __gdpr__(user_id):

AFK_HANDLER = DisableAbleCommandHandler("afk", afk, run_async=True)
AFK_REGEX_HANDLER = DisableAbleMessageHandler(
Filters.regex(r"^(?i)brb(.*)$"), afk, friendly="afk"
Filters.regex(r"(?i)^brb(.*)$"), afk, friendly="afk"
)
NO_AFK_HANDLER = MessageHandler(Filters.all & Filters.chat_type.groups, no_longer_afk, run_async=True)
AFK_REPLY_HANDLER = MessageHandler(Filters.all & Filters.chat_type.groups, reply_afk, run_async=True)
Expand Down
Loading