Skip to content

Commit

Permalink
Add more important settings to Web-UI to manage better and easiest (#53)
Browse files Browse the repository at this point in the history
* Add some settings to Web-UI to manage better and easiest

* Add SUBSCRIPTION_BASE_URL to DB settings
  • Loading branch information
eloravpn authored Nov 30, 2024
1 parent fec0424 commit ef887c5
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/club/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _calculate_score(cls, total_subset: int):
@classmethod
def _is_channel_member(cls, db_user: User):
result = bot.get_chat_member(
chat_id=config.TELEGRAM_CHANNEL,
chat_id=f"@{config.TELEGRAM_CHANNEL}",
user_id=db_user.telegram_chat_id,
)
if result.status in ["administrator", "creator", "member"]:
Expand Down
2 changes: 1 addition & 1 deletion src/club/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def create_new_club_profiles():

def _is_channel_member(db_user: User):
result = bot.get_chat_member(
chat_id=config.TELEGRAM_CHANNEL, user_id=db_user.telegram_chat_id
chat_id=f"@{config.TELEGRAM_CHANNEL}", user_id=db_user.telegram_chat_id
)
if result.status in ["administrator", "creator", "member"]:
logger.info(f"User {db_user.full_name} is channel member")
Expand Down
27 changes: 18 additions & 9 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
print("Failed to get SERVER_IP, using 127.0.0.1 instead")
SERVER_IP = "127.0.0.1"

UVICORN_HOST = config("UVICORN_HOST", default="0.0.0.0")
UVICORN_PORT = config("UVICORN_PORT", cast=int, default=8000)
UVICORN_HOST = get_setting("UVICORN_HOST", default="0.0.0.0")
UVICORN_PORT = get_setting("UVICORN_PORT", cast=int, default=8000)
UVICORN_UDS = config("UVICORN_UDS", default=None)
UVICORN_SSL_CERTFILE = get_setting("UVICORN_SSL_CERTFILE", default=None)
UVICORN_SSL_KEYFILE = get_setting("UVICORN_SSL_KEYFILE", default=None)
Expand All @@ -37,18 +37,27 @@
)
TELEGRAM_ADMIN_ID = get_setting("TELEGRAM_ADMIN_ID", cast=int, default=0)
TELEGRAM_ADMIN_USER_NAME = get_setting("TELEGRAM_ADMIN_USER_NAME", default=None)
BOT_USER_NAME = config("BOT_USER_NAME", default="")
TELEGRAM_CHANNEL = config("TELEGRAM_CHANNEL", default=None)
TELEGRAM_PROXY_URL = config("TELEGRAM_PROXY_URL", default=None)
BOT_USER_NAME = get_setting("BOT_USER_NAME", default="")
TELEGRAM_CHANNEL = get_setting("TELEGRAM_CHANNEL", default=None)
TELEGRAM_PROXY_URL = get_setting("TELEGRAM_PROXY_URL", default=None)

# Bot URLS

TELEGRAM_CHANNEL_URL = get_setting("TELEGRAM_CHANNEL_URL", default="")
IPHONE_HELP_POST_URL = get_setting("IPHONE_HELP_POST_URL", default="")
ANDROID_HELP_POST_URL = get_setting("ANDROID_HELP_POST_URL", default="")
WINDOWS_HELP_POST_URL = get_setting("WINDOWS_HELP_POST_URL", default="")
MAC_HELP_POST_URL = get_setting("MAC_HELP_POST_URL", default="")


MINIMUM_PAYMENT_TO_TRUST_USER = config(
"MINIMUM_PAYMENT_TO_TRUST_USER", cast=int, default=200000
)
TRUST_CARD_NUMBER = config("TRUST_CARD_NUMBER", default="")
TRUST_CARD_OWNER = config("TRUST_CARD_OWNER", default="")

CARD_NUMBER = config("CARD_NUMBER", default="")
CARD_OWNER = config("CARD_OWNER", default="")
CARD_NUMBER = get_setting("CARD_NUMBER", default="")
CARD_OWNER = get_setting("CARD_OWNER", default="")

TEST_ACCOUNT_EMAIL_PREFIX = config("TEST_ACCOUNT_EMAIL_PREFIX", default="test_")
TEST_ACCOUNT_LIMIT_INTERVAL_DAYS = config(
Expand All @@ -60,7 +69,7 @@
)
TEST_ACCOUNT_HOST_ZONE_ID = config("TEST_ACCOUNT_HOST_ZONE_ID", cast=int, default=1)

TEST_SERVICE_ID = config("TEST_SERVICE_ID", cast=int, default=0)
TEST_SERVICE_ID = get_setting("TEST_SERVICE_ID", cast=int, default=0)

JWT_ACCESS_TOKEN_EXPIRE_MINUTES = config(
"JWT_ACCESS_TOKEN_EXPIRE_MINUTES", cast=int, default=1440
Expand All @@ -71,7 +80,7 @@
config("SUDO_USERNAME", default="admin"): config("SUDO_PASSWORD", default="admin")
}

SUBSCRIPTION_BASE_URL = config(
SUBSCRIPTION_BASE_URL = get_setting(
"SUBSCRIPTION_BASE_URL", default="https://localhost:8000/api/sub"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Move some settings to DB
Revision ID: 47010335de98
Revises: a00786a4da47
Create Date: 2024-11-30 22:17:52.510679
"""

from datetime import datetime

from alembic import op
import sqlalchemy as sa

from src import config

# revision identifiers, used by Alembic.
revision = "47010335de98"
down_revision = "a00786a4da47"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
config_settings_table = sa.table(
"config_settings",
sa.Column("key", sa.String(), nullable=False),
sa.Column("value", sa.String(), nullable=True),
sa.Column("value_type", sa.String(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
# Add other columns as needed
)
op.bulk_insert(
config_settings_table,
[
{
"key": "TEST_SERVICE_ID",
"value": config.TEST_SERVICE_ID,
"value_type": "int",
"updated_at": datetime.utcnow(),
},
{
"key": "TELEGRAM_CHANNEL",
"value": config.TELEGRAM_CHANNEL,
"value_type": "str",
"updated_at": datetime.utcnow(),
},
{
"key": "BOT_USER_NAME",
"value": config.BOT_USER_NAME,
"value_type": "str",
"updated_at": datetime.utcnow(),
},
{
"key": "UVICORN_HOST",
"value": config.UVICORN_HOST,
"value_type": "str",
"updated_at": datetime.utcnow(),
},
{
"key": "UVICORN_PORT",
"value": config.UVICORN_PORT,
"value_type": "int",
"updated_at": datetime.utcnow(),
},
],
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_config_settings_key"), table_name="config_settings")
op.create_index("ix_config_settings_key", "config_settings", ["key"], unique=False)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Add SUBSCRIPTION_BASE_URL settings to DB
Revision ID: b1bc7aad133f
Revises: 47010335de98
Create Date: 2024-11-30 22:53:24.042474
"""
from datetime import datetime

from alembic import op
import sqlalchemy as sa

from src import config

# revision identifiers, used by Alembic.
revision = 'b1bc7aad133f'
down_revision = '47010335de98'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
config_settings_table = sa.table(
"config_settings",
sa.Column("key", sa.String(), nullable=False),
sa.Column("value", sa.String(), nullable=True),
sa.Column("value_type", sa.String(), nullable=True),
sa.Column("updated_at", sa.DateTime(), nullable=True),
# Add other columns as needed
)
op.bulk_insert(
config_settings_table,
[
{
"key": "SUBSCRIPTION_BASE_URL",
"value": config.SUBSCRIPTION_BASE_URL,
"value_type": "str",
"updated_at": datetime.utcnow(),
}
],
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_config_settings_key'), table_name='config_settings')
op.create_index('ix_config_settings_key', 'config_settings', ['key'], unique=False)
# ### end Alembic commands ###
15 changes: 5 additions & 10 deletions src/telegram/user/keyboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from telebot import types # noqa

from src import config
from src.accounts.models import Account
from src.commerce.schemas import OrderStatus
from src.telegram import utils
Expand Down Expand Up @@ -50,21 +51,15 @@ def channel_menu():
def help_links():
keyboard = types.InlineKeyboardMarkup()
keyboard.add(
types.InlineKeyboardButton(text="آیفون", url=config.IPHONE_HELP_POST_URL),
types.InlineKeyboardButton(
text="آیفون", url="https://t.me/EloraVPNChannel/210"
),
types.InlineKeyboardButton(
text="اندروید", url="https://t.me/EloraVPNChannel/72"
text="اندروید", url=config.ANDROID_HELP_POST_URL
),
)

keyboard.add(
types.InlineKeyboardButton(
text="ویندوز", url="https://t.me/EloraVPNChannel/90"
),
types.InlineKeyboardButton(
text="مک بوک", url="https://t.me/EloraVPNChannel/93"
),
types.InlineKeyboardButton(text="ویندوز", url=config.WINDOWS_HELP_POST_URL),
types.InlineKeyboardButton(text="مک بوک", url=config.MAC_HELP_POST_URL),
)
return keyboard

Expand Down
4 changes: 2 additions & 2 deletions src/telegram/user/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
همچنین از طریق منوی زیر می توانید به اطلاعات پروفایل و وضعیت سرویس های خریداری شده خود دسترسی داشته باشید.
[📣 کانال تلگرام](https://t.me/EloraVPNChannel/73)
[📣 کانال تلگرام]({telegram_channel_url})
[💬 ارتباط با پشتیبانی](https://t.me/{admin_id})
"""

Expand Down Expand Up @@ -98,7 +98,7 @@
به نام: {card_owner}
<a href="https://t.me/EloraVPNChannel/73">📣 کانال تلگرام</a>
<a href="{telegram_channel_url}">📣 کانال تلگرام</a>
<a href="https://t.me/{admin_id}">💬 ارتباط با پشتیبانی</a>
"""
Expand Down
21 changes: 16 additions & 5 deletions src/telegram/user/user_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def check(message: types.Message):
return True
else:
result = bot.get_chat_member(
config.TELEGRAM_CHANNEL, user_id=message.from_user.id
f"@{config.TELEGRAM_CHANNEL}", user_id=message.from_user.id
)
if result.status not in ["administrator", "creator", "member"]:
bot.send_message(
Expand Down Expand Up @@ -113,7 +113,10 @@ def start_game(message: types.Message):
def send_welcome(message: types.Message):
bot.send_message(
chat_id=message.from_user.id,
text=messages.WELCOME_MESSAGE.format(admin_id=config.TELEGRAM_ADMIN_USER_NAME),
text=messages.WELCOME_MESSAGE.format(
admin_id=config.TELEGRAM_ADMIN_USER_NAME,
telegram_channel_url=config.TELEGRAM_CHANNEL_URL,
),
disable_web_page_preview=True,
reply_markup=BotUserKeyboard.main_menu(),
parse_mode="markdown",
Expand Down Expand Up @@ -163,7 +166,10 @@ def my_profile(message):
def support(message):
bot.reply_to(
message,
text=messages.WELCOME_MESSAGE.format(admin_id=config.TELEGRAM_ADMIN_USER_NAME),
text=messages.WELCOME_MESSAGE.format(
telegram_channel_url=config.TELEGRAM_CHANNEL_URL,
admin_id=config.TELEGRAM_ADMIN_USER_NAME,
),
parse_mode="markdown",
)

Expand Down Expand Up @@ -196,14 +202,16 @@ def payment(message):
total_payment = utils.get_total_payment(user_id=user.id)

text = messages.PAYMENT_MESSAGE.format(
telegram_channel_url=config.TELEGRAM_CHANNEL_URL,
balance=user.balance_readable,
card_number=config.CARD_NUMBER,
card_owner=config.CARD_OWNER,
admin_id=config.TELEGRAM_ADMIN_USER_NAME,
)

if total_payment > config.MINIMUM_PAYMENT_TO_TRUST_USER:
if total_payment > config.MINIMUM_PAYMENT_TO_TRUST_USER > 0:
text = messages.PAYMENT_MESSAGE.format(
telegram_channel_url=config.TELEGRAM_CHANNEL_URL,
balance=user.balance_readable,
card_number=config.TRUST_CARD_NUMBER,
card_owner=config.TRUST_CARD_OWNER,
Expand Down Expand Up @@ -385,7 +393,10 @@ def main_menu(call: types.CallbackQuery):

bot.send_message(
chat_id=call.from_user.id,
text=messages.WELCOME_MESSAGE.format(admin_id=config.TELEGRAM_ADMIN_USER_NAME),
text=messages.WELCOME_MESSAGE.format(
telegram_channel_url=config.TELEGRAM_CHANNEL_URL,
admin_id=config.TELEGRAM_ADMIN_USER_NAME,
),
disable_web_page_preview=True,
reply_markup=BotUserKeyboard.main_menu(),
parse_mode="markdown",
Expand Down

0 comments on commit ef887c5

Please sign in to comment.