Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0199.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
47 | 47 |
48 def __init__(self, host): | 48 def __init__(self, host): |
49 log.info(_("XMPP Ping plugin initialization")) | 49 log.info(_("XMPP Ping plugin initialization")) |
50 self.host = host | 50 self.host = host |
51 host.bridge.add_method( | 51 host.bridge.add_method( |
52 "ping", ".plugin", in_sign='ss', out_sign='d', method=self._ping, async_=True) | 52 "ping", ".plugin", in_sign="ss", out_sign="d", method=self._ping, async_=True |
53 ) | |
53 try: | 54 try: |
54 self.text_cmds = self.host.plugins[C.TEXT_CMDS] | 55 self.text_cmds = self.host.plugins[C.TEXT_CMDS] |
55 except KeyError: | 56 except KeyError: |
56 log.info(_("Text commands not available")) | 57 log.info(_("Text commands not available")) |
57 else: | 58 else: |
104 | 105 |
105 if pong[0] == "PONG": | 106 if pong[0] == "PONG": |
106 txt_cmd.feed_back(client, "PONG ({time} s)".format(time=pong[1]), mess_data) | 107 txt_cmd.feed_back(client, "PONG ({time} s)".format(time=pong[1]), mess_data) |
107 else: | 108 else: |
108 txt_cmd.feed_back( | 109 txt_cmd.feed_back( |
109 client, _("ping error ({err_msg}). Response time: {time} s") | 110 client, |
110 .format(err_msg=pong[0], time=pong[1]), mess_data) | 111 _("ping error ({err_msg}). Response time: {time} s").format( |
112 err_msg=pong[0], time=pong[1] | |
113 ), | |
114 mess_data, | |
115 ) | |
111 | 116 |
112 def cmd_ping(self, client, mess_data): | 117 def cmd_ping(self, client, mess_data): |
113 """ping an entity | 118 """ping an entity |
114 | 119 |
115 @command (all): [JID] | 120 @command (all): [JID] |
118 if mess_data["unparsed"].strip(): | 123 if mess_data["unparsed"].strip(): |
119 try: | 124 try: |
120 entity_jid = jid.JID(mess_data["unparsed"].strip()) | 125 entity_jid = jid.JID(mess_data["unparsed"].strip()) |
121 except RuntimeError: | 126 except RuntimeError: |
122 txt_cmd = self.host.plugins[C.TEXT_CMDS] | 127 txt_cmd = self.host.plugins[C.TEXT_CMDS] |
123 txt_cmd.feed_back(client, _('Invalid jid: "{entity_jid}"').format( | 128 txt_cmd.feed_back( |
124 entity_jid=mess_data["unparsed"].strip()), mess_data) | 129 client, |
130 _('Invalid jid: "{entity_jid}"').format( | |
131 entity_jid=mess_data["unparsed"].strip() | |
132 ), | |
133 mess_data, | |
134 ) | |
125 return False | 135 return False |
126 else: | 136 else: |
127 entity_jid = mess_data["to"] | 137 entity_jid = mess_data["to"] |
128 d = self.ping(client, entity_jid) | 138 d = self.ping(client, entity_jid) |
129 d.addCallback(self._cmd_ping_fb, client, mess_data) | 139 d.addCallback(self._cmd_ping_fb, client, mess_data) |
130 | 140 |
131 return False | 141 return False |
132 | 142 |
133 def on_ping_request(self, iq_elt, client): | 143 def on_ping_request(self, iq_elt, client): |
134 log.info(_("XMPP PING received from {from_jid} [{profile}]").format( | 144 log.info( |
135 from_jid=iq_elt["from"], profile=client.profile)) | 145 _("XMPP PING received from {from_jid} [{profile}]").format( |
146 from_jid=iq_elt["from"], profile=client.profile | |
147 ) | |
148 ) | |
136 iq_elt.handled = True | 149 iq_elt.handled = True |
137 iq_result_elt = xmlstream.toResponse(iq_elt, "result") | 150 iq_result_elt = xmlstream.toResponse(iq_elt, "result") |
138 client.send(iq_result_elt) | 151 client.send(iq_result_elt) |
139 | 152 |
140 | 153 |