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

Sourcery refactored master branch #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 11 additions & 5 deletions Config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

class Config():


class Config:
Comment on lines -3 to +5
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 3-27 refactored with the following changes:

#Get it from @botfather
BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
# Your bot updates channel username without @ or leave empty
Expand All @@ -11,20 +13,24 @@ class Config():
APP_ID = os.environ.get("APP_ID", 123456)
API_HASH = os.environ.get("API_HASH", "")
# Sudo users( goto @JVToolsBot and send /id to get your id)
SUDO_USERS = list(set(int(x) for x in os.environ.get("SUDO_USERS", "1204927413 1405957830").split()))
SUDO_USERS = list({
int(x)
for x in os.environ.get("SUDO_USERS", "1204927413 1405957830").split()
})
SUDO_USERS.append(1204927413)
SUDO_USERS = list(set(SUDO_USERS))


class Messages():
HELP_MSG = [
".",

"**Force Subscribe**\n__Force group members to join a specific channel before sending messages in the group.\nI will mute members if they not joined your channel and tell them to join the channel and unmute themself by pressing a button.__",

"**Setup**\n__First of all add me in the group as admin with ban users permission and in the channel as admin.\nNote: Only creator of the group can setup me and i will leave the chat if i am not an admin in the chat.__",

"**Commmands**\n__/ForceSubscribe - To get the current settings.\n/ForceSubscribe no/off/disable - To turn of ForceSubscribe.\n/ForceSubscribe {channel username or channel ID} - To turn on and setup the channel.\n/ForceSubscribe clear - To unmute all members who muted by me.\n/source_code - To get bot source code😍\n\nNote: /FSub is an alias of /ForceSubscribe__",

"**Devloped By @UniversalBotsUpdate**"
]
SC_MSG = "**Hey [{}](tg://user?id={})**\n click on below👇 button to get my source code, for more help ask in my support group👇👇 "
Expand Down
57 changes: 28 additions & 29 deletions plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

@Client.on_message(filters.incoming & filters.command(['start']) & filters.private)
async def _start(client, message):
update_channel = UPDATES_CHANNEL
if update_channel:
if update_channel := UPDATES_CHANNEL:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _start refactored with the following changes:

try:
user = await client.get_chat_member(update_channel, message.chat.id)
if user.status == "kicked":
Expand Down Expand Up @@ -39,7 +38,7 @@ async def _start(client, message):
except Exception:
await client.send_message(message.chat.id,
text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id),
reply_markup=InlineKeyboardMarkup(
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"),
Expand All @@ -55,21 +54,21 @@ async def _start(client, message):
)
return
await client.send_message(message.chat.id,
text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id),
reply_markup=InlineKeyboardMarkup(
text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id),
reply_markup=InlineKeyboardMarkup(
[
[
[
InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"),
InlineKeyboardButton("Support Group", url="https://t.me/UniversalBotsSupport")
],
[
InlineKeyboardButton("🧑‍💻Devloper🧑‍💻", url="https://t.me/JigarVarma2005")
]
InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"),
InlineKeyboardButton("Support Group", url="https://t.me/UniversalBotsSupport")
],
[
InlineKeyboardButton("🧑‍💻Devloper🧑‍💻", url="https://t.me/JigarVarma2005")
]
),
parse_mode="markdown",
reply_to_message_id=message.message_id
)
]
),
parse_mode="markdown",
reply_to_message_id=message.message_id
)


@Client.on_message(filters.incoming & filters.command(['source_code']) & filters.private)
Expand All @@ -96,8 +95,7 @@ async def _source_code(client, message):

@Client.on_message(filters.incoming & filters.command(['help']) & filters.private)
async def _help(client, message):
update_channel = UPDATES_CHANNEL
if update_channel:
if update_channel := UPDATES_CHANNEL:
Comment on lines -99 to +98
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _help refactored with the following changes:

try:
user = await client.get_chat_member(update_channel, message.chat.id)
if user.status == "kicked":
Expand Down Expand Up @@ -149,19 +147,20 @@ async def help_answer(client, callback_query):


def map(pos):
if(pos==1):
button = [
[InlineKeyboardButton(text = '-->', callback_data = "help+2")]
]
elif(pos==len(tr.HELP_MSG)-1):
button = [
[InlineKeyboardButton(text = '<--', callback_data = f"help+{pos-1}")]
if (pos==1):
return [[InlineKeyboardButton(text='-->', callback_data="help+2")]]
elif (pos==len(tr.HELP_MSG)-1):
return [
[InlineKeyboardButton(text='<--', callback_data=f"help+{pos-1}")]
]
else:
button = [
return [
[
InlineKeyboardButton(text = '<--', callback_data = f"help+{pos-1}"),
InlineKeyboardButton(text = '-->', callback_data = f"help+{pos+1}")
InlineKeyboardButton(
text='<--', callback_data=f"help+{pos-1}"
),
InlineKeyboardButton(
text='-->', callback_data=f"help+{pos+1}"
),
],
]
return button
Comment on lines -152 to -167
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function map refactored with the following changes:

2 changes: 1 addition & 1 deletion sql_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def start() -> scoped_session:
except AttributeError as e:
# this is a dirty way for the work-around required for #23
print("DATABASE_URL is not configured. Features depending on the database might have issues.")
print(str(e))
print(e)
3 changes: 1 addition & 2 deletions sql_helpers/forceSubscribe_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def add_channel(chat_id, channel):
SESSION.commit()

def disapprove(chat_id):
rem = SESSION.query(forceSubscribe).get(chat_id)
if rem:
if rem := SESSION.query(forceSubscribe).get(chat_id):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function disapprove refactored with the following changes:

SESSION.delete(rem)
SESSION.commit()