Add cookie and human support

This commit is contained in:
Joscha 2019-06-21 18:05:27 +00:00
parent 33a4afa73e
commit 17d7cabba6
3 changed files with 38 additions and 3 deletions

View file

@ -2,6 +2,8 @@
## Next version ## Next version
- Add ability to connect as human
- Add cookie support
- Add nick list - Add nick list
- Clean up code - Clean up code
- Fix crash on "Choose a room" screen - Fix crash on "Choose a room" screen

View file

@ -9,6 +9,16 @@ class EuphConfig(TransparentConfig):
def __init__(self, parent: Optional[TransparentConfig] = None) -> None: def __init__(self, parent: Optional[TransparentConfig] = None) -> None:
super().__init__(parent) super().__init__(parent)
# behavior
@property
def cookie_file(self) -> Optional[str]:
return self["behavior.cookie_file"]
@property
def human(self) -> bool:
return self["behavior.human"]
# basic styles # basic styles
@property @property
@ -204,12 +214,18 @@ class EuphLoader(TreeLoader):
SINGLE_CHAR = (lambda x: len(x) == 1, "must be single character") SINGLE_CHAR = (lambda x: len(x) == 1, "must be single character")
AT_LEAST_0 = (lambda x: x >= 0, "must be at least 0") AT_LEAST_0 = (lambda x: x >= 0, "must be at least 0")
AT_LEAST_1 = (lambda x: x >= 1, "must be at least 1") AT_LEAST_1 = (lambda x: x >= 1, "must be at least 1")
OPTIONAL_STR = (lambda x: x is None or type(x) is str,
"must be a string or empty")
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
self._styles: Set[str] = set() self._styles: Set[str] = set()
# behavior
self.add("behavior.cookie_file", Kind.RAW, None, self.OPTIONAL_STR)
self.add("behavior.human", Kind.BOOL, True)
# basic styles # basic styles
self.add_style("visual.room_style", "room") self.add_style("visual.room_style", "room")
self.add_style("visual.nick_style", "nick") self.add_style("visual.nick_style", "nick")

View file

@ -1,4 +1,5 @@
import asyncio import asyncio
import pathlib
from enum import Enum from enum import Enum
from typing import Any, Awaitable, Callable, List, Optional, Tuple, TypeVar from typing import Any, Awaitable, Callable, List, Optional, Tuple, TypeVar
@ -186,7 +187,19 @@ class RoomWidget(urwid.WidgetWrap):
self._requesting_logs = False self._requesting_logs = False
self._hit_top_of_supply = False self._hit_top_of_supply = False
self._room = yaboli.Room(roomname) url_format = yaboli.Room.URL_FORMAT
if self.c.human:
url_format += "?h=1"
cookie_file = self.c.cookie_file
if cookie_file is not None:
cookie_file = str(pathlib.Path(cookie_file).expanduser())
self._room = yaboli.Room(
roomname,
url_format=url_format,
cookie_file=cookie_file,
)
self._room.register_event("connected", self.on_connected) self._room.register_event("connected", self.on_connected)
self._room.register_event("snapshot", self.on_snapshot) self._room.register_event("snapshot", self.on_snapshot)
@ -506,6 +519,7 @@ class RoomWidget(urwid.WidgetWrap):
for message in messages: for message in messages:
self.receive_message(message) self.receive_message(message)
self.change_own_nick()
self.update_nick_list() self.update_nick_list()
async def on_send(self, message: yaboli.LiveMessage) -> None: async def on_send(self, message: yaboli.LiveMessage) -> None:
@ -549,8 +563,11 @@ class RoomWidget(urwid.WidgetWrap):
@synchronous @synchronous
async def nick(self, nick: str) -> None: async def nick(self, nick: str) -> None:
await self._room.nick(nick) try:
self.change_own_nick() await self._room.nick(nick)
self.change_own_nick()
except yaboli.EuphException:
pass
@synchronous @synchronous
async def send(self, content: str, parent_id: Optional[str]) -> None: async def send(self, content: str, parent_id: Optional[str]) -> None: