Compare commits
3 Commits
f6e85a7a2c
...
e9ef008080
Author | SHA1 | Date | |
---|---|---|---|
e9ef008080
|
|||
aee5cdf6a5
|
|||
eadbdd1eda
|
@@ -9,7 +9,7 @@ class CallbackVerify:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_callback(cls, callback: CallbackQuery):
|
def from_callback(cls, callback: CallbackQuery):
|
||||||
action, user_id = str(callback.data).split(";")
|
action, user_id = str(callback.data).split(":")
|
||||||
if action.lower() != "verify":
|
if action.lower() != "verify":
|
||||||
raise ValueError("Callback provided is not a verification callback")
|
raise ValueError("Callback provided is not a verification callback")
|
||||||
return cls(int(user_id))
|
return cls(int(user_id))
|
||||||
@@ -22,7 +22,7 @@ class CallbackEmoji:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_callback(cls, callback: CallbackQuery):
|
def from_callback(cls, callback: CallbackQuery):
|
||||||
action, user_id, emoji = str(callback.data).split(";")
|
action, user_id, emoji = str(callback.data).split(":")
|
||||||
if action.lower() != "emoji":
|
if action.lower() != "emoji":
|
||||||
raise ValueError("Callback provided is not an emoji button callback")
|
raise ValueError("Callback provided is not an emoji button callback")
|
||||||
return cls(int(user_id), emoji)
|
return cls(int(user_id), emoji)
|
||||||
@@ -34,7 +34,7 @@ class CallbackBan:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_callback(cls, callback: CallbackQuery):
|
def from_callback(cls, callback: CallbackQuery):
|
||||||
action, user_id = str(callback.data).split(";")
|
action, user_id = str(callback.data).split(":")
|
||||||
if action.lower() != "ban":
|
if action.lower() != "ban":
|
||||||
raise ValueError("Callback provided is not a ban callback")
|
raise ValueError("Callback provided is not a ban callback")
|
||||||
return cls(int(user_id))
|
return cls(int(user_id))
|
||||||
@@ -46,7 +46,7 @@ class CallbackLanguage:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_callback(cls, callback: CallbackQuery):
|
def from_callback(cls, callback: CallbackQuery):
|
||||||
action, language = str(callback.data).split(";")
|
action, language = str(callback.data).split(":")
|
||||||
if action.lower() != "language":
|
if action.lower() != "language":
|
||||||
raise ValueError("Callback provided is not a language callback")
|
raise ValueError("Callback provided is not a language callback")
|
||||||
return cls(language)
|
return cls(language)
|
||||||
|
@@ -85,6 +85,10 @@ class PyroUser:
|
|||||||
logger.debug("%s's mistakes count has been set to %s", self.id, mistakes)
|
logger.debug("%s's mistakes count has been set to %s", self.id, mistakes)
|
||||||
await col_users.update_one({"_id": self._id}, {"$set": {"mistakes": mistakes}})
|
await col_users.update_one({"_id": self._id}, {"$set": {"mistakes": mistakes}})
|
||||||
|
|
||||||
|
async def set_selected(self, emojis: List[str] = None) -> None:
|
||||||
|
logger.debug("%s's elected emojis have been set to %s", self.id, emojis)
|
||||||
|
await col_users.update_one({"_id": self._id}, {"$set": {"selected": emojis}})
|
||||||
|
|
||||||
async def update_score(self, points: int = 1) -> None:
|
async def update_score(self, points: int = 1) -> None:
|
||||||
logger.debug("%s point(s) have been added to %s score", points, self.id)
|
logger.debug("%s point(s) have been added to %s score", points, self.id)
|
||||||
await col_users.update_one(
|
await col_users.update_one(
|
||||||
|
@@ -11,7 +11,7 @@ from classes.pyrogroup import PyroGroup
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@PyroClient.on_callback_query(filters.regex(r"ban;[\s\S]*")) # type: ignore
|
@PyroClient.on_callback_query(filters.regex(r"ban:[\s\S]*")) # type: ignore
|
||||||
async def callback_ban(app: PyroClient, callback: CallbackQuery):
|
async def callback_ban(app: PyroClient, callback: CallbackQuery):
|
||||||
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
||||||
locale = group.select_locale(app, callback.message.from_user)
|
locale = group.select_locale(app, callback.message.from_user)
|
||||||
|
@@ -16,7 +16,7 @@ from classes.pyrogroup import PyroGroup
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@PyroClient.on_callback_query(filters.regex(r"emoji;[\s\S]*")) # type: ignore
|
@PyroClient.on_callback_query(filters.regex(r"emoji:[\s\S]*")) # type: ignore
|
||||||
async def callback_emoji_button(app: PyroClient, callback: CallbackQuery):
|
async def callback_emoji_button(app: PyroClient, callback: CallbackQuery):
|
||||||
parsed = CallbackEmoji.from_callback(callback)
|
parsed = CallbackEmoji.from_callback(callback)
|
||||||
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
||||||
@@ -62,7 +62,7 @@ async def callback_emoji_button(app: PyroClient, callback: CallbackQuery):
|
|||||||
await app.restrict_chat_member(
|
await app.restrict_chat_member(
|
||||||
chat_id=group.id,
|
chat_id=group.id,
|
||||||
user_id=callback.from_user.id,
|
user_id=callback.from_user.id,
|
||||||
permissions=ChatPermissions(can_send_messages=True),
|
permissions=callback.message.chat.permissions,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ from modules.utils import get_captcha_image
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@PyroClient.on_callback_query(filters.regex(r"verify;[\s\S]*")) # type: ignore
|
@PyroClient.on_callback_query(filters.regex(r"verify:[\s\S]*")) # type: ignore
|
||||||
async def callback_verify(app: PyroClient, callback: CallbackQuery):
|
async def callback_verify(app: PyroClient, callback: CallbackQuery):
|
||||||
parsed = CallbackVerify.from_callback(callback)
|
parsed = CallbackVerify.from_callback(callback)
|
||||||
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
||||||
@@ -50,7 +50,7 @@ async def callback_verify(app: PyroClient, callback: CallbackQuery):
|
|||||||
await user.set_emojis(captcha.emojis_correct)
|
await user.set_emojis(captcha.emojis_correct)
|
||||||
|
|
||||||
buttons = [
|
buttons = [
|
||||||
InlineButton(emoji, f"emoji;{user.id};{emoji}") for emoji in captcha.emojis_all
|
InlineButton(emoji, f"emoji:{user.id}:{emoji}") for emoji in captcha.emojis_all
|
||||||
]
|
]
|
||||||
|
|
||||||
keyboard = InlineKeyboard(3)
|
keyboard = InlineKeyboard(3)
|
||||||
|
@@ -69,6 +69,9 @@ async def handler_user_join(app: PyroClient, message: Message):
|
|||||||
await user.set_score(0)
|
await user.set_score(0)
|
||||||
await user.set_mistakes(0)
|
await user.set_mistakes(0)
|
||||||
|
|
||||||
|
if len(user.selected) > 0:
|
||||||
|
await user.set_selected([])
|
||||||
|
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
verification_request = await app.send_message(
|
verification_request = await app.send_message(
|
||||||
chat_id=group.id,
|
chat_id=group.id,
|
||||||
@@ -80,13 +83,13 @@ async def handler_user_join(app: PyroClient, message: Message):
|
|||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
app._("verify", "buttons", locale=locale),
|
app._("verify", "buttons", locale=locale),
|
||||||
callback_data=f"verify;{user.id}",
|
callback_data=f"verify:{user.id}",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
app._("ban", "buttons", locale=locale),
|
app._("ban", "buttons", locale=locale),
|
||||||
callback_data=f"ban;{user.id}",
|
callback_data=f"ban:{user.id}",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@@ -35,12 +35,12 @@ async def command_language(app: PyroClient, message: Message):
|
|||||||
for language, data in app.in_every_locale("metadata").items():
|
for language, data in app.in_every_locale("metadata").items():
|
||||||
if data["selectable"]:
|
if data["selectable"]:
|
||||||
buttons.append(
|
buttons.append(
|
||||||
InlineButton(f"{data['flag']} {data['name']}", f"language;{language}")
|
InlineButton(f"{data['flag']} {data['name']}", f"language:{language}")
|
||||||
)
|
)
|
||||||
|
|
||||||
buttons.append(
|
buttons.append(
|
||||||
InlineButton(
|
InlineButton(
|
||||||
f"🤖 {app._('locale_default', 'buttons', locale=locale)}", "language;default"
|
f"🤖 {app._('locale_default', 'buttons', locale=locale)}", "language:default"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ async def command_language(app: PyroClient, message: Message):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@Client.on_callback_query(filters.regex(r"language;[\s\S]*")) # type: ignore
|
@Client.on_callback_query(filters.regex(r"language:[\s\S]*")) # type: ignore
|
||||||
async def callback_language(app: PyroClient, callback: CallbackQuery):
|
async def callback_language(app: PyroClient, callback: CallbackQuery):
|
||||||
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
group = await PyroGroup.create_if_not_exists(callback.message.chat.id, None, True)
|
||||||
locale = group.select_locale(app, callback.message.from_user)
|
locale = group.select_locale(app, callback.message.from_user)
|
||||||
|
Reference in New Issue
Block a user