Skip to content

Commit

Permalink
Merge pull request #42 from mariopaolo/master
Browse files Browse the repository at this point in the history
add text styling support
  • Loading branch information
filipre authored Jan 13, 2024
2 parents 71e09a1 + 00ba600 commit 0b6b416
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
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

0 comments on commit 0b6b416

Please sign in to comment.