Esempio n. 1
0
    chat = message.db_chat

    if len(message.command) < 2:
        await message.reply_text(user.get_message('group_speak_no_arguments'))
    else:
        reply_to_message_id = message.reply_to_message.message_id if message.reply_to_message else message.message_id

        await execute(client=client,
                      message=message,
                      origin=AudioOrigin.GROUP,
                      keyboard=False,
                      chat=chat,
                      reply_to_message_id=reply_to_message_id)


@Client.on_callback_query(cfilters.callback_data('create_audio'))
async def on_speak_callback(_, callback):
    user = callback.db_user
    user.set_action('create_audio')

    msg = user.get_message('awaiting_text')
    keyboard = create_input_keyboard(user)

    await callback.answer()

    if callback.message and callback.message.voice:
        try:
            await callback.edit_message_reply_markup(None)
        except RPCError:  # Message not edited...
            pass
Esempio n. 2
0
    slow_mode_button = InlineKeyboardButton(user.get_message(
        'slow_mode_button', status=slow_mode),
                                            callback_data='toggle_slow_mode')

    language_button = InlineKeyboardButton(user.get_message('language_button'),
                                           callback_data='change_language')

    menu_button = InlineKeyboardButton(user.get_message('menu_button'),
                                       callback_data='main_menu')

    return InlineKeyboardMarkup([[always_speak_button, slow_mode_button],
                                 [language_button], [menu_button]])


@Client.on_message(filters.command('settings') & filters.private)
async def on_settings_command(_, message):
    user = message.db_user

    await message.reply_text(create_message(user),
                             reply_markup=create_keyboard(user))


@Client.on_callback_query(cfilters.callback_data('settings'))
async def on_settings_callback(_, callback):
    user = callback.db_user

    await callback.answer()
    await callback.edit_message_text(create_message(user),
                                     reply_markup=create_keyboard(user))
Esempio n. 3
0
    if len(message.command) > 1:
        arg = message.command[1].lower()

        if arg == 'language':
            await language.on_language_command(client, message)
            return
        elif arg == 'settings':
            await settings.on_settings_command(client, message)
            return

    await message.reply_text(create_message(user),
                             reply_markup=create_keyboard(user),
                             disable_web_page_preview=False)


@Client.on_callback_query(cfilters.callback_data('main_menu'))
async def on_start_callback(_, callback):
    user = callback.db_user
    user.reset_action()

    await callback.answer()

    if callback.message.voice:
        try:
            await callback.edit_message_reply_markup(None)
        except RPCError:  # Message already has empty keyboard or is deleted
            pass

        await callback.message.reply_text(create_message(user),
                                          reply_markup=create_keyboard(user),
                                          disable_web_page_preview=False)
Esempio n. 4
0
from pyrogram import Client

from texttospeech.bot import cfilters
from texttospeech.bot.plugin import settings
from texttospeech.db.models import Settings
from texttospeech.util.emojifier import Emoji


@Client.on_callback_query(cfilters.callback_data("toggle_always_speak"))
async def on_always_speak(_, callback):
    user = callback.db_user

    always_speak = Emoji.from_boolean(
        user.toggle_setting(Settings.ALWAYS_SPEAK))
    message = user.get_message('toggle_always_speak', status=always_speak)

    await callback.edit_message_text(
        settings.create_message(user),
        reply_markup=settings.create_keyboard(user))
    await callback.answer(message, show_alert=True)
Esempio n. 5
0
from pyrogram import Client
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton

from texttospeech.bot import cfilters
from texttospeech.db.models import *


def create_keyboard(user) -> InlineKeyboardMarkup:
    menu = user.get_message('menu_button')

    return InlineKeyboardMarkup(
        [[InlineKeyboardButton(menu, callback_data='main_menu')]])


@Client.on_callback_query(cfilters.callback_data("stats"))
async def on_stats(_, callback):
    if not callback.db_user.is_admin:
        await callback.answer(text='N/A', show_alert=True)
        return

    with db_session:
        user = callback.db_user
        users = User.select().count()
        groups = Chat.select().count()
        audios = Audio.select().count()

        users_today = User.select(lambda u: u.creation_date >= (datetime.now(
        ) - timedelta(hours=24))).count()
        groups_today = Chat.select(lambda c: c.creation_date >= (datetime.now(
        ) - timedelta(hours=24))).count()
Esempio n. 6
0
from pyrogram.types import InlineKeyboardButton

from texttospeech.bot import cfilters
from texttospeech.localization import languages


@Client.on_message(filters.command('language') & filters.private)
async def on_language_command(_, message):
    user = message.db_user
    user.reset_action()

    back = InlineKeyboardButton(user.get_message('back_button'), callback_data='main_menu')
    await message.reply_text(user.get_message('language_selection'), reply_markup=languages.create_keyboard(back))


@Client.on_callback_query(cfilters.callback_data('change_language'))
async def on_language_callback(_, callback):
    user = callback.db_user
    back = InlineKeyboardButton(user.get_message('back_button'), callback_data='settings')

    await callback.answer()
    await callback.edit_message_text(user.get_message('language_selection'),
                                     reply_markup=languages.create_keyboard(back))


@Client.on_callback_query(filters.regex('^set_language_'))
async def on_set_language_callback(_, callback):
    callback.db_user.set_language(callback.data[len('set_language_'):])

    try:
        await callback.answer(callback.db_user.get_message('language_set'), show_alert=True)
Esempio n. 7
0
from pyrogram import Client

from texttospeech.bot import cfilters
from texttospeech.bot.plugin import settings
from texttospeech.db.models import Settings
from texttospeech.util.emojifier import Emoji


@Client.on_callback_query(cfilters.callback_data("toggle_slow_mode"))
async def on_slow_mode(_, callback):
    user = callback.db_user

    slow_mode = Emoji.from_boolean(user.toggle_setting(Settings.SLOW_MODE))
    message = user.get_message('toggle_slow_mode', status=slow_mode)

    await callback.edit_message_text(
        settings.create_message(user),
        reply_markup=settings.create_keyboard(user))
    await callback.answer(message, show_alert=True)
Esempio n. 8
0
from pyrogram import Client
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton

from texttospeech.bot import cfilters


def create_keyboard(user) -> InlineKeyboardMarkup:
    menu = user.get_message('menu_button')

    return InlineKeyboardMarkup([[InlineKeyboardButton(menu, callback_data='main_menu')]])


@Client.on_callback_query(cfilters.callback_data("info"))
async def on_about_me(_, callback):
    user = callback.db_user

    await callback.answer()
    await callback.edit_message_text(user.get_message("about_me"), reply_markup=create_keyboard(user),
                                     disable_web_page_preview=True)