Exemplo n.º 1
0
async def set_ghost_avatar(evt: CommandEvent) -> Optional[EventID]:
    try:
        mxc_uri = ContentURI(evt.args[0])
    except (KeyError, IndexError):
        return await evt.reply(
            "**Usage:** `$cmdprefix+sp set-avatar <mxc_uri> [mxid]`")
    if not mxc_uri.startswith("mxc://"):
        return await evt.reply("The URI has to start with mxc://.")
    if len(evt.args) > 1:
        # TODO support parsing mention pills instead of requiring a plaintext mxid
        puppet = await evt.processor.bridge.get_puppet(UserID(evt.args[1]))
        if puppet is None:
            return await evt.reply("The given mxid was not a valid ghost user."
                                   )
        intent = puppet.intent
    elif evt.is_portal:
        intent = evt.portal.main_intent
        if intent == evt.az.intent:
            return await evt.reply(
                "No mxid given and the main intent is not a ghost user.")
    else:
        return await evt.reply("No mxid given and not in a portal.")
    try:
        return await intent.set_avatar_url(mxc_uri)
    except (MatrixRequestError, IntentError):
        evt.log.exception("Failed to set avatar.")
        return await evt.reply(
            "Failed to set avatar (see logs for more details).")
Exemplo n.º 2
0
 async def _update_photo(self, photo_url: str) -> bool:
     if self.is_direct:
         return False
     photo_id = self._get_photo_id(photo_url)
     if self.photo_id != photo_id:
         self.photo_id = photo_id
         if photo_url:
             self._avatar_uri, _, _ = await self._reupload_fb_photo(photo_url, self.main_intent)
         else:
             self._avatar_uri = ContentURI("")
         if self.mxid:
             await self.main_intent.set_room_avatar(self.mxid, self._avatar_uri)
         return True
     return False
Exemplo n.º 3
0
 async def _update_photo(self, source: 'u.User', photo: Picture) -> bool:
     photo_id = p.Portal.get_photo_id(photo)
     if photo_id != self.photo_id or not self.avatar_set:
         self.photo_id = photo_id
         if photo:
             self.photo_mxc = await self.reupload_avatar(source, self.default_mxid_intent,
                                                         photo.uri, self.fbid,
                                                         use_graph=(photo.height or 0) < 500)
         else:
             self.photo_mxc = ContentURI("")
         try:
             await self.default_mxid_intent.set_avatar_url(self.photo_mxc)
             self.avatar_set = True
         except Exception:
             self.log.exception("Failed to set avatar")
             self.avatar_set = False
         return True
     return False
Exemplo n.º 4
0
    async def update_avatar(
            self, source: 'AbstractUser',
            photo: Union[UserProfilePhoto, UserProfilePhotoEmpty]) -> bool:
        if self.disable_updates:
            return False

        if photo is None or isinstance(photo, UserProfilePhotoEmpty):
            photo_id = ""
        elif isinstance(photo, UserProfilePhoto):
            photo_id = str(photo.photo_id)
        else:
            self.log.warning(f"Unknown user profile photo type: {type(photo)}")
            return False
        if not photo_id and not config["bridge.allow_avatar_remove"]:
            return False
        if self.photo_id != photo_id:
            if not photo_id:
                self.photo_id = ""
                try:
                    await self.default_mxid_intent.set_avatar_url(
                        ContentURI(""))
                except MatrixError:
                    self.log.exception("Failed to set avatar")
                    self.photo_id = ""
                return True

            loc = InputPeerPhotoFileLocation(
                peer=await self.get_input_entity(source),
                local_id=photo.photo_big.local_id,
                volume_id=photo.photo_big.volume_id,
                big=True)
            file = await util.transfer_file_to_matrix(source.client,
                                                      self.default_mxid_intent,
                                                      loc)
            if file:
                self.photo_id = photo_id
                try:
                    await self.default_mxid_intent.set_avatar_url(file.mxc)
                except MatrixError:
                    self.log.exception("Failed to set avatar")
                    self.photo_id = ""
                return True
        return False
Exemplo n.º 5
0
async def remove_ghost_avatar(evt: CommandEvent) -> Optional[EventID]:
    if len(evt.args) > 0:
        puppet = await evt.processor.bridge.get_puppet(UserID(evt.args[0]))
        if puppet is None:
            return await evt.reply("The given mxid was not a valid ghost user."
                                   )
        intent = puppet.intent
    elif evt.is_portal:
        intent = evt.portal.main_intent
        if intent == evt.az.intent:
            return await evt.reply(
                "No mxid given and the main intent is not a ghost user.")
    else:
        return await evt.reply("No mxid given and not in a portal.")
    try:
        return await intent.set_avatar_url(ContentURI(""))
    except (MatrixRequestError, IntentError):
        evt.log.exception("Failed to remove avatar.")
        return await evt.reply(
            "Failed to remove avatar (see logs for more details).")
Exemplo n.º 6
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
from typing import Dict

from mautrix.types import (MessageType, MediaMessageEventContent, ImageInfo,
                           ThumbnailInfo, ContentURI)

gif_versions: Dict[str, MediaMessageEventContent] = {
    "crap":
    MediaMessageEventContent(
        msgtype=MessageType.IMAGE,
        body="putkiteippi.gif",
        url=ContentURI("mxc://maunium.net/IkSoSYYrtaYJQeCaABSLqKiD"),
        info=ImageInfo(
            mimetype="image/gif",
            width=364,
            height=153,
            size=2079294,
            thumbnail_url=ContentURI(
                "mxc://maunium.net/iivOnCDjcGqGvnwnNWxSbAvb"),
            thumbnail_info=ThumbnailInfo(
                mimetype="image/png",
                width=364,
                height=153,
                size=51302,
            ),
        ),
    ),