~wldhx/telegram-crm

f5b9d120accd7205e2e251df5326f26ea9ec4eb6 — wldhx 1 year, 9 months ago 4ff6be5
rewrite ping() to ping peers in folder
1 files changed, 11 insertions(+), 17 deletions(-)

M telegram_crm/__init__.py
M telegram_crm/__init__.py => telegram_crm/__init__.py +11 -17
@@ 72,19 72,15 @@ async def ping(app):
    client, config = app
    now = datetime.now()

    contacts = set(filter(None, [u.username for u in await client.get_contacts()]))
    ping_folder = await get_folder_by_name(app, config.ping_folder_name)

    i = 0
    async for dialog in client.get_dialogs():
        if (
            dialog.chat.type == ChatType.PRIVATE
            # skip people without a @nickname
            and dialog.chat.username
            and dialog.chat.username in contacts
            and "[ping]" in dialog.chat.last_name
            and now - dialog.top_message.date > config.last_talked
        ):
            greeting = await openai.Completion.acreate(
    async for peer in get_stale_peers_in_folder(app, ping_folder):
        user = await client.invoke(raw.functions.users.GetFullUser(id=peer))
        chat = await Chat._parse_full(client, user)
        last_msg = await anext(client.get_chat_history(chat.id, limit=1))

        if now - last_msg.date > config.last_talked:
            completion = await openai.Completion.acreate(
                model="text-davinci-001",
                prompt="Write a short invitation to casually meet up over the weekend",
                temperature=0.8,


@@ 93,11 89,9 @@ async def ping(app):
                frequency_penalty=0,
                presence_penalty=0,
            )
            greeting = completion["choices"][0]["text"].strip()

            await app.send_message(dialog.chat.username, greeting)
            i += 1
        if i >= config.n:
            break
            await app.send_message(dialog.chat.username, f"🤖 ${greeting}")


async def pin(app):


@@ 143,7 137,7 @@ async def run(app):
        return

    await pin(app)
    # await ping(app)
    await ping(app)


async def _main():