# BromineCore
[ぶろみね](https://github.com/35enidoi/bromine35bot)くんのコア部分の実装、そしてmisskeyのwebsocketAPI単体の実装です。
ローカルのノートを講読したり、通知を取得したり。リバーシも頑張れば実装できます。
何か問題が発生したり追加してほしい機能があったらissueに書いてください
頑張って実装したり解決します
# Example
簡単なタイムライン閲覧クライアントです。
トークン無しでタイムラインをリアルタイムで閲覧できます。
```py
import asyncio
from brcore import Bromine, enum
INSTANCE = "misskey.io"
TL = enum.MisskeyChannelNames.LOCAL_TIMELINE
def note_printer(note: dict) -> None:
"""ノートの情報を受け取って表示する関数"""
NOBASIBOU_LENGTH = 20
user = note["user"]
username = user["name"] if user["name"] is not None else user["username"]
print("-"*NOBASIBOU_LENGTH)
if note.get("renoteId") and note["text"] is None:
# リノートのときはリノート先だけ書く
print(f"{username}がリノート")
note_printer(note["renote"])
# リノートはリアクション数とか書きたくないので
# ここで返す
print("-"*NOBASIBOU_LENGTH)
return
else:
# 普通のノート
print(f"{username}がノート ノートid: {note['id']}")
if note.get("reply"):
# リプライがある場合
print("リプライ:")
note_printer(note["reply"])
if note.get("text"):
print("テキスト:")
print(note["text"])
if note.get("renoteId"):
# 引用
print("引用:")
note_printer(note["renote"])
if len(note["files"]) != 0:
# ファイルがある時
print(f"ファイル数: {len(note['files'])}")
# リアクションとかを書く
print(f"リプライ数: {note['repliesCount']}, リノート数: {note['renoteCount']}, リアクション数: {note['reactionCount']}")
reactions = []
for reactionid, val in note["reactions"].items():
if reactionid[-3:] == "@.:":
# ローカルのカスタム絵文字のidはへんなのついてるので
# それを消す
reactionid = reactionid[:-3] + ":"
reactions.append(f"({reactionid}, {val})")
if len(reactions) != 0:
print("リアクション達: ", ", ".join(reactions))
print("-"*NOBASIBOU_LENGTH)
async def note_async(note: dict) -> None:
"""上のprinterの引数を調整するやつ
asyncにするのはws_connectでは非同期関数が求められるので(見た目非同期っていう体にしているだけ)"""
note_printer(note["body"])
print() # 空白をノート後に入れておく
async def main() -> None:
brm = Bromine(instance=INSTANCE)
brm.ws_connect(TL, note_async)
print("start...")
await brm.main()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("fin")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "brominecore",
"maintainer": "iodine53",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "misskey",
"author": "iodine53",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/fb/37/539177d593fb0f8d209394d270aa61d79d9f7b3f152f36745e47039bdb4d/brominecore-1.0.tar.gz",
"platform": null,
"description": "# BromineCore\n[\u3076\u308d\u307f\u306d](https://github.com/35enidoi/bromine35bot)\u304f\u3093\u306e\u30b3\u30a2\u90e8\u5206\u306e\u5b9f\u88c5\u3001\u305d\u3057\u3066misskey\u306ewebsocketAPI\u5358\u4f53\u306e\u5b9f\u88c5\u3067\u3059\u3002 \n\n\u30ed\u30fc\u30ab\u30eb\u306e\u30ce\u30fc\u30c8\u3092\u8b1b\u8aad\u3057\u305f\u308a\u3001\u901a\u77e5\u3092\u53d6\u5f97\u3057\u305f\u308a\u3002\u30ea\u30d0\u30fc\u30b7\u3082\u9811\u5f35\u308c\u3070\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002 \n\n\u4f55\u304b\u554f\u984c\u304c\u767a\u751f\u3057\u305f\u308a\u8ffd\u52a0\u3057\u3066\u307b\u3057\u3044\u6a5f\u80fd\u304c\u3042\u3063\u305f\u3089issue\u306b\u66f8\u3044\u3066\u304f\u3060\u3055\u3044 \n\u9811\u5f35\u3063\u3066\u5b9f\u88c5\u3057\u305f\u308a\u89e3\u6c7a\u3057\u307e\u3059\n# Example\n\u7c21\u5358\u306a\u30bf\u30a4\u30e0\u30e9\u30a4\u30f3\u95b2\u89a7\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u3059\u3002 \n\u30c8\u30fc\u30af\u30f3\u7121\u3057\u3067\u30bf\u30a4\u30e0\u30e9\u30a4\u30f3\u3092\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u3067\u95b2\u89a7\u3067\u304d\u307e\u3059\u3002\n```py\nimport asyncio\nfrom brcore import Bromine, enum\n\n\nINSTANCE = \"misskey.io\"\nTL = enum.MisskeyChannelNames.LOCAL_TIMELINE\n\n\ndef note_printer(note: dict) -> None:\n \"\"\"\u30ce\u30fc\u30c8\u306e\u60c5\u5831\u3092\u53d7\u3051\u53d6\u3063\u3066\u8868\u793a\u3059\u308b\u95a2\u6570\"\"\"\n NOBASIBOU_LENGTH = 20\n user = note[\"user\"]\n username = user[\"name\"] if user[\"name\"] is not None else user[\"username\"]\n print(\"-\"*NOBASIBOU_LENGTH)\n if note.get(\"renoteId\") and note[\"text\"] is None:\n # \u30ea\u30ce\u30fc\u30c8\u306e\u3068\u304d\u306f\u30ea\u30ce\u30fc\u30c8\u5148\u3060\u3051\u66f8\u304f\n print(f\"{username}\u304c\u30ea\u30ce\u30fc\u30c8\")\n note_printer(note[\"renote\"])\n # \u30ea\u30ce\u30fc\u30c8\u306f\u30ea\u30a2\u30af\u30b7\u30e7\u30f3\u6570\u3068\u304b\u66f8\u304d\u305f\u304f\u306a\u3044\u306e\u3067\n # \u3053\u3053\u3067\u8fd4\u3059\n print(\"-\"*NOBASIBOU_LENGTH)\n return\n else:\n # \u666e\u901a\u306e\u30ce\u30fc\u30c8\n print(f\"{username}\u304c\u30ce\u30fc\u30c8 \u30ce\u30fc\u30c8id: {note['id']}\")\n if note.get(\"reply\"):\n # \u30ea\u30d7\u30e9\u30a4\u304c\u3042\u308b\u5834\u5408\n print(\"\u30ea\u30d7\u30e9\u30a4:\")\n note_printer(note[\"reply\"])\n if note.get(\"text\"):\n print(\"\u30c6\u30ad\u30b9\u30c8:\")\n print(note[\"text\"])\n if note.get(\"renoteId\"):\n # \u5f15\u7528\n print(\"\u5f15\u7528:\")\n note_printer(note[\"renote\"])\n if len(note[\"files\"]) != 0:\n # \u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u6642\n print(f\"\u30d5\u30a1\u30a4\u30eb\u6570: {len(note['files'])}\")\n # \u30ea\u30a2\u30af\u30b7\u30e7\u30f3\u3068\u304b\u3092\u66f8\u304f\n print(f\"\u30ea\u30d7\u30e9\u30a4\u6570: {note['repliesCount']}, \u30ea\u30ce\u30fc\u30c8\u6570: {note['renoteCount']}, \u30ea\u30a2\u30af\u30b7\u30e7\u30f3\u6570: {note['reactionCount']}\")\n reactions = []\n for reactionid, val in note[\"reactions\"].items():\n if reactionid[-3:] == \"@.:\":\n # \u30ed\u30fc\u30ab\u30eb\u306e\u30ab\u30b9\u30bf\u30e0\u7d75\u6587\u5b57\u306eid\u306f\u3078\u3093\u306a\u306e\u3064\u3044\u3066\u308b\u306e\u3067\n # \u305d\u308c\u3092\u6d88\u3059\n reactionid = reactionid[:-3] + \":\"\n reactions.append(f\"({reactionid}, {val})\")\n if len(reactions) != 0:\n print(\"\u30ea\u30a2\u30af\u30b7\u30e7\u30f3\u9054: \", \", \".join(reactions))\n print(\"-\"*NOBASIBOU_LENGTH)\n\n\nasync def note_async(note: dict) -> None:\n \"\"\"\u4e0a\u306eprinter\u306e\u5f15\u6570\u3092\u8abf\u6574\u3059\u308b\u3084\u3064\n\n async\u306b\u3059\u308b\u306e\u306fws_connect\u3067\u306f\u975e\u540c\u671f\u95a2\u6570\u304c\u6c42\u3081\u3089\u308c\u308b\u306e\u3067(\u898b\u305f\u76ee\u975e\u540c\u671f\u3063\u3066\u3044\u3046\u4f53\u306b\u3057\u3066\u3044\u308b\u3060\u3051)\"\"\"\n note_printer(note[\"body\"])\n print() # \u7a7a\u767d\u3092\u30ce\u30fc\u30c8\u5f8c\u306b\u5165\u308c\u3066\u304a\u304f\n\n\nasync def main() -> None:\n brm = Bromine(instance=INSTANCE)\n brm.ws_connect(TL, note_async)\n print(\"start...\")\n await brm.main()\n\n\nif __name__ == \"__main__\":\n try:\n asyncio.run(main())\n except KeyboardInterrupt:\n print(\"fin\")\n\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Misskey websocketAPI wrapper.",
"version": "1.0",
"project_urls": {
"Issues": "https://github.com/35enidoi/BromineCore/issues",
"Repository": "https://github.com/35enidoi/BromineCore"
},
"split_keywords": [
"misskey"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cf7014a42d34f754ce89e9709c44f029e1446cb8e20ee65ff7f99a33bddb9c5c",
"md5": "7cb7955bb451e2f5151e450b3b9f9ede",
"sha256": "f0005190db85518df1f065ddd22ca4a5538907b8fa5b216b4000cb83a08a581b"
},
"downloads": -1,
"filename": "brominecore-1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7cb7955bb451e2f5151e450b3b9f9ede",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10787,
"upload_time": "2024-10-17T17:28:54",
"upload_time_iso_8601": "2024-10-17T17:28:54.721787Z",
"url": "https://files.pythonhosted.org/packages/cf/70/14a42d34f754ce89e9709c44f029e1446cb8e20ee65ff7f99a33bddb9c5c/brominecore-1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fb37539177d593fb0f8d209394d270aa61d79d9f7b3f152f36745e47039bdb4d",
"md5": "747678c47b0835ceba74e6ead029335d",
"sha256": "82c954559ba4e98858e1c823dae3af87585af86f6001ee2f59b6da72ceebdfe3"
},
"downloads": -1,
"filename": "brominecore-1.0.tar.gz",
"has_sig": false,
"md5_digest": "747678c47b0835ceba74e6ead029335d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 10840,
"upload_time": "2024-10-17T17:28:56",
"upload_time_iso_8601": "2024-10-17T17:28:56.236995Z",
"url": "https://files.pythonhosted.org/packages/fb/37/539177d593fb0f8d209394d270aa61d79d9f7b3f152f36745e47039bdb4d/brominecore-1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-17 17:28:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "35enidoi",
"github_project": "BromineCore",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "websockets",
"specs": []
}
],
"lcname": "brominecore"
}