-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from filipre/private-chats
Version 0.8.0 Release
- Loading branch information
Showing
18 changed files
with
524 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
from signalbot import SignalBot | ||
from commands import ( | ||
PingCommand, | ||
FridayCommand, | ||
TypingCommand, | ||
TriggeredCommand, | ||
ReplyCommand, | ||
) | ||
import logging | ||
|
||
logging.getLogger().setLevel(logging.INFO) | ||
logging.getLogger("apscheduler").setLevel(logging.WARNING) | ||
|
||
|
||
def main(): | ||
signal_service = os.environ["SIGNAL_SERVICE"] | ||
phone_number = os.environ["PHONE_NUMBER"] | ||
|
||
config = { | ||
"signal_service": signal_service, | ||
"phone_number": phone_number, | ||
"storage": None, | ||
} | ||
bot = SignalBot(config) | ||
|
||
# enable a chat command for all contacts and all groups | ||
bot.register(PingCommand()) | ||
bot.register(ReplyCommand()) | ||
|
||
# enable a chat command only for groups | ||
bot.register(FridayCommand(), contacts=False, groups=True) | ||
|
||
# enable a chat command for one specific group with the name "My Group" | ||
bot.register(TypingCommand(), groups=["My Group"]) | ||
|
||
# chat command is enabled for all groups and one specific contact | ||
bot.register(TriggeredCommand(), contacts=["+490123456789"], groups=True) | ||
|
||
bot.start() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .ping import PingCommand | ||
from .friday import FridayCommand | ||
from .typing import TypingCommand | ||
from .triggered import TriggeredCommand | ||
from .reply import ReplyCommand | ||
|
||
__all__ = [ | ||
"PingCommand", | ||
"FridayCommand", | ||
"TypingCommand", | ||
"TriggeredCommand", | ||
"ReplyCommand", | ||
] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from signalbot import Command, Context | ||
|
||
|
||
class PingCommand(Command): | ||
def describe(self) -> str: | ||
return "🏓 Ping Command: Listen for a ping" | ||
|
||
async def handle(self, c: Context): | ||
command = c.message.text | ||
|
||
if command == "ping": | ||
await c.send("pong") | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from signalbot import Command, Context | ||
|
||
|
||
class ReplyCommand(Command): | ||
async def handle(self, c: Context): | ||
if "reply" in c.message.text.lower(): | ||
await c.reply( | ||
"i ain't reading all that. i'm happy for u tho or sorry that happened" | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import unittest | ||
from signalbot.utils import ChatTestCase, chat | ||
from commands.ping import PingCommand | ||
|
||
|
||
class PingChatTest(ChatTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.signal_bot.register(PingCommand()) | ||
|
||
@chat("ping") | ||
async def test_ping(self, query, replies, reactions): | ||
self.assertEqual(replies.call_count, 1) | ||
for recipient, message in replies.results(): | ||
self.assertEqual(recipient, ChatTestCase.group_secret) | ||
self.assertEqual(message, "pong") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from signalbot import Command, Context, triggered | ||
|
||
|
||
class TriggeredCommand(Command): | ||
def describe(self) -> str: | ||
return "😤 Decorator example, matches command_1, command_2 and command_3" | ||
|
||
# add case_sensitive=True for case sensitive triggers | ||
@triggered("command_1", "Command_2", "CoMmAnD_3") | ||
async def handle(self, c: Context): | ||
await c.send("I am triggered") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import asyncio | ||
from signalbot import Command, Context | ||
|
||
|
||
class TypingCommand(Command): | ||
def describe(self) -> str: | ||
return None | ||
|
||
async def handle(self, c: Context): | ||
if c.message.text == "typing": | ||
await c.start_typing() | ||
seconds = 5 | ||
await asyncio.sleep(seconds) | ||
await c.stop_typing() | ||
await c.send(f"Typed for {seconds}s") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.