Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of bokkichat.
6bokkichat is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11bokkichat is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import json
21from bokkichat.settings.Settings import Settings
24class TelegramBotSettings(Settings):
25 """
26 Class that defines a Settings object for a Telegram bot connection
27 """
29 def __init__(self, api_key: str):
30 """
31 Initializes the Telegram Connection.
32 :param api_key: The API key used for authentication
33 """
34 self.api_key = api_key
36 # noinspection PyMethodMayBeStatic
37 def serialize(self) -> str:
38 """
39 Serializes the settings to a string
40 :return: The serialized Settings object
41 """
42 return json.dumps({
43 "api_key": self.api_key
44 })
46 @classmethod
47 def deserialize(cls, serialized: str) -> "TelegramBotSettings":
48 """
49 Deserializes a string and generates a Settings object from it
50 :param serialized: The serialized string
51 :return: The deserialized Settings object
52 """
53 obj = json.loads(serialized)
54 return cls(obj["api_key"])
56 @classmethod
57 def prompt(cls) -> Settings:
58 """
59 Prompts the user for input to generate a Settings object
60 :return: The generated settings object
61 """
62 api_key = cls.user_input("API Key")
63 return cls(api_key=api_key)