Skip to content

Commit 486b7e5

Browse files
committed
reinit with different structure for dynamic importing per-backend
1 parent 7674086 commit 486b7e5

53 files changed

Lines changed: 351 additions & 142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chatom/_.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# from .enums import BACKEND
2+
# from .user import User
3+
4+
5+
# def mention_user(user: User, backend: BACKEND) -> str:
6+
# """Generate a mention string for a user based on the backend platform.
7+
8+
# Args:
9+
# user (User): The user to mention.
10+
# backend (BACKEND): The backend platform.
11+
12+
# Returns:
13+
# str: The formatted mention string.
14+
# """
15+
# match backend:
16+
# case "discord":
17+
# return f"<@!{user.id}>"
18+
# case "email":
19+
# return f"<a href='mailto:{user.email}'>{user.name}</a>" if user.email else user.name
20+
# case "irc":
21+
# return f"{user.handle}" if user.handle else user.name
22+
# case "matrix":
23+
# return f"@{user.handle}:matrix.org" if user.handle else user.name
24+
# # case "mattermost":
25+
# # return f"@{user.handle}" if user.handle else user.name
26+
# # case "messenger":
27+
# # return f"@{user.name}"
28+
# case "slack":
29+
# return f"<@{user.id}>"
30+
# case "symphony":
31+
# return f"@{user.name}"
32+
# # case "teams":
33+
# # return f"<at>{user.name}</at>"
34+
# # case "telegram":
35+
# # return f"@{user.handle}" if user.handle else user.name
36+
# # case "whatsapp":
37+
# # return f"@{user.name}"
38+
# # case "zulip":
39+
# # return f"@**{user.name}**"
40+
# case _:
41+
# # Fallback to full name if no specific format is defined
42+
# return user.name

chatom/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
from .attachment import *
21
from .backend import *
3-
from .channel import *
2+
from .base import *
3+
from .enums import *
44
from .format import *
5-
from .mention import *
6-
from .message import *
7-
from .presence import *
8-
from .user import *
95

106
__version__ = "0.1.0"

chatom/backend.py

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,13 @@
1-
from typing import Literal, Union
1+
from pydantic import BaseModel, Field
22

3-
DISCORD = "discord"
4-
EMAIL = "email"
5-
IRC = "irc"
6-
MATRIX = "matrix"
7-
# MATTERMOST = "mattermost"
8-
# MESSENGER = "messenger"
9-
SLACK = "slack"
10-
SYMPHONY = "symphony"
11-
# TEAMS = "teams"
12-
# TELEGRAM = "telegram"
13-
# WHATSAPP = "whatsapp"
14-
# ZULIP = "zulip"
3+
from .enums import BACKEND
154

16-
BACKEND = Union[
17-
Literal[DISCORD],
18-
Literal[EMAIL],
19-
Literal[IRC],
20-
Literal[MATRIX],
21-
# Literal[MATTERMOST],
22-
# Literal[MESSENGER],
23-
Literal[SLACK],
24-
Literal[SYMPHONY],
25-
# Literal[TEAMS],
26-
# Literal[TELEGRAM],
27-
# Literal[WHATSAPP],
28-
# Literal[ZULIP],
29-
str,
30-
]
31-
ALL_BACKENDS = [
32-
DISCORD,
33-
EMAIL,
34-
IRC,
35-
# MATRIX,
36-
# MATTERMOST,
37-
# MESSENGER,
38-
SLACK,
39-
SYMPHONY,
40-
# TEAMS,
41-
# TELEGRAM,
42-
# WHATSAPP,
43-
# ZULIP,
44-
]
455

46-
__all__ = (
47-
"BACKEND",
48-
"DISCORD",
49-
"EMAIL",
50-
"IRC",
51-
"MATRIX",
52-
# "MATTERMOST",
53-
# "MESSENGER",
54-
"SLACK",
55-
"SYMPHONY",
56-
# "TEAMS",
57-
# "TELEGRAM",
58-
# "WHATSAPP",
59-
# "ZULIP",
60-
)
6+
class BackendConfig(BaseModel): ...
7+
8+
9+
class Backend(BaseModel):
10+
backend: BACKEND
11+
config: BackendConfig = Field(default_factory=BackendConfig)
12+
13+
def connect(self): ...

chatom/base/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .base import *
2+
from .channel import *
3+
from .mention import *
4+
from .message import *
5+
from .presence import *
6+
from .user import *

chatom/base/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pydantic import BaseModel as PydanticBaseModel, Field
2+
3+
__all__ = ("BaseModel", "Field")
4+
5+
6+
class BaseModel(PydanticBaseModel):
7+
# In case customization needed
8+
...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, Field
1+
from .base import BaseModel, Field
22

33
__all__ = ("Channel",)
44

chatom/base/mention.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from singledispatch import singledispatch
2+
3+
from .user import User
4+
5+
__all__ = ("mention_user",)
6+
7+
8+
@singledispatch
9+
def mention_user(user: User) -> str:
10+
"""Generate a mention string for a user based on the backend platform.
11+
12+
Args:
13+
user (User): The user to mention.
14+
15+
Returns:
16+
str: The formatted mention string.
17+
"""
18+
return user.name # Default to using the user's name if no specific implementation exists
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import List
22

3-
from pydantic import BaseModel, Field
4-
3+
from .base import BaseModel, Field
54
from .channel import Channel
65
from .user import User
76

chatom/user.py renamed to chatom/base/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, Field
1+
from .base import BaseModel, Field
22

33
__all__ = ("User",)
44

0 commit comments

Comments
 (0)