async def on_startup(bot: Bot) -> None:
await print('it's working!')
def main() -> None:
dp = Dispatcher()
dp.include_router(router)
dp.startup.register(on_startup)
bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
app = web.Application()
webhook_requests_handler = SimpleRequestHandler(
dispatcher=dp,
bot=bot,
secret_token=WEBHOOK_SECRET,
)
webhook_requests_handler.register(app, path=WEBHOOK_PATH)
setup_application(app, dp, bot=bot)
web.run_app(app, host=WEB_SERVER_HOST, port=WEB_SERVER_PORT)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
main()
client = texttospeech.TextToSpeechClient()
credentials = service_account.Credentials.from_service_account_file('C:\Programmirovanie\IDE\Microsoft VS Code\exctazy_bot\skript_anonimka\goggletexttospeech-96f1ecee0681.json')
client = texttospeech.TextToSpeechClient(credentials=credentials)
1. Как можно переслать пост из канала всем участникам, а не только определённым по ID через бота в ЛС?
| id | user_id | message |
| -- | ------- | ---------------------------------------- |
| 1 | 12345 | Привет, наша утренняя рассылка новостей |
| 2 | 67890 | Привет, от тебя давно не было активности |
2. Как можно отправить случайный пост из канала участнику при взаимодействии с кнопкой через бота в ЛС?
from aiogram import types, Dispatcher
from createbot import dp, shieldbot
import keyboards
from random import choice
posts = [<id постов>]
chat_id = <id канала>
@dp.message_handler(commands=['random_post', 'lucky'])
async def random_channel_post(message: types.Message):
await shieldbot.forward_message(chat_id=message.from_user.id, from_chat_id=chat_id, message_id=choice(posts))
class Action(str, Enum):
ban = "ban"
kick = "kick"
warn = "warn"
class AdminAction(CallbackData, prefix="adm"):
action: Action
chat_id: int
user_id: int
...
# Inside handler
builder = InlineKeyboardBuilder()
for action in Action:
builder.button(
text=action.value.title(),
callback_data=AdminAction(action=action, chat_id=chat_id, user_id=user_id),
)
await bot.send_message(
chat_id=admins_chat,
text=f"What do you want to do with {html.quote(name)}",
reply_markup=builder.as_markup(),
)
...
@router.callback_query(AdminAction.filter(F.action == Action.ban))
async def ban_user(query: CallbackQuery, callback_data: AdminAction, bot: Bot):
await bot.ban_chat_member(
chat_id=callback_data.chat_id,
user_id=callback_data.user_id,
...
)