Skip to content

Commit

Permalink
Translate video conferences to links and send unknown command numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3yx committed May 15, 2022
1 parent 1b0bce0 commit 1d34f87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
39 changes: 28 additions & 11 deletions miniirc_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import miniirc, requests, traceback # type: ignore


ver = (0, 0, 3)
ver = (0, 0, 4)
__version__ = '.'.join(map(str, ver))


Expand Down Expand Up @@ -460,16 +460,7 @@ def disconnect(self) -> None:

def _main(self) -> None:
try:
if miniirc.ver >= (2, 0, 0):
self.handle_msg(miniirc.IRCMessage('001', ('', '', ''), {}, [
self.current_nick,
f'Welcome to Matrix {self.current_nick}'
]))
else:
self._handle('001', ('001', '001', '001'), {}, [
self.current_nick,
f':Welcome to Matrix {self.current_nick}'
])
self.__numeric('001', f'Welcome to Matrix {self.current_nick}')

next_batch: Optional[str] = None
while self.connected:
Expand Down Expand Up @@ -578,6 +569,9 @@ def send(self, cmd: str, *args: str, force: Optional[bool] = None,
self.debug(self.__post(f'join/{_url_quote(args[0])}'))
elif cmd == 'PART' and len(args) == 1:
self.debug(self.__post(f'{self._get_room_url(args[0])}/leave'))
elif self.connected:
self.debug('Unknown command:', cmd)
self.__numeric('421', cmd, 'Unknown command')

def __send_tagmsg(self, channel: str, tags: dict[Any, Any]) -> None:
if tags.get('+draft/react') and tags.get('+draft/reply'):
Expand All @@ -604,6 +598,11 @@ def __irc_msg(self, event: _Event, command: str, args: list[str],
self.handle_msg(miniirc.IRCMessage(
command, (sender, sender, sender), tags, args
))

def __numeric(self, numeric: str, *args: str) -> None:
self.handle_msg(miniirc.IRCMessage(
numeric, ('', '', ''), {}, [self.current_nick, *args]
))
else:
def __irc_msg(self, event: _Event, command: str, args: list[str],
tags: Optional[dict[str, str]] = None, *,
Expand All @@ -618,6 +617,11 @@ def __irc_msg(self, event: _Event, command: str, args: list[str],

self._handle(command, (sender, sender, sender), tags, args)

def __numeric(self, numeric: str, *args: str) -> None:
raw_args = [self.current_nick, *args]
raw_args[-1] = ':' + raw_args[-1]
self._handle(numeric, (numeric, numeric, numeric), {}, raw_args)

@_register_event('m.room.message')
def _message_event(self, room_id: str, event: _Event) -> None:
if ('echo-message' not in self.active_caps and
Expand Down Expand Up @@ -693,6 +697,19 @@ def _reaction_event(self, room_id: str, event: _Event) -> None:
'+draft/reply': relates_to.event_id[str]
})

@_register_event('im.vector.modular.widgets')
def _widget_event(self, room_id: str, event: _Event) -> None:
if event.content.type == 'jitsi':
data = event.content.data
msg = (f'\x01ACTION started a video conference: https://'
f'{data.domain[str]}/{data.conferenceId[str]}\x01')
elif event.unsigned.prev_content.type == 'jitsi':
msg = '\x01ACTION ended a video conference\x01'
else:
return

self.__irc_msg(event, 'PRIVMSG', [room_id, msg], {})

# Helpers
@classmethod
def _login(cls, homeserver: str, username: str, password: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='miniirc_matrix',
version='0.0.3',
version='0.0.4',
py_modules=['miniirc_matrix'],
author='luk3yx',
description='A Matrix wrapper for miniirc.',
Expand Down

0 comments on commit 1d34f87

Please sign in to comment.