slidge.plugins.hackernews#

Hackernews slidge plugin

Will poll replies to items you’ve posted. For every reply, the chat window ‘<REPLY_ITEM_ID>@<BRIDGE_JID>’ should open. It will contain your original post (as a carbon) and its reply as a normal chat message. You can re-reply by replying in your XMPP client directly.

Module Contents#

Classes#

Gateway

Must be subclassed by a plugin to set up various aspects of the XMPP

Session

Represents a gateway user logged in to the legacy network and performing actions.

Functions#

Attributes#

class slidge.plugins.hackernews.Gateway[source]#

Bases: slidge.BaseGateway

Must be subclassed by a plugin to set up various aspects of the XMPP component behaviour, such as its display name or its registration process.

On slidge launch, a singleton is instantiated, and it will be made available to public classes such LegacyContact or BaseSession as the .xmpp attribute. Since it inherits from slixmpp.componentxmpp.ComponentXMPP, this gives you a hand on low-level XMPP interactions via slixmpp plugins, e.g.:

self.send_presence(
    pfrom="somebody@component.example.com",
    pto="someonwelse@anotherexample.com",
)

However, you should not need to do so often since the classes of the plugin API provides higher level abstractions around most commonly needed use-cases, such as sending messages, or displaying a custom status.

REGISTRATION_INSTRUCTIONS = "Enter the hackernews cookie from your browser's dev console (something like your-user-name..."[source]#
REGISTRATION_FIELDS[source]#
ROSTER_GROUP = 'HN'[source]#
COMPONENT_NAME = 'Hackernews (slidge)'[source]#
COMPONENT_TYPE = 'hackernews'[source]#
COMPONENT_AVATAR = 'https://news.ycombinator.com/favicon.ico'[source]#
async validate(user_jid, registration_form)[source]#

Validate a registration form from a user.

Since XEP-0077 is pretty limited in terms of validation, it is OK to validate anything that looks good here and continue the legacy auth process via direct messages to the user (using BaseGateway.input() for instance).

Parameters:
class slidge.plugins.hackernews.Session(user)[source]#

Bases: slidge.BaseSession

Represents a gateway user logged in to the legacy network and performing actions.

Will be instantiated automatically when a user sends an online presence to the gateway component, as per XEP-0100.

Must be subclassed for a functional slidge plugin.

async login()[source]#

Login the gateway user to the legacy network.

Triggered when the gateway start and on user registration. It is recommended that this function returns once the user is logged in, so if you need to await forever (for instance to listen to incoming events), it’s a good idea to wrap your listener in an asyncio.Task.

Returns:

Optionally, a text to use as the gateway status, e.g., “Connected as ‘dude@legacy.network’”

async main_loop()[source]#
async get_user_submissions()[source]#
Return type:

list[int]

async send_own_and_reply(user_submission, reply_id)[source]#
async get_item(item_id)[source]#
async logout()[source]#

Logout the gateway user from the legacy network.

Called on user unregistration and gateway shutdown.

async send_text(chat, text, **k)[source]#

Triggered when the user sends a text message from XMPP to a bridged entity, e.g. to translated_user_name@slidge.example.com, or translated_group_name@slidge.example.com

Override this and implement sending a message to the legacy network in this method.

Parameters:
  • text (str) – Content of the message

  • chat (slidge.LegacyContact) – RecipientType of the message. LegacyContact instance for 1:1 chat, MUC instance for groups.

  • reply_to_msg_id – A legacy message ID if the message references (quotes) another message (XEP-0461)

  • reply_to_fallback_text – Content of the quoted text. Not necessarily set by XMPP clients

  • reply_to – Author of the quoted message. LegacyContact instance for 1:1 chat, LegacyParticipant instance for groups. If None, should be interpreted as a self-reply if reply_to_msg_id is not None.

  • thread

Returns:

An ID of some sort that can be used later to ack and mark the message as read by the user

async send_file(chat, url, *_a, **_k)[source]#

Triggered when the user has sends a file using HTTP Upload (XEP-0363)

Parameters:
Returns:

An ID of some sort that can be used later to ack and mark the message as read by the user

async active(c, thread=None)[source]#

Triggered when the user sends an ‘active’ chat state to the legacy network (XEP-0085)

Parameters:

c (slidge.LegacyContact) – RecipientType of the active chat state

async inactive(c, thread=None)[source]#

Triggered when the user sends an ‘inactive’ chat state to the legacy network (XEP-0085)

Parameters:

c (slidge.LegacyContact) –

async composing(c, thread=None)[source]#

Triggered when the user starts typing in the window of a legacy contact (XEP-0085)

Parameters:

c (slidge.LegacyContact) –

async paused(c, thread=None)[source]#

Triggered when the user pauses typing in the window of a legacy contact (XEP-0085)

Parameters:

c (slidge.LegacyContact) –

async displayed(c, legacy_msg_id, thread=None)[source]#

Triggered when the user reads a message sent by a legacy contact. (XEP-0333)

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a contact to the user in LegacyContact.sent_text() or slidge.LegacyContact.send_file().

Parameters:
async correct(c, text, legacy_msg_id, thread=None)[source]#

Triggered when the user corrected a message using XEP-0308

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a contact to the user in LegacyContact.send_text() or slidge.LegacyContact.send_file().

Parameters:
async search(form_values)[source]#

Triggered when the user uses Jabber Search (XEP-0055) on the component

Form values is a dict in which keys are defined in BaseGateway.SEARCH_FIELDS

Parameters:

form_values (dict[str, str]) – search query, defined for a specific plugin by overriding in BaseGateway.SEARCH_FIELDS

Returns:

slidge.plugins.hackernews.parse_comment_text(text)[source]#
Parameters:

text (str) –

slidge.plugins.hackernews.LOGIN_URL = 'https://news.ycombinator.com/login'[source]#
slidge.plugins.hackernews.REPLY_URL = 'https://news.ycombinator.com/reply'[source]#
slidge.plugins.hackernews.REPLY_POST_URL = 'https://news.ycombinator.com/comment'[source]#
slidge.plugins.hackernews.API_URL = 'https://hacker-news.firebaseio.com/v0'[source]#
slidge.plugins.hackernews.POLL_INTERVAL = 30[source]#
slidge.plugins.hackernews.SLEEP_BEFORE_POST = 30[source]#
slidge.plugins.hackernews.SLEEP_BEFORE_POST2 = 5[source]#
slidge.plugins.hackernews.REPOST_TEXT = '<tr><td>Please confirm that this is your comment by submitting it one'[source]#
slidge.plugins.hackernews.HMAC_RE[source]#
slidge.plugins.hackernews.log[source]#