mirror of
https://github.com/luk3yx/miniirc_matrix.git
synced 2026-05-17 05:25:44 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f00a14e316 | ||
|
|
1baa8ef02f | ||
|
|
1a0d644b60 | ||
|
|
c184810355 | ||
|
|
af6a763c14 |
24
.github/workflows/pythonapp.yml
vendored
Normal file
24
.github/workflows/pythonapp.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# From https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python
|
||||
|
||||
name: Test with pytest
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
run-tests:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
python_version: [3.8, 3]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python_version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python_version }}
|
||||
- name: Install dependencies
|
||||
run: python -m pip install miniirc pytest 'requests>=2.22.0,<3'
|
||||
- name: Run pytest
|
||||
run: pytest
|
||||
@@ -8,11 +8,11 @@ from __future__ import annotations
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Optional, TypeVar, overload
|
||||
from urllib.parse import quote as _url_quote, urlparse as _urlparse
|
||||
import functools, html.parser, itertools, json, math, re, threading, time, uuid
|
||||
import functools, html.parser, itertools, json, math, re, time, uuid
|
||||
import miniirc, requests, traceback # type: ignore
|
||||
|
||||
|
||||
ver = (0, 0, 5)
|
||||
ver = (0, 0, 9)
|
||||
__version__ = '.'.join(map(str, ver))
|
||||
|
||||
|
||||
@@ -257,7 +257,9 @@ class _MatrixHTMLParser(html.parser.HTMLParser):
|
||||
if tag in ('mx-reply', 'script'):
|
||||
self.in_reply -= 1
|
||||
return
|
||||
if tag in self.irc_codes:
|
||||
if tag == 'br':
|
||||
return
|
||||
elif tag in self.irc_codes:
|
||||
self.text.append(self.irc_codes[tag])
|
||||
elif tag != 'font':
|
||||
raise _UnknownTagError(tag)
|
||||
@@ -398,7 +400,7 @@ class Matrix(miniirc.IRC):
|
||||
# Non-SSL localhost connections are probably to
|
||||
# https://github.com/matrix-org/pantalaimon which doesn't support
|
||||
# the "v3" URLs yet.
|
||||
matrix_url = f'http://{hostname}'
|
||||
baseurl = f'http://{hostname}'
|
||||
api_version = 'r0'
|
||||
else:
|
||||
api_version = 'v3'
|
||||
@@ -495,6 +497,14 @@ class Matrix(miniirc.IRC):
|
||||
if self.debug_file:
|
||||
self.debug(json.dumps(res, indent=4))
|
||||
if 'error' in res:
|
||||
# TODO: Use self.debug or something
|
||||
print(f'[miniirc_matrix] Error returned when trying to '
|
||||
f'fetch /sync: {res["error"]!r}')
|
||||
|
||||
if self.persist:
|
||||
self.debug('Trying again in 15 seconds...')
|
||||
time.sleep(15)
|
||||
continue
|
||||
break
|
||||
next_batch = res['next_batch']
|
||||
if 'rooms' in res:
|
||||
@@ -520,8 +530,9 @@ class Matrix(miniirc.IRC):
|
||||
@_room_processor('join', 'leave')
|
||||
def __process_join(self, room_id: str, room: dict[str, Any]) -> None:
|
||||
# Joined rooms
|
||||
for raw_event in room['timeline']['events']:
|
||||
self.__fire_event(room_id, _Event(raw_event))
|
||||
if 'timeline' in room:
|
||||
for raw_event in room['timeline']['events']:
|
||||
self.__fire_event(room_id, _Event(raw_event))
|
||||
|
||||
@_room_processor('invite')
|
||||
def __process_invite(self, room_id: str, room: dict[str, Any]) -> None:
|
||||
|
||||
2
setup.py
2
setup.py
@@ -5,7 +5,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='miniirc_matrix',
|
||||
version='0.0.5',
|
||||
version='0.0.9',
|
||||
py_modules=['miniirc_matrix'],
|
||||
author='luk3yx',
|
||||
description='A Matrix wrapper for miniirc.',
|
||||
|
||||
24
test_formatting.py
Normal file
24
test_formatting.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from miniirc_matrix import _Event, _irc_to_html, _matrix_html_to_irc
|
||||
|
||||
|
||||
def test_irc_to_html():
|
||||
assert _irc_to_html('Hello world!') is None
|
||||
assert _irc_to_html('\x02Bold text') == '<strong>Bold text</strong>'
|
||||
assert (_irc_to_html('\x021 \x1d2\x02 3') ==
|
||||
'<strong>1 <em>2</em></strong><em> 3</em>')
|
||||
|
||||
|
||||
def html_to_irc(html):
|
||||
res, html_parsed_ok = _matrix_html_to_irc(_Event({
|
||||
'format': 'org.matrix.custom.html',
|
||||
'formatted_body': html,
|
||||
}))
|
||||
assert html_parsed_ok
|
||||
return res
|
||||
|
||||
|
||||
def test_html_to_irc():
|
||||
assert html_to_irc('Hello <b>world</b>!') == 'Hello \x02world\x02!'
|
||||
assert html_to_irc('Hello\nworld!') == 'Hello\nworld!'
|
||||
assert html_to_irc('Hello<br>world!') == 'Hello\nworld!'
|
||||
assert html_to_irc('Hello<br/>world!') == 'Hello\nworld!'
|
||||
Reference in New Issue
Block a user