summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-09-26 20:21:33 +0200
committermathieui <mathieui@mathieui.net>2022-04-07 19:36:04 +0200
commit8601dc82c5fe41f68f8e0b5d989b2599d156969d (patch)
tree45ee0ca3990d2db8a8f5aa91fda6c73ad406505a /plugins
parentfb079be08b388a28c8f58f27a86471c02228e9c4 (diff)
downloadpoezio-8601dc82c5fe41f68f8e0b5d989b2599d156969d.tar.gz
poezio-8601dc82c5fe41f68f8e0b5d989b2599d156969d.tar.bz2
poezio-8601dc82c5fe41f68f8e0b5d989b2599d156969d.tar.xz
poezio-8601dc82c5fe41f68f8e0b5d989b2599d156969d.zip
fix: irc plugin, remove login part and fix types
(biboumi handles login and everything)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/irc.py161
1 files changed, 30 insertions, 131 deletions
diff --git a/plugins/irc.py b/plugins/irc.py
index d732c127..4b3512c8 100644
--- a/plugins/irc.py
+++ b/plugins/irc.py
@@ -46,17 +46,6 @@ section name, and the following options:
.. glossary::
:sorted:
-
- login_command
- **Default:** ``[empty]``
-
- The command used to identify with the services (e.g. ``IDENTIFY mypassword``).
-
- login_nick
- **Default:** ``[empty]``
-
- The nickname to whom the auth command will be sent.
-
nickname
**Default:** ``[empty]``
@@ -77,14 +66,6 @@ Commands
.. glossary::
:sorted:
- /irc_login
- **Usage:** ``/irc_login [server1] [server2]…``
-
- Authenticate with the specified servers if they are correctly
- configured. If no servers are provided, the plugin will try
- them all. (You need to set :term:`login_nick` and
- :term:`login_command` as well)
-
/irc_join
**Usage:** ``/irc_join <room or server>``
@@ -131,6 +112,8 @@ Example configuration
import asyncio
+from slixmpp.jid import JID, InvalidJID
+
from poezio.plugin import BasePlugin
from poezio.decorators import command_args_parser
from poezio.core.structs import Completion
@@ -144,19 +127,6 @@ class Plugin(BasePlugin):
asyncio.create_task(
self.initial_connect()
)
-
- self.api.add_command(
- 'irc_login',
- self.command_irc_login,
- usage='[server] [server]…',
- help=('Connect to the specified servers if they '
- 'exist in the configuration and the login '
- 'options are set. If not is given, the '
- 'plugin will try all the sections in the '
- 'configuration.'),
- short='Login to irc servers with nickserv',
- completion=self.completion_irc_login)
-
self.api.add_command(
'irc_join',
self.command_irc_join,
@@ -200,8 +170,21 @@ class Plugin(BasePlugin):
gateway = self.config.get('gateway', 'irc.poez.io')
sections = self.config.sections()
- for section in (s for s in sections if s != 'irc'):
+ sections_jid = []
+ for sect in sections:
+ if sect == 'irc':
+ continue
+ try:
+ sect_jid = JID(sect)
+ if sect_jid != sect_jid.server:
+ self.api.information(f'Invalid server: {sect}', 'Warning')
+ continue
+ except InvalidJID:
+ self.api.information(f'Invalid server: {sect}', 'Warning')
+ continue
+ sections_jid.append(sect_jid)
+ for section in sections_jid:
room_suffix = '%{}@{}'.format(section, gateway)
already_opened = False
@@ -210,101 +193,9 @@ class Plugin(BasePlugin):
already_opened = True
break
- login_command = self.config.get_by_tabname(
- 'login_command', section, default='')
- login_nick = self.config.get_by_tabname(
- 'login_nick', section, default='')
- nick = self.config.get_by_tabname(
- 'nickname', section, default='') or self.core.own_nick
- if login_command and login_nick:
-
- def login(gw, sect, log_nick, log_cmd, room_suff):
- dest = '{}%{}'.format(log_nick, room_suff)
- self.core.xmpp.send_message(
- mto=dest, mbody=log_cmd, mtype='chat')
- delayed = self.api.create_delayed_event(
- 5, self.join, gw, sect)
- self.api.add_timed_event(delayed)
-
- if not already_opened:
- self.core.command.join(room_suffix + '/' + nick)
- delayed = self.api.create_delayed_event(
- 5, login, gateway, section, login_nick, login_command,
- room_suffix[1:])
- self.api.add_timed_event(delayed)
- else:
- login(gateway, section, login_nick, login_command,
- room_suffix[1:])
- elif not already_opened:
+ if not already_opened:
await self.join(gateway, section)
- @command_args_parser.quoted(0, -1)
- def command_irc_login(self, args):
- """
- /irc_login [server] [server]…
- """
- gateway = self.config.get('gateway', 'irc.poez.io')
- if args:
- not_present = []
- sections = self.config.sections()
- for section in args:
- if section not in sections:
- not_present.append(section)
- continue
- login_command = self.config.get_by_tabname(
- 'login_command', section, default='')
- login_nick = self.config.get_by_tabname(
- 'login_nick', section, default='')
- if not login_command and not login_nick:
- not_present.append(section)
- continue
-
- room_suffix = '%{}@{}'.format(section, gateway)
- dest = '{}%{}'.format(login_nick, room_suffix[1:])
- self.core.xmpp.send_message(
- mto=dest, mbody=login_command, mtype='chat')
- if len(not_present) == 1:
- self.api.information(
- 'Section %s does not exist or is not configured' %
- not_present[0], 'Warning')
- elif len(not_present) > 1:
- self.api.information(
- 'Sections %s do not exist or are not configured' %
- ', '.join(not_present), 'Warning')
- else:
- sections = self.config.sections()
-
- for section in (s for s in sections if s != 'irc'):
- login_command = self.config.get_by_tabname(
- 'login_command', section, default='')
- login_nick = self.config.get_by_tabname(
- 'login_nick', section, default='')
- if not login_nick and not login_command:
- continue
-
- room_suffix = '%{}@{}'.format(section, gateway)
- dest = '{}%{}'.format(login_nick, room_suffix[1:])
- self.core.xmpp.send_message(
- mto=dest, mbody=login_command, mtype='chat')
-
- def completion_irc_login(self, the_input):
- """
- completion for /irc_login
- """
- args = the_input.text.split()
- if '' in args:
- args.remove('')
- pos = the_input.get_argument_position()
- sections = self.config.sections()
- if 'irc' in sections:
- sections.remove('irc')
- for section in args:
- try:
- sections.remove(section)
- except:
- pass
- return Completion(the_input.new_completion, sections, pos)
-
@command_args_parser.quoted(1, 1)
async def command_irc_join(self, args):
"""
@@ -315,9 +206,13 @@ class Plugin(BasePlugin):
sections = self.config.sections()
if 'irc' in sections:
sections.remove('irc')
- if args[0] in sections and self.config.get_by_tabname(
- 'rooms', args[0]):
- await self.join_server_rooms(args[0])
+ if args[0] in sections:
+ try:
+ section_jid = JID(args[0])
+ except InvalidJID:
+ return
+ self.config.get_by_tabname('rooms', section_jid)
+ await self.join_server_rooms(section_jid)
else:
await self.join_room(args[0])
@@ -343,7 +238,7 @@ class Plugin(BasePlugin):
else:
self.core.command.message('{}'.format(jid))
- async def join_server_rooms(self, section):
+ async def join_server_rooms(self, section: JID):
"""
Join all the rooms configured for a section
(section = irc server)
@@ -368,9 +263,13 @@ class Plugin(BasePlugin):
if not current_tab_info:
return
server, gateway = current_tab_info
+ try:
+ server_jid = JID(server)
+ except InvalidJID:
+ return
room = '{}%{}@{}'.format(name, server, gateway)
- if self.config.get_by_tabname('nickname', server):
+ if self.config.get_by_tabname('nickname', server_jid):
room += '/' + self.config.get_by_tabname('nickname', server)
await self.core.command.join(room)