WIP: Add group creation and moderation
This is still a work-in-progress, and requires more testing. Group creation seems to work, however.
This commit is contained in:
parent
7eedd28d28
commit
ce7956d7c3
|
@ -270,6 +270,29 @@ d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"]
|
|||
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
|
||||
uvloop = ["uvloop (>=0.15.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "blurhash-python"
|
||||
version = "1.2.1"
|
||||
description = "BlurHash encoder implementation for Python"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "blurhash-python-1.2.1.tar.gz", hash = "sha256:aff583f4f2e6c388d0ddaa019c7e954549ba41021fed1c7838b574c1b6fb0349"},
|
||||
{file = "blurhash_python-1.2.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d7836629923f65141c945503f22b8ee009d256952c852218bedbf2475d1a2a68"},
|
||||
{file = "blurhash_python-1.2.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:91a4476f0551538255a867576cbd033c486e1487467ce7e2319a2fbcc17a0281"},
|
||||
{file = "blurhash_python-1.2.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b7afa9d0783e764f60b4b873e5dddf13b99ca559a6011ed343ae22964fda4df4"},
|
||||
{file = "blurhash_python-1.2.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c4455a534480cec6555635541901bbb4f867050cb927266132e753a233e2f15b"},
|
||||
{file = "blurhash_python-1.2.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62a98d7c02ed78df15645276a084969791a22149eebf1dfe6295b188a3e248c6"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
cffi = "*"
|
||||
Pillow = "*"
|
||||
six = "*"
|
||||
|
||||
[package.extras]
|
||||
testing = ["pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "brotli"
|
||||
version = "1.1.0"
|
||||
|
@ -1730,6 +1753,17 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments
|
|||
testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
|
||||
testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"]
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
version = "1.16.0"
|
||||
description = "Python 2 and 3 compatibility utilities"
|
||||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||
files = [
|
||||
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
|
||||
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slidge"
|
||||
version = "0.0.0-dev"
|
||||
|
@ -1741,6 +1775,7 @@ develop = false
|
|||
|
||||
[package.dependencies]
|
||||
aiohttp = {version = "^3.8.3", extras = ["speedups"]}
|
||||
blurhash-python = "^1.2.1"
|
||||
ConfigArgParse = "^1.5.3"
|
||||
pickle-secure = "^0.99.9"
|
||||
Pillow = "^10"
|
||||
|
@ -1752,7 +1787,7 @@ slixmpp = "^1.8.4"
|
|||
type = "git"
|
||||
url = "https://git.sr.ht/~nicoco/slidge"
|
||||
reference = "master"
|
||||
resolved_reference = "e7c3d91d44a4e7af9ed173cd33905f7b89ebf6d2"
|
||||
resolved_reference = "902c3ce21be27ecd22db514ee67d4c61de5ab629"
|
||||
|
||||
[[package]]
|
||||
name = "slidge-dev-helpers"
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import re
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from slidge.group import LegacyBookmarks, LegacyMUC, LegacyParticipant, MucType
|
||||
from slidge.util.types import MucAffiliation
|
||||
from slixmpp.exceptions import XMPPError
|
||||
|
||||
from .contact import Contact
|
||||
from .generated import whatsapp
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .contact import Contact
|
||||
from .session import Session
|
||||
|
||||
|
||||
|
@ -55,6 +56,15 @@ class MUC(LegacyMUC[str, str, Participant, str]):
|
|||
if avatar.URL:
|
||||
await self.set_avatar(avatar.URL, avatar.ID)
|
||||
|
||||
async def on_set_affiliation(
|
||||
self,
|
||||
contact: Contact,
|
||||
affiliation: MucAffiliation,
|
||||
reason: Optional[str],
|
||||
nickname: Optional[str],
|
||||
):
|
||||
pass
|
||||
|
||||
def get_message_sender(self, legacy_msg_id: str):
|
||||
sender_legacy_id = self.sent.get(legacy_msg_id)
|
||||
if sender_legacy_id is None:
|
||||
|
|
|
@ -431,6 +431,32 @@ func (s *Session) GetGroups() ([]Group, error) {
|
|||
return groups, nil
|
||||
}
|
||||
|
||||
// CreateGroup attempts to create a new WhatsApp group for the given human-readable name and
|
||||
// participant JIDs given.
|
||||
func (s *Session) CreateGroup(name string, participants []string) (Group, error) {
|
||||
if s.client == nil || s.client.Store.ID == nil {
|
||||
return Group{}, fmt.Errorf("Cannot create group for unauthenticated session")
|
||||
}
|
||||
|
||||
var jids []types.JID
|
||||
for _, p := range participants {
|
||||
jid, err := types.ParseJID(p)
|
||||
if err != nil {
|
||||
return Group{}, fmt.Errorf("Could not parse participant JID: %s", err)
|
||||
}
|
||||
|
||||
jids = append(jids, jid)
|
||||
}
|
||||
|
||||
req := whatsmeow.ReqCreateGroup{Name: name, Participants: jids}
|
||||
info, err := s.client.CreateGroup(req)
|
||||
if err != nil {
|
||||
return Group{}, fmt.Errorf("Could not create group: %s", err)
|
||||
}
|
||||
|
||||
return newGroup(s.client, info), nil
|
||||
}
|
||||
|
||||
// GetAvatar fetches a profile picture for the Contact or Group JID given. If a non-empty `avatarID`
|
||||
// is also given, GetAvatar will return an empty [Avatar] instance with no error if the remote state
|
||||
// for the given ID has not changed.
|
||||
|
|
|
@ -466,6 +466,25 @@ class Session(BaseSession[str, Recipient]):
|
|||
"""
|
||||
self.whatsapp.SetAvatar("", await get_bytes_temp(bytes_) if bytes_ else "")
|
||||
|
||||
async def on_moderate(
|
||||
self,
|
||||
muc: MUC, # type: ignore
|
||||
legacy_msg_id: str,
|
||||
reason: Optional[str],
|
||||
):
|
||||
pass
|
||||
|
||||
async def on_create_group(
|
||||
self, name: str, contacts: list[Contact] # type:ignore
|
||||
):
|
||||
"""
|
||||
Creates a WhatsApp group for the given human-readable name and participant list.
|
||||
"""
|
||||
group = self.whatsapp.CreateGroup(
|
||||
name, go.Slice_string([c.legacy_id for c in contacts])
|
||||
)
|
||||
return await self.bookmarks.legacy_id_to_jid_local_part(group.JID)
|
||||
|
||||
async def search(self, form_values: dict[str, str]):
|
||||
self.send_gateway_message("Searching on WhatsApp has not been implemented yet.")
|
||||
|
||||
|
|
Loading…
Reference in New Issue