comparison sat_frontends/jp/cmd_pubsub.py @ 3835:f599e0e36444

cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items: rel 369
author Goffi <goffi@goffi.org>
date Sun, 10 Jul 2022 16:15:09 +0200
parents b7cef1b24f83
children 915fb230cb28
comparison
equal deleted inserted replaced
3834:3260401fdb98 3835:f599e0e36444
1605 except Exception as e: 1605 except Exception as e:
1606 self.disp(f"can't get node affiliations: {e}", error=True) 1606 self.disp(f"can't get node affiliations: {e}", error=True)
1607 self.host.quit(C.EXIT_BRIDGE_ERRBACK) 1607 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1608 else: 1608 else:
1609 await self.output(affiliations) 1609 await self.output(affiliations)
1610 self.host.quit()
1611
1612
1613 class Reference(base.CommandBase):
1614 def __init__(self, host):
1615 super().__init__(
1616 host,
1617 "reference",
1618 use_pubsub=True,
1619 pubsub_flags={C.NODE, C.SINGLE_ITEM},
1620 help=_("send a reference/mention to pubsub item"),
1621 )
1622
1623 def add_parser_options(self):
1624 self.parser.add_argument(
1625 "-t",
1626 "--type",
1627 default="mention",
1628 choices=("data", "mention"),
1629 help=_("type of reference to send (DEFAULT: mention)"),
1630 )
1631 self.parser.add_argument(
1632 "recipient",
1633 help=_("recipient of the reference")
1634 )
1635
1636 async def start(self):
1637 service = self.args.service or await self.host.get_profile_jid()
1638 if self.args.item:
1639 anchor = uri.buildXMPPUri(
1640 "pubsub", path=service, node=self.args.node, item=self.args.item
1641 )
1642 else:
1643 anchor = uri.buildXMPPUri("pubsub", path=service, node=self.args.node)
1644
1645 try:
1646 await self.host.bridge.referenceSend(
1647 self.args.recipient,
1648 anchor,
1649 self.args.type,
1650 "",
1651 self.profile,
1652 )
1653 except Exception as e:
1654 self.disp(f"can't send reference: {e}", error=True)
1655 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
1656 else:
1610 self.host.quit() 1657 self.host.quit()
1611 1658
1612 1659
1613 class Search(base.CommandBase): 1660 class Search(base.CommandBase):
1614 """This command do a search without using MAM 1661 """This command do a search without using MAM
2528 Rename, 2575 Rename,
2529 Subscribe, 2576 Subscribe,
2530 Unsubscribe, 2577 Unsubscribe,
2531 Subscriptions, 2578 Subscriptions,
2532 Affiliations, 2579 Affiliations,
2580 Reference,
2533 Search, 2581 Search,
2534 Transform, 2582 Transform,
2535 Hook, 2583 Hook,
2536 Uri, 2584 Uri,
2537 Node, 2585 Node,