Skip to content

Instantly share code, notes, and snippets.

@Rafaeltheraven
Created May 25, 2025 15:06
Show Gist options
  • Select an option

  • Save Rafaeltheraven/cca3bdcdc89c6a74b64378f14e354b5d to your computer and use it in GitHub Desktop.

Select an option

Save Rafaeltheraven/cca3bdcdc89c6a74b64378f14e354b5d to your computer and use it in GitHub Desktop.
Maunium Stickerpicker -> MSC2545 Packs
import os
import json
import requests
def convert_to_msc2545_pack(data):
display_name = data["title"]
id = data["id"]
stickers = {}
shortcode = ""
for s in data["stickers"]:
sticker = {
"body": s["body"],
"url": s["url"],
"usage": ["sticker"],
"info": s["info"]
}
shortcode = ''.join(s["net.maunium.telegram.sticker"]["emoticons"])
i = 1
while (shortcode in stickers):
i = i + 1
shortcode = shortcode + str(i)
stickers[shortcode] = sticker
stickerpack = {
"id": id,
"pack": {
"display_name": display_name,
"avatar_url": stickers[shortcode]["url"],
"usage": ["sticker"]
},
"images": stickers
}
return stickerpack
def send_stickerpack_to_matrix(homeserver_url, access_token, room_id, stickerpack):
event_type = "im.ponies.room_emotes"
state_key = stickerpack["id"]
url = f"{homeserver_url}/_matrix/client/v3/rooms/{room_id}/state/{event_type}/{state_key}"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
request_body = {
"images": stickerpack["images"],
"pack": stickerpack["pack"]
}
response = requests.put(url, headers=headers, json=request_body)
if response.status_code == 200:
print(f"Sent stickerpack '{stickerpack['pack']['display_name']}' (id: {stickerpack['id']}) successfully.")
else:
print(f"Failed to send stickerpack '{stickerpack['pack']['display_name']}' (id: {stickerpack['id']}): {response.status_code} {response.text}")
sys.exit()
def main():
folder_path = "./web/packs" # change to your folder path
MATRIX_HOMESERVER = "<homeserver>" # or your own homeserver
ACCESS_TOKEN = "<token>"
ROOM_ID = "<room_id>"
for filename in os.listdir(folder_path):
if filename.endswith(".json") and not filename == "index.json":
filepath = os.path.join(folder_path, filename)
with open(filepath, "r", encoding="utf-8") as f:
data = json.load(f)
stickerpack = convert_to_msc2545_pack(data)
send_stickerpack_to_matrix(MATRIX_HOMESERVER, ACCESS_TOKEN, ROOM_ID, stickerpack)
if __name__ == "__main__":
main()
@Rafaeltheraven
Copy link
Author

A simple scripts which converts https://github.com/maunium/stickerpicker (supported by element) into matrix-org/matrix-spec-proposals#2545 (supported by fluffychat/nheko). The script assumes that the stickerpicker has already been run successfully and then simply converts the resulting json found in web/packs into valid ponies events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment