Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from Astrako:master #14

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 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
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
5 changes: 5 additions & 0 deletions AstrakoBot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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 +131,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 +149,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
10 changes: 5 additions & 5 deletions AstrakoBot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
StartTime,
telethn,
updater,
DROP_UPDATES,
)

# needed to dynamically load modules
Expand Down Expand Up @@ -660,12 +661,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
17 changes: 2 additions & 15 deletions AstrakoBot/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ 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
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 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
26 changes: 14 additions & 12 deletions AstrakoBot/modules/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from AstrakoBot.modules.github import getphh
from AstrakoBot.modules.helper_funcs.misc import delete

rget_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
}

def magisk(update: Update, context: CallbackContext):
message = update.effective_message
Expand Down Expand Up @@ -55,14 +58,15 @@ def checkfw(update: Update, context: CallbackContext):
temp, csc = args
model = f'sm-' + temp if not temp.upper().startswith('SM-') else temp
fota = get(
f'http://fota-cloud-dn.ospserver.net/firmware/{csc.upper()}/{model.upper()}/version.xml'
f'https://fota-cloud-dn.ospserver.net/firmware/{csc.upper()}/{model.upper()}/version.xml',
headers=rget_headers
)

if fota.status_code != 200:
msg = f"Couldn't check for {temp.upper()} and {csc.upper()}, please refine your search or try again later!"

else:
page = BeautifulSoup(fota.content, 'lxml')
page = BeautifulSoup(fota.content, 'xml')
os = page.find("latest").get("o")

if page.find("latest").text.strip():
Expand Down Expand Up @@ -102,7 +106,8 @@ def getfw(update: Update, context: CallbackContext):
temp, csc = args
model = f'sm-' + temp if not temp.upper().startswith('SM-') else temp
fota = get(
f'http://fota-cloud-dn.ospserver.net/firmware/{csc.upper()}/{model.upper()}/version.xml'
f'https://fota-cloud-dn.ospserver.net/firmware/{csc.upper()}/{model.upper()}/version.xml',
headers=rget_headers
)

if fota.status_code != 200:
Expand All @@ -113,10 +118,7 @@ def getfw(update: Update, context: CallbackContext):
url2 = f'https://www.sammobile.com/samsung/firmware/{model.upper()}/{csc.upper()}/'
url3 = f'https://sfirmware.com/samsung-{model.lower()}/#tab=firmwares'
url4 = f'https://samfw.com/firmware/{model.upper()}/{csc.upper()}/'
fota = get(
f'http://fota-cloud-dn.ospserver.net/firmware/{csc.upper()}/{model.upper()}/version.xml'
)
page = BeautifulSoup(fota.content, 'lxml')
page = BeautifulSoup(fota.content, 'xml')
os = page.find("latest").get("o")
msg = ""
if page.find("latest").text.strip():
Expand All @@ -129,10 +131,10 @@ def getfw(update: Update, context: CallbackContext):
msg += f'• Android: `{os}`\n'
msg += '\n'
msg += f'*Downloads for {model.upper()} and {csc.upper()}*\n'
btn = [[InlineKeyboardButton(text=f"samfrew.com", url = url1)]]
btn += [[InlineKeyboardButton(text=f"sammobile.com", url = url2)]]
btn += [[InlineKeyboardButton(text=f"sfirmware.com", url = url3)]]
btn += [[InlineKeyboardButton(text=f"samfw.com", url = url4)]]
btn = [[InlineKeyboardButton(text=f"Samfrew", url = url1)]]
btn += [[InlineKeyboardButton(text=f"Sammobile", url = url2)]]
btn += [[InlineKeyboardButton(text=f"SFirmware", url = url3)]]
btn += [[InlineKeyboardButton(text=f"Samfw (Recommended)", url = url4)]]
else:
msg = 'Give me something to fetch, like:\n`/getfw SM-N975F DBT`'

Expand Down Expand Up @@ -240,7 +242,7 @@ def orangefox(update: Update, context: CallbackContext):
version = page["version"]
changelog = page["changelog"][0]
size = str(round(float(page["size"]) / 1024 / 1024, 1)) + "MB"
dl_link = page["mirrors"]["NL"]
dl_link = page["mirrors"]["US"]
date = datetime.fromtimestamp(page["date"])
md5 = page["md5"]
msg = f"*Latest OrangeFox Recovery for the {full_name}*\n\n"
Expand Down
10 changes: 5 additions & 5 deletions AstrakoBot/modules/antiflood.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def check_flood(update: Update, context: CallbackContext) -> str:
if not user: # ignore channels
return ""

# ignore admins and whitelists
if is_user_admin(chat, user.id) or user.id in WHITELIST_USERS:
# ignore admins, whitelists and telegram's native tech
if is_user_admin(chat, user.id) or user.id in WHITELIST_USERS or user.id == 777000:
sql.update_flood(chat.id, None)
return ""
# ignore approved users
Expand All @@ -54,11 +54,11 @@ def check_flood(update: Update, context: CallbackContext) -> str:
try:
getmode, getvalue = sql.get_flood_setting(chat.id)
if getmode == 1:
chat.kick_member(user.id)
chat.ban_member(user.id)
execstrings = "Banned"
tag = "BANNED"
elif getmode == 2:
chat.kick_member(user.id)
chat.ban_member(user.id)
chat.unban_member(user.id)
execstrings = "Kicked"
tag = "KICKED"
Expand All @@ -70,7 +70,7 @@ def check_flood(update: Update, context: CallbackContext) -> str:
tag = "MUTED"
elif getmode == 4:
bantime = extract_time(msg, getvalue)
chat.kick_member(user.id, until_date=bantime)
chat.ban_member(user.id, until_date=bantime)
execstrings = "Banned for {}".format(getvalue)
tag = "TBAN"
elif getmode == 5:
Expand Down
7 changes: 5 additions & 2 deletions AstrakoBot/modules/approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ def approved(update: Update, context: CallbackContext):
msg = "The following users are approved.\n"
approved_users = sql.list_approved(message.chat_id)
for i in approved_users:
member = chat.get_member(int(i.user_id))
msg += f"- `{i.user_id}`: {member.user['first_name']}\n"
try:
member = chat.get_member(int(i.user_id))
msg += f"- `{i.user_id}`: {member.user['first_name']}\n"
except BadRequest:
sql.disapprove(message.chat_id, i.user_id)
if msg.endswith("approved.\n"):
message.reply_text(f"No users are approved in {chat_title}.")
return ""
Expand Down
24 changes: 17 additions & 7 deletions AstrakoBot/modules/bans.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
user_admin,
user_can_ban,
can_delete,
is_bot_admin,
)
from AstrakoBot.modules.helper_funcs.extraction import extract_user_and_text
from AstrakoBot.modules.helper_funcs.string_handling import extract_time
Expand Down Expand Up @@ -100,7 +101,7 @@ def ban(update: Update, context: CallbackContext) -> str:
log += "\n<b>Reason:</b> {}".format(reason)

try:
chat.kick_member(user_id)
chat.ban_member(user_id)

if silent:
if message.reply_to_message:
Expand Down Expand Up @@ -199,7 +200,7 @@ def temp_ban(update: Update, context: CallbackContext) -> str:
log += "\n<b>Reason:</b> {}".format(reason)

try:
chat.kick_member(user_id, until_date=bantime)
chat.ban_member(user_id, until_date=bantime)
bot.sendMessage(
chat.id,
f"Banned! User {mention_html(member.user.id, html.escape(member.user.first_name))} "
Expand Down Expand Up @@ -353,11 +354,8 @@ def unban(update: Update, context: CallbackContext) -> str:
return log


@connection_status
@bot_admin
@can_restrict
@gloggable
def selfunban(context: CallbackContext, update: Update) -> str:
def selfunban(update: Update, context: CallbackContext) -> str:
message = update.effective_message
user = update.effective_user
bot, args = context.bot, context.args
Expand All @@ -370,7 +368,19 @@ def selfunban(context: CallbackContext, update: Update) -> str:
message.reply_text("Give a valid chat ID.")
return

chat = bot.getChat(chat_id)
try:
chat = bot.getChat(chat_id)
except:
message.reply_text("It doesn't look like I'm listed as a member of this chat.")
return

if (chat.type == "private"):
message.reply_text("How am i going to unban you from a private chat?")
return

if not is_bot_admin(chat, bot.id):
message.reply_text("I'm sorry but i am not an admin there!")
return

try:
member = chat.get_member(user.id)
Expand Down
4 changes: 2 additions & 2 deletions AstrakoBot/modules/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def del_blacklist(update: Update, context: CallbackContext):
return
elif getmode == 5:
message.delete()
chat.kick_member(user.id)
chat.ban_member(user.id)
bot.sendMessage(
chat.id,
f"Banned {user.first_name} for using Blacklisted word: {trigger}",
Expand All @@ -396,7 +396,7 @@ def del_blacklist(update: Update, context: CallbackContext):
elif getmode == 6:
message.delete()
bantime = extract_time(message, value)
chat.kick_member(user.id, until_date=bantime)
chat.ban_member(user.id, until_date=bantime)
bot.sendMessage(
chat.id,
f"Banned {user.first_name} until '{value}' for using Blacklisted word: {trigger}!",
Expand Down
4 changes: 2 additions & 2 deletions AstrakoBot/modules/blacklist_stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def del_blackliststicker(update: Update, context: CallbackContext):
return
elif getmode == 5:
message.delete()
chat.kick_member(user.id)
chat.ban_member(user.id)
bot.sendMessage(
chat.id,
"{} banned because using '{}' which in blacklist stickers".format(
Expand All @@ -435,7 +435,7 @@ def del_blackliststicker(update: Update, context: CallbackContext):
elif getmode == 6:
message.delete()
bantime = extract_time(message, value)
chat.kick_member(user.id, until_date=bantime)
chat.ban_member(user.id, until_date=bantime)
bot.sendMessage(
chat.id,
"{} banned for {} because using '{}' which in blacklist stickers".format(
Expand Down
Loading