Module telereddit.linker
Linker class which handles all telereddit requests.
Classes
class Linker (chat_id: int)
-
Handle a single telereddit request.
Gets instanciated at every telereddit request. (new message, messsage callback, etc.)
Attributes
bot
:Bot
- python-telegram-bot's Bot instance: initialized by
set_bot()
. chat_id
:Int
- Telegram's chat id to which to send the message.
args
:dict
- Args to construct the Telegram message.
Class variables
var bot : telegram.bot.Bot
Static methods
def set_bot(bot: telegram.bot.Bot) ‑> NoneType
-
Set the python-telegram-bot's Bot instance for the Linker object.
This should be set only once, at the package startup.
Note: This needs to be set before starting the bot loop.
Parameters
bot
:Bot
- The bot instance provided by python-telegram-bot
Methods
def get_args(self, override_dict: Union[dict, NoneType] = None) ‑> dict
-
Get the args parameters potentially overriding some of them.
Parameters
override_dict
:dict
-
(Default value = {})
Args to override, with key as argument key and value as override value.
Returns
args
def send_random_post(self, subreddit: str) ‑> NoneType
-
Send a random post to the chat from the given subreddit.
Potentially catch Telereddit exceptions.
Parameters
subreddit
:str
-
Valid subreddit name.
Note: This should be a r/ prefixed subreddit name.
def send_post_from_url(self, post_url: str) ‑> NoneType
-
Try to send the reddit post relative to post_url to the chat.
Potentially catch Telereddit exceptions.
Parameters
post_url
:str
- Reddit share link of the post.
def send_post(self, post_url: str, from_url: bool = False) ‑> NoneType
-
Send the reddit post relative to post_url to the chat.
This is the core functionality of Linker.
Parameters
post_url
:str
- Reddit share link of the post.
from_url
:Boolean
-
(Default value = False)
Indicates whether the post url has been received from the chat or from the random post.
def edit_result(self, message: telegram.message.Message) ‑> NoneType
-
Edit the given message with a new post from that subreddit.
Edit the keyboard markup to give the user the ability to edit or confirm the message.
Parameters
message
:Message
- python-telegram-bot's instance of the Telegram message.
def edit_random_post(self, message: telegram.message.Message, subreddit: str) ‑> NoneType
-
Edit the current Telegram message with another random Reddit post.
Parameters
message
:Message
- python-telegram-bot's instance of the Telegram message.
subreddit
:str
- Subreddit from which to retrieve the random post.
def delete_message(self, message: telegram.message.Message)
-
Delete a bot's message from the chat.
Parameters
message
:Message
- python-telegram-bot's instance of the message object.