Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add text styling support #42

Merged
merged 5 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions example/commands/styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
from signalbot import SignalBot, Command, Context

class StylesCommand(Command):
async def handle(self, c: Context):
if c.message.text == "Styles":
await c.send("**Bold style**", text_mode="styled")
await c.send("*Italic style*", text_mode="styled")
await c.send("~Strikethrough style~", text_mode="styled")
await c.send("||Spoiler style||", text_mode="styled")
await c.send("`Monospaced style`", text_mode="styled")

if __name__ == "__main__":
bot = SignalBot({
"signal_service": os.environ["SIGNAL_SERVICE"],
"phone_number": os.environ["PHONE_NUMBER"],
})
bot.register(StylesCommand()) # all contacts and groups
bot.start()
3 changes: 3 additions & 0 deletions signalbot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def send(
quote_message: str = None,
quote_timestamp: str = None,
mentions: list = None,
text_mode: str = None,
) -> aiohttp.ClientResponse:
uri = self._send_rest_uri()
if base64_attachments is None:
Expand All @@ -56,6 +57,8 @@ async def send(
payload["quote_timestamp"] = quote_timestamp
if mentions:
payload["mentions"] = mentions
if text_mode:
payload["text_mode"] = text_mode

try:
async with aiohttp.ClientSession() as session:
Expand Down
2 changes: 2 additions & 0 deletions signalbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ async def send(
quote_message: str = None,
quote_timestamp: str = None,
mentions: list = None,
text_mode: str = None,
listen: bool = False,
) -> int:
receiver = self._resolve_receiver(receiver)
Expand All @@ -193,6 +194,7 @@ async def send(
quote_message=quote_message,
quote_timestamp=quote_timestamp,
mentions=mentions,
text_mode=text_mode,
)
resp_payload = await resp.json()
timestamp = resp_payload["timestamp"]
Expand Down
4 changes: 4 additions & 0 deletions signalbot/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ async def send(
text: str,
base64_attachments: list = None,
mentions: list = None,
text_mode: str = None,
):
return await self.bot.send(
self.message.recipient(),
text,
base64_attachments=base64_attachments,
mentions=mentions,
text_mode=text_mode,
)

async def reply(
self,
text: str,
base64_attachments: list = None,
mentions: list = None,
text_mode: str = None,
):
return await self.bot.send(
self.message.recipient(),
Expand All @@ -35,6 +38,7 @@ async def reply(
quote_message=self.message.text,
quote_timestamp=self.message.timestamp,
mentions=mentions,
text_mode=text_mode,
)

async def react(self, emoji: str):
Expand Down
Loading