Skip to content

Commit

Permalink
feat: Major changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Apr 29, 2024
1 parent 82dcbf8 commit 9e8b331
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 60 deletions.
6 changes: 6 additions & 0 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ voice=Brian
# If you're stuck just leave it null.
database=

# Test g4f-based providers' working statuses
test-g4f=true

# Ignore messages send before launch
skip-pending=true

#Welcome to PYTGPT-BOT.
#For chatting, text-to-image and text-to-voice conversions.

Expand Down
12 changes: 11 additions & 1 deletion pytgpt_bot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def bot():
"--database",
help="Database engine URL e.g sqlite:////:memory:",
)
@click.option(
"--skip-pending",
is_flag=True,
help="Ignore messages send before bot launched.",
)
@click.option(
"--test-g4f",
is_flag=True,
help="Test g4f-based providers' working statuses.",
)
@click.help_option("-h", "--help")
def run(**kwargs):
"""Start the bot"""
Expand All @@ -91,7 +101,7 @@ def run(**kwargs):

bot.infinity_polling(
timeout=kwargs.get("timeout"),
skip_pending=True,
skip_pending=modded_kwargs.get("skip-pending").lower() == "true",
long_polling_timeout=kwargs.get("timeout"),
)
except Exception as e:
Expand Down
12 changes: 2 additions & 10 deletions pytgpt_bot/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pytgpt_bot.models import Chat
from pytgpt_bot.models import session
from pytgpt_bot.config import admin_id
from pytgpt_bot.utils import get_user_id
from telebot.types import Message, CallbackQuery


Expand All @@ -14,16 +15,8 @@ def __init__(self, message: Message | CallbackQuery = None, user_id: int = None)
message (telebot.types.Message): Message object. Defaults to None.
user_id (int): User id. Defaults to None
"""
assert message or user_id, "Message or User id is required."

if user_id:
id = user_id

elif message.chat.type == "private":
id = message.from_user.id

else:
id = message.chat.id
id = get_user_id(message, user_id)

chat = session.query(Chat).filter_by(id=id).first()
if chat:
Expand All @@ -32,7 +25,6 @@ def __init__(self, message: Message | CallbackQuery = None, user_id: int = None)
else:
self.chat = Chat(id=id)
session.add(self.chat)
session.commit()

@property
def is_admin(self) -> bool:
Expand Down
18 changes: 13 additions & 5 deletions pytgpt_bot/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from telebot.util import extract_command, extract_arguments
from pytgpt_bot.db import User
from pytgpt_bot.config import admin_ids
from pytgpt_bot.utils import get_user_id


class IsActiveFilter(SimpleCustomFilter):
Expand Down Expand Up @@ -45,17 +46,24 @@ def check(self, message: types.Message | types.CallbackQuery):
"""
:meta private:
"""

if message.chat.type == "private":
return True
else:
# channel message
return True
# I can't get this shit working
# like I want to check if the message receoived from a channel, is from the channel's admin.
"""
if isinstance(message, types.CallbackQuery):
return self._bot.get_chat_member(
message.message.chat.id, message.from_user.id
message.message.chat.id, get_user_id(user_id=message.from_user.id)
).status in ["creator", "administrator"]
elif message.chat.type == "private":
return True

return self._bot.get_chat_member(
message.chat.id, message.from_user.id
message.chat.id, get_user_id(user_id=message.from_user.id)
).status in ["creator", "administrator"]
"""


class IsBotTaggedFilter(SimpleCustomFilter):
Expand Down
Loading

0 comments on commit 9e8b331

Please sign in to comment.