-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
database: add BaseDatabase & DictDatabase
- Loading branch information
Showing
16 changed files
with
303 additions
and
87 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
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,36 @@ | ||
# Pyroboard - Keyboard manager for Pyrogram | ||
# Copyright (C) 2020 Hearot <https://github.com/hearot> | ||
# | ||
# This file is part of Pyroboard. | ||
# | ||
# Pyroboard is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pyroboard 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Pyroboard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass(init=False) | ||
class Button: | ||
button_id: str | ||
element_id: str = "" | ||
name: str | ||
parameters: dict | ||
|
||
def __init__(self, name: str, button_id: str, **kwargs): | ||
self.button_id = button_id | ||
self.name = name | ||
self.parameters = kwargs | ||
self.parameters['name'] = name | ||
|
||
if "element_id" in kwargs: | ||
self.element_id = kwargs['element_id'] |
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,19 @@ | ||
# Pyroboard - Keyboard manager for Pyrogram | ||
# Copyright (C) 2020 Hearot <https://github.com/hearot> | ||
# | ||
# This file is part of Pyroboard. | ||
# | ||
# Pyroboard is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pyroboard 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Pyroboard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from .dict_database import DictDatabase # noqa |
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,30 @@ | ||
# Pyroboard - Keyboard manager for Pyrogram | ||
# Copyright (C) 2020 Hearot <https://github.com/hearot> | ||
# | ||
# This file is part of Pyroboard. | ||
# | ||
# Pyroboard is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pyroboard 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Pyroboard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from typing import Optional | ||
|
||
|
||
class BaseDatabase: | ||
def get(self, callback_query_id: str) -> Optional[str]: | ||
raise NotImplementedError | ||
|
||
def insert(self, callback_query_id: str, data: str) -> bool: | ||
raise NotImplementedError | ||
|
||
def delete(self, callback_query_id: str) -> bool: | ||
raise NotImplementedError |
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,36 @@ | ||
# Pyroboard - Keyboard manager for Pyrogram | ||
# Copyright (C) 2020 Hearot <https://github.com/hearot> | ||
# | ||
# This file is part of Pyroboard. | ||
# | ||
# Pyroboard is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pyroboard 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Pyroboard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from .base_database import BaseDatabase | ||
from typing import Optional | ||
|
||
|
||
class DictDatabase(dict, BaseDatabase): | ||
def get(self, callback_query_id: str) -> Optional[str]: | ||
return dict.get(self, callback_query_id) | ||
|
||
def insert(self, callback_query_id: str, data: str) -> bool: | ||
self.update({callback_query_id: data}) | ||
return True | ||
|
||
def delete(self, callback_query_id: str) -> bool: | ||
try: | ||
self.pop(callback_query_id) | ||
return True | ||
except KeyError: | ||
return False |
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,30 @@ | ||
# Pyroboard - Keyboard manager for Pyrogram | ||
# Copyright (C) 2020 Hearot <https://github.com/hearot> | ||
# | ||
# This file is part of Pyroboard. | ||
# | ||
# Pyroboard is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pyroboard 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 Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Pyroboard. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from .base_handler import BaseHandler | ||
from .button import Button | ||
from pyrogram import InlineKeyboardMarkup | ||
from typing import List | ||
|
||
|
||
class Keyboard(InlineKeyboardMarkup): | ||
def __init__(self, inline_keyboard: List[List[Button]], | ||
handler: BaseHandler, callback_query_id: str): | ||
super().__init__( | ||
handler.process_keyboard(inline_keyboard, | ||
str(callback_query_id))) |
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.