Commit a2e63a82 authored by Hermann Krumrey's avatar Hermann Krumrey

Specify the basic structure of the project

parent 41a58ba6
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
class Address:
"""
Class that models an Address.
"""
def __init__(self, address: str):
"""
Initializes the address object
:param address: The actual address to which messages can be sent
"""
self.address = address
def __str__(self) -> str:
"""
:return: The actual address to which messages can be sent
"""
return self.address
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from typing import Callable, List
from bokkichat.message.Message import Message
from bokkichat.connection.Settings import Settings
class Connection:
"""
Class that defines methods a Connection must implement.
A connection is the central class in bokkichat and handles all
communications with the chat services.
"""
def __init__(self, settings: Settings):
"""
Initializes the connection, with credentials provided by a
Settings object.
:param settings: The settings for the connection
"""
self.settings = settings
def send(self, message: Message):
"""
Sends a message. A message may be either a TextMessage
or a MediaMessage.
:param message: The message to send
:return: None
"""
raise NotImplementedError()
def receive(self) -> List[Message]:
"""
Receives all pending messages.
:return: A list of pending Message objects
"""
raise NotImplementedError()
def loop(self, callback: Callable):
"""
Starts a loop that periodically checks for new messages, calling
a provided callback function in the process.
:param callback: The callback function to call for each
received message.
The callback should have the following format:
lambda connection, message: do_stuff()
:return: None
"""
raise NotImplementedError()
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
class Settings:
"""
Class that defines what methods a Settings class must implement.
Settings objects are used to initialize a Connection.
"""
def serialize(self) -> str:
"""
Serializes the settings to a string
:return: The serialized Settings object
"""
raise NotImplementedError()
@classmethod
def deserialize(cls, serialized: str):
"""
Deserializes a string and generates a Settings object from it
:param serialized: The serialized string
:return: The deserialized Settings object
"""
raise NotImplementedError()
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from bokkichat.message.Message import Message
from bokkichat.address.Address import Address
from bokkichat.message.MediaType import MediaType
class MediaMessage(Message):
"""
Class that defines an interface for media messages.
Each media message has a media type, data and caption.
"""
def __init__(
self,
sender: Address,
receiver: Address,
media_type: MediaType,
data: bytes,
caption: str
):
"""
Initializes the TextMessage object
:param sender: The sender of the message
:param receiver: The receiver of the message
:param media_type: The type of the contained media
:param data: The data of the attached media
:param caption: The caption attached to the media
"""
super().__init__(sender, receiver)
self.media_type = media_type
self.data = data
self.caption = caption
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from enum import Enum, auto
class MediaType(Enum):
"""
Enum that specifies the various types of media that can be sent using
MediaMessage objects.
"""
VIDEO = auto()
AUDIO = auto()
IMAGE = auto()
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from bokkichat.address.Address import Address
class Message:
"""
Class that defines common attributes for a Message object.
"""
def __init__(self, sender: Address, receiver: Address):
"""
Initializes a Message object.
:param sender: The sender of the message
:param receiver: The receiver of the message
"""
self.sender = sender
self.receiver = receiver
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from bokkichat.message.Message import Message
from bokkichat.address.Address import Address
class TextMessage(Message):
"""
Class that defines an interface for text messages.
Each text message has a title and a body.
Some chat services don't allow titles for messages, in those cases,
the title will be blank.
"""
def __init__(
self,
sender: Address,
receiver: Address,
body: str,
title: str = ""
):
"""
Initializes the TextMessage object
:param sender: The sender of the message
:param receiver: The receiver of the message
:param body: The message body
:param title: The title of the message. Defaults to an empty string
"""
super().__init__(sender, receiver)
self.body = body
self.title = title
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
"""LICENSE
Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
This file is part of bokkichat.
bokkichat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
bokkichat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
# Planning
Basic Idea:
```python
settings = TelegramSetting(username="username", password="password")
connection = TelegramConnection(settings)
msg = TextMessage(to="address", body="Hello World")
connection.send(msg)
```
Support looping:
```python
connection.loop(lambda conn, msg: do_stuff(conn, msg))
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment