-
Notifications
You must be signed in to change notification settings - Fork 1
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 #64 from OrBin/dev
Merging dev to master: version 2.0.0
- Loading branch information
Showing
32 changed files
with
782 additions
and
113 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 |
---|---|---|
@@ -1,4 +1,33 @@ | ||
Filter Triggers | ||
=============== | ||
|
||
Filter triggers will be documented soon, after a small refactor with them. | ||
.. autoclass:: gramhopper.triggers.filter_triggers.FilterTriggers | ||
:members: | ||
|
||
filter.user | ||
------------------- | ||
.. autoclass:: gramhopper.triggers.filter_triggers._UserFilterBasedTrigger | ||
:members: | ||
|
||
.. automethod:: __init__ | ||
|
||
filter.chat | ||
------------------ | ||
.. autoclass:: gramhopper.triggers.filter_triggers._ChatFilterBasedTrigger | ||
:members: | ||
|
||
.. automethod:: __init__ | ||
|
||
filter.language | ||
----------- | ||
.. autoclass:: gramhopper.triggers.filter_triggers._LanguageFilterBasedTrigger | ||
:members: | ||
|
||
.. automethod:: __init__ | ||
|
||
filter.message_type | ||
----------- | ||
.. autoclass:: gramhopper.triggers.filter_triggers._MessageTypeFilterBasedTrigger | ||
:members: | ||
|
||
.. automethod:: __init__ |
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 |
---|---|---|
@@ -1,19 +0,0 @@ | ||
from pathlib import Path | ||
|
||
|
||
CONFIG_DIR = Path(Path.home(), '.gramhopper/') | ||
TOKEN_FILE_NAME = 'token.txt' | ||
RULES_FILE_NAME = 'rules.yml' | ||
USERS_FILE_NAME = 'users.json' | ||
|
||
|
||
def token_file_path(): | ||
return Path(CONFIG_DIR, TOKEN_FILE_NAME) | ||
|
||
|
||
def rules_file_path(): | ||
return Path(CONFIG_DIR, RULES_FILE_NAME) | ||
|
||
|
||
def users_file_path(): | ||
return Path(CONFIG_DIR, USERS_FILE_NAME) | ||
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,23 @@ | ||
import logging | ||
from .paths import log_file_path | ||
|
||
|
||
def configure_logger(): | ||
root_logger = logging.getLogger() | ||
root_logger.setLevel(logging.INFO) | ||
|
||
file_handler = logging.FileHandler(log_file_path()) | ||
|
||
# Create console handler with a higher log level | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.WARNING) | ||
|
||
# Create formatter and add it to the handlers | ||
formatter = logging.Formatter('%(asctime)s %(module)s.%(funcName)s %(levelname)s - %(message)s', | ||
datefmt='%Y-%m-%d %H:%M:%S') | ||
file_handler.setFormatter(formatter) | ||
console_handler.setFormatter(formatter) | ||
|
||
# Add the handlers to the logger | ||
root_logger.addHandler(file_handler) | ||
root_logger.addHandler(console_handler) |
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,24 @@ | ||
from pathlib import Path | ||
|
||
|
||
CONFIG_DIR = Path(Path.home(), '.gramhopper/') | ||
TOKEN_FILE_NAME = 'token.txt' | ||
DEFAULT_RULES_FILE_NAME = 'rules.yml' | ||
USERS_FILE_NAME = 'users.json' | ||
LOG_FILE_NAME = 'gramhopper.log' | ||
|
||
|
||
def token_file_path(): | ||
return Path(CONFIG_DIR, TOKEN_FILE_NAME) | ||
|
||
|
||
def default_rules_file_path(): | ||
return Path(CONFIG_DIR, DEFAULT_RULES_FILE_NAME) | ||
|
||
|
||
def users_file_path(): | ||
return Path(CONFIG_DIR, USERS_FILE_NAME) | ||
|
||
|
||
def log_file_path(file_name=LOG_FILE_NAME): | ||
return Path(CONFIG_DIR, file_name) |
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,18 @@ | ||
class Representable: | ||
|
||
def __init__(self): | ||
self.__name = None | ||
|
||
@property | ||
def name(self): | ||
return self.__name | ||
|
||
@name.setter | ||
def name(self, value): | ||
self.__name = value | ||
|
||
def __str__(self): | ||
if self.__name: | ||
return self.__name | ||
|
||
return f'inline {self.__class__.__name__}' |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import abc | ||
from telegram import Bot, Update | ||
from telegram.message import Message | ||
from ..representable import Representable | ||
|
||
|
||
class BaseResponse(abc.ABC): | ||
class BaseResponse(abc.ABC, Representable): | ||
|
||
@abc.abstractmethod | ||
def respond(self, bot: Bot, update: Update, response_payload: dict) -> None: | ||
def respond(self, bot: Bot, update: Update, response_payload: dict) -> Message: | ||
pass |
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.