Skip to content

Commit

Permalink
fix: filename
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Oct 26, 2024
1 parent f9305b8 commit f3a2796
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 151 deletions.
151 changes: 69 additions & 82 deletions examples/multisession.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import asyncio
import logging
import os
import signal
import sys
from datetime import timedelta
from neonize.aioze.client import ClientFactory, NewAClient
from neonize.client import ClientFactory, NewClient
from neonize.events import (
ConnectedEv,
MessageEv,
PairStatusEv,
event,
ReceiptEv,
CallOfferEv,
)
Expand All @@ -26,12 +27,12 @@
sys.path.insert(0, os.getcwd())


# def interrupted(*_):
# event.set()
def interrupted(*_):
event.set()


log.setLevel(logging.DEBUG)
# signal.signal(signal.SIGINT, interrupted)
signal.signal(signal.SIGINT, interrupted)


client_factory = ClientFactory("db.sqlite3")
Expand All @@ -48,189 +49,175 @@


@client_factory.event(ConnectedEv)
async def on_connected(_: NewAClient, __: ConnectedEv):
def on_connected(_: NewClient, __: ConnectedEv):
log.info("⚡ Connected")


@client_factory.event(ReceiptEv)
async def on_receipt(_: NewAClient, receipt: ReceiptEv):
def on_receipt(_: NewClient, receipt: ReceiptEv):
log.debug(receipt)


@client_factory.event(CallOfferEv)
async def on_call(_: NewAClient, call: CallOfferEv):
def on_call(_: NewClient, call: CallOfferEv):
log.debug(call)


@client_factory.event(MessageEv)
async def on_message(client: NewAClient, message: MessageEv):
await handler(client, message)
def on_message(client: NewClient, message: MessageEv):
handler(client, message)


