Skip to content

Commit

Permalink
Add possibility to get another article by reacting with πŸ‘ or βž•
Browse files Browse the repository at this point in the history
Release v0.2.3
  • Loading branch information
jaywink committed Feb 27, 2022
1 parent 09b79fd commit c43a34c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v0.2.3 (2022-02-27)

* Add possibility to get another article by reacting with πŸ‘ or βž•.

## v0.2.0 (2021-08-08)

* Initial version with the following features
Expand Down
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ maubot: 0.1.2
id: me.jasonrobinson.pocket

# A PEP 440 compliant version string.
version: 0.2.0
version: 0.2.3

# The SPDX license identifier for the plugin. https://spdx.org/licenses/
# Optional, assumes all rights reserved if omitted.
Expand Down
43 changes: 40 additions & 3 deletions pocket/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,45 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:
class PocketPlugin(Plugin):
db: Database

@command.passive(
event_type=EventType.REACTION,
field=lambda e: e.content.relates_to.key,
msgtypes=[],
regex=r"\U00002795|\U0001F44D",
)
async def another(self, event: ReactionEvent, _: Tuple[str]) -> None:
item_event = self.db.get_user_event(event.sender, event.content.relates_to.event_id)
if not item_event:
return

user = self.db.get_user_by_id(event.sender)
if not user or not user.access_token:
await self.client.react(
event.room_id,
event.content.relates_to.event_id,
"❌",
)
return

article = await self.get_random_article(user)
if not article:
await self.client.react(
event.room_id,
event.content.relates_to.event_id,
"🀷",
)
return
event_id = await self.client.send_markdown(
room_id=event.room_id,
markdown=self.format_article_message(article),
)
self.db.store_user_event(event.sender, event_id, article["item_id"])

@staticmethod
def format_article_message(article):
return f"{article['resolved_title']} - {article['resolved_url']} " \
f"(βœ… to archive, [view in Pocket](https://getpocket.com/read/{article['item_id']}), πŸ‘/βž• for another)"

@command.passive(
event_type=EventType.REACTION,
field=lambda e: e.content.relates_to.key,
Expand Down Expand Up @@ -137,9 +176,7 @@ async def handler(self, event: MessageEvent) -> None:
if not article:
await event.respond("Didn't find any saved articles. Is your Pocket empty? Or did we hit an error?")
return
event_id = await event.respond(
f"{article['resolved_title']} - {article['resolved_url']} "
f"(react βœ… to archive, [open in Pocket](https://getpocket.com/read/{article['item_id']}))")
event_id = await event.respond(self.format_article_message(article))
self.db.store_user_event(event.sender, event_id, article["item_id"])

@handler.subcommand(help="Authenticate with Pocket")
Expand Down

0 comments on commit c43a34c

Please sign in to comment.