async def handler(client: NewAClient, message: MessageEv):
def handler(client: NewClient, message: MessageEv):
text = message.Message.conversation or message.Message.extendedTextMessage.text
chat = message.Info.MessageSource.Chat
match text:
case "ping":
await client.reply_message("pong", message)
client.reply_message("pong", message)
case "_test_link_preview":
await client.send_message(
client.send_message(
chat, "Test https://github.com/krypton-byte/neonize", link_preview=True
)
case "_sticker":
await client.send_sticker(
client.send_sticker(
chat,
"https://mystickermania.com/cdn/stickers/anime/spy-family-anya-smirk-512x512.png",
)
case "_sticker_exif":
await client.send_sticker(
client.send_sticker(
chat,
"https://mystickermania.com/cdn/stickers/anime/spy-family-anya-smirk-512x512.png",
name="@Neonize",
packname="2024",
)
case "_image":
await client.send_image(
client.send_image(
chat,
"https://download.samplelib.com/png/sample-boat-400x300.png",
caption="Test",
quoted=message,
)
case "_video":
await client.send_video(
client.send_video(
chat,
"https://download.samplelib.com/mp4/sample-5s.mp4",
caption="Test",
quoted=message,
)
case "_audio":
await client.send_audio(
client.send_audio(
chat,
"https://download.samplelib.com/mp3/sample-12s.mp3",
quoted=message,
)
case "_ptt":
await client.send_audio(
client.send_audio(
chat,
"https://download.samplelib.com/mp3/sample-12s.mp3",
ptt=True,
quoted=message,
)
case "_doc":
await client.send_document(
client.send_document(
chat,
"https://download.samplelib.com/xls/sample-heavy-1.xls",
caption="Test",
filename="test.xls",
quoted=message,
)
case "debug":
await client.send_message(chat, message.__str__())
client.send_message(chat, message.__str__())
case "viewonce":
await client.send_image(
client.send_image(
chat,
"https://pbs.twimg.com/media/GC3ywBMb0AAAEWO?format=jpg&name=medium",
viewonce=True,
)
case "profile_pict":
await client.send_message(
chat, (await client.get_profile_picture(chat)).__str__()
)
client.send_message(chat, client.get_profile_picture(chat).__str__())
case "status_privacy":
await client.send_message(
chat, (await client.get_status_privacy()).__str__()
)
client.send_message(chat, client.get_status_privacy().__str__())
case "read":
await client.send_message(
client.send_message(
chat,
(
await client.mark_read(
message.Info.ID,
chat=message.Info.MessageSource.Chat,
sender=message.Info.MessageSource.Sender,
receipt=ReceiptType.READ,
)
client.mark_read(
message.Info.ID,
chat=message.Info.MessageSource.Chat,
sender=message.Info.MessageSource.Sender,
receipt=ReceiptType.READ,
).__str__(),
)
case "read_channel":
metadata = await client.get_newsletter_info_with_invite(
metadata = client.get_newsletter_info_with_invite(
"https://whatsapp.com/channel/0029Va4K0PZ5a245NkngBA2M"
)
err = await client.follow_newsletter(metadata.ID)
await client.send_message(chat, "error: " + err.__str__())
resp = await client.newsletter_mark_viewed(
metadata.ID, [MessageServerID(0)]
)
await client.send_message(chat, resp.__str__() + "\n" + metadata.__str__())
err = client.follow_newsletter(metadata.ID)
client.send_message(chat, "error: " + err.__str__())
resp = client.newsletter_mark_viewed(metadata.ID, [MessageServerID(0)])
client.send_message(chat, resp.__str__() + "\n" + metadata.__str__())
case "logout":
await client.logout()
client.logout()
case "send_react_channel":
metadata = await client.get_newsletter_info_with_invite(
metadata = client.get_newsletter_info_with_invite(
"https://whatsapp.com/channel/0029Va4K0PZ5a245NkngBA2M"
)
data_msg = await client.get_newsletter_messages(
data_msg = client.get_newsletter_messages(
metadata.ID, 2, MessageServerID(0)
)
await client.send_message(chat, data_msg.__str__())
client.send_message(chat, data_msg.__str__())
for _ in data_msg:
await client.newsletter_send_reaction(
client.newsletter_send_reaction(
metadata.ID, MessageServerID(0), "🗿", ""
)
case "subscribe_channel_updates":
metadata = await client.get_newsletter_info_with_invite(
metadata = client.get_newsletter_info_with_invite(
"https://whatsapp.com/channel/0029Va4K0PZ5a245NkngBA2M"
)
result = await client.newsletter_subscribe_live_updates(metadata.ID)
await client.send_message(chat, result.__str__())
result = client.newsletter_subscribe_live_updates(metadata.ID)
client.send_message(chat, result.__str__())
case "mute_channel":
metadata = await client.get_newsletter_info_with_invite(
metadata = client.get_newsletter_info_with_invite(
"https://whatsapp.com/channel/0029Va4K0PZ5a245NkngBA2M"
)
await client.send_message(
chat,
(await client.newsletter_toggle_mute(metadata.ID, False)).__str__(),
client.send_message(
chat, client.newsletter_toggle_mute(metadata.ID, False).__str__()
)
case "set_diseapearing":
await client.send_message(
chat,
(
await client.set_default_disappearing_timer(timedelta(days=7))
).__str__(),
client.send_message(
chat, client.set_default_disappearing_timer(timedelta(days=7)).__str__()
)
case "test_contacts":
await client.send_message(
chat, (await client.contact.get_all_contacts()).__str__()
)
client.send_message(chat, client.contact.get_all_contacts().__str__())
case "build_sticker":
await client.send_message(
client.send_message(
chat,
await client.build_sticker_message(
client.build_sticker_message(
"https://mystickermania.com/cdn/stickers/anime/spy-family-anya-smirk-512x512.png",
message,
"2024",
"neonize",
),
)
case "build_video":
await client.send_message(
client.send_message(
chat,
await client.build_video_message(
client.build_video_message(
"https://download.samplelib.com/mp4/sample-5s.mp4", "Test", message
),
)
case "build_image":
await client.send_message(
client.send_message(
chat,
await client.build_image_message(
client.build_image_message(
"https://download.samplelib.com/png/sample-boat-400x300.png",
"Test",
message,
),
)
case "build_document":
await client.send_message(
client.send_message(
chat,
await client.build_document_message(
client.build_document_message(
"https://download.samplelib.com/xls/sample-heavy-1.xls",
"Test",
"title",
Expand All @@ -240,21 +227,21 @@ async def handler(client: NewAClient, message: MessageEv):
)
# ChatSettingsStore
case "put_muted_until":
await client.chat_settings.put_muted_until(chat, timedelta(seconds=5))
client.chat_settings.put_muted_until(chat, timedelta(seconds=5))
case "put_pinned_enable":
await client.chat_settings.put_pinned(chat, True)
client.chat_settings.put_pinned(chat, True)
case "put_pinned_disable":
await client.chat_settings.put_pinned(chat, False)
client.chat_settings.put_pinned(chat, False)
case "put_archived_enable":
await client.chat_settings.put_archived(chat, True)
client.chat_settings.put_archived(chat, True)
case "put_archived_disable":
await client.chat_settings.put_archived(chat, False)
client.chat_settings.put_archived(chat, False)
case "get_chat_settings":
await client.send_message(
chat, (await client.chat_settings.get_chat_settings(chat)).__str__()
client.send_message(
chat, client.chat_settings.get_chat_settings(chat).__str__()
)
case "button":
await client.send_message(
client.send_message(
message.Info.MessageSource.Chat,
Message(
viewOnceMessage=FutureProofMessage(
Expand Down Expand Up @@ -312,12 +299,12 @@ async def handler(client: NewAClient, message: MessageEv):
),
)


@client_factory.event(PairStatusEv)
async def PairStatusMessage(_: NewAClient, message: PairStatusEv):
def PairStatusMessage(_: NewClient, message: PairStatusEv):
log.info(f"logged as {message.ID.User}")


if __name__ == "__main__":
# all created clients will be automatically logged in and receive all events
loop = asyncio.get_event_loop()
loop.run_until_complete(client_factory.run())
client_factory.run()
Loading

0 comments on commit f3a2796

Please sign in to comment.