diff --git a/.github/workflows/upload.yml b/.github/workflows/upload.yml new file mode 100644 index 0000000..0ddfff4 --- /dev/null +++ b/.github/workflows/upload.yml @@ -0,0 +1,86 @@ +name: Pulblish to PyPI + +on: + release: + types: [prereleased, released] + workflow_dispatch: + inputs: + version: + description: 'version' + required: true + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: "Set env" + run: | + + if [ -n "${{ github.event.inputs.version }}" ]; then + echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV + git tag ${{ github.event.inputs.version }} + else + echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + fi + + - name: echo version + run: | + echo $RELEASE_VERSION + echo ${{ env.RELEASE_VERSION }} + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install Poetry + run: | + python -m pip install --upgrade pip + pip install poetry + - name: Add Poetry Plugin + # poetry plugin add poetry-version-plugin + run: | + pip install poetry-version-plugin + - name: PyPI Settings + run: | + poetry config pypi-token.pypi ${{secrets.PYPI_TOKEN}} + + - name: Build Poetry + run: | + poetry build + poetry publish + - name: Gets latest created release info + id: latest_release_info + uses: jossef/action-latest-release-info@v1.2.1 + env: + GITHUB_TOKEN: ${{ secrets.USER_TOKEN }} + - name: Get Name of Artifact + run: | + ARTIFACT_PATHNAME=$(ls dist/*.whl | head -n 1) + ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME) + echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV + echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV + ARTIFACT2_PATHNAME=$(ls dist/*.tar.gz | head -n 1) + ARTIFACT2_NAME=$(basename $ARTIFACT2_PATHNAME) + echo "ARTIFACT2_PATHNAME=${ARTIFACT2_PATHNAME}" >> $GITHUB_ENV + echo "ARTIFACT2_NAME=${ARTIFACT2_NAME}" >> $GITHUB_ENV + - name: Upload Whl to Release Assets + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.USER_TOKEN }} + with: + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ${{ env.ARTIFACT_PATHNAME }} + asset_name: ${{ env.ARTIFACT_NAME }} + asset_content_type: application/x-wheel+zip + - name: Upload Whl to Release Assets2 + id: upload-release-asset2 + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.USER_TOKEN }} + with: + upload_url: ${{ steps.latest_release_info.outputs.upload_url }} + asset_path: ${{ env.ARTIFACT2_PATHNAME }} + asset_name: ${{ env.ARTIFACT2_NAME }} + asset_content_type: application/x-wheel+zip + \ No newline at end of file diff --git a/misspy/Bot.py b/misspy/Bot.py index 81f0055..1eb898a 100644 --- a/misspy/Bot.py +++ b/misspy/Bot.py @@ -9,6 +9,7 @@ from .endpoints.drive import drive from .endpoints.notes import notes +from .endpoints.reaction import reactions from .settings import Option, extension @@ -35,6 +36,7 @@ def __init__( # ---------- endpoints ------------ self.notes = notes(self.address, self.i, self.ssl, endpoints=self.endpoint_list, handler=self.http) self.drive = drive(self.address, self.i, self.ssl, endpoints=self.endpoint_list, handler=self.http) + self.reactions = reactions(self.address, self.i, self.ssl, endpoints=self.endpoint_list, handler=self.http) # --------------------------------- def __i(self): @@ -57,6 +59,9 @@ async def handler(self, json: dict): if json["type"] == "channel": if json["body"]["type"] == "note": json["body"]["body"]["api"] = {} + json["body"]["body"]["api"]["reactions"] = {} + json["body"]["body"]["api"]["reactions"]["create"] = partial(self.reactions.create, noteId=json["body"]["body"]["id"]) + json["body"]["body"]["api"]["reactions"]["delete"] = partial(self.reactions.delete, noteId=json["body"]["body"]["id"]) json["body"]["body"]["api"]["reply"] = partial(self.notes.create, replyId=json["body"]["body"]["id"]) json["body"]["body"]["api"]["renote"] = partial(self.notes.create, renoteId=json["body"]["body"]["id"]) pnote = Note(**json["body"]["body"]) diff --git a/misspy/core/types/action.py b/misspy/core/types/action.py index 4291f50..e8239cf 100644 --- a/misspy/core/types/action.py +++ b/misspy/core/types/action.py @@ -3,8 +3,13 @@ import pydantic from pydantic import dataclasses +@dataclasses.dataclass(config=dict(extra="allow", arbitrary_types_allowed=True)) +class reactions: # 以下同理由 + create: Any + delete: Any @dataclasses.dataclass(config=dict(extra="allow", arbitrary_types_allowed=True)) class APIAction: # anyは一時的。misspy.notes系を読み込むと循環インポートになって動かないからどうにかして解決したい reply: Any renote: Any + reactions: reactions \ No newline at end of file diff --git a/misspy/endpoints/reaction.py b/misspy/endpoints/reaction.py new file mode 100644 index 0000000..6973f90 --- /dev/null +++ b/misspy/endpoints/reaction.py @@ -0,0 +1,51 @@ +from typing import List, Union +import traceback + +import pydantic +import orjson + +from ..core.exception import NotFound +from ..core.http import AsyncHttpHandler +from ..core.types.note import Note +from ..core.types.poll import Poll +from ..core.types.drive import DriveFile +from ..utils.internaltool import nonecheck + +class reactions: + def __init__( + self, address: str, i: Union[str, None], ssl: bool, endpoints: List[str], handler: AsyncHttpHandler=None + ) -> None: + self.http = handler + if handler is None: + self.http = AsyncHttpHandler(address, i, ssl) + self.endpoints = endpoints + + async def create(self, reaction: str, noteId: str) -> None: + """create reaction. + + Args: + address (string): instance address + i (string): user token + noteId (string): noteId + reaction (string): Specify reaction. Reactions are Unicode emojis or custom emojis. For custom emoji, enclose the emoji name with a colon. + + Returns: + dict: Misskey API response + """ + return await self.http.send( + "notes/reactions/create", {"noteId": noteId, "reaction": reaction} + ) + + + async def delete(self, noteId) -> None: + """delete reaction. + + Args: + address (string): instance address + i (string): user token + noteId (string): noteId + + Returns: + dict: Misskey API response + """ + return await self.http.send("notes/reactions/delete", {"noteId": noteId}) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index c088c84..d019e98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "misspy" -version = "2024.1.0" -description = "Fast, asynchronous misskey API framework" +version = "0.0.0" +description = "Fast, asynchronous Misskey API framework" authors = ["sonyakun "] readme = "README.md" license = "MIT" @@ -10,7 +10,7 @@ homepage = "https://rewrite.misspy.xyz/" repository = "https://go.misspy.xyz/rewrite" documentation = "https://rewrite.misspy.xyz/docs/" -keywords = ["misskey", "misskey-api"] +keywords = ["misskey", "misskey-api", "misskey-bot"] classifiers = [ "Topic :: Software Development :: Build Tools", @@ -21,6 +21,9 @@ packages = [ { include = "misspy" } ] +[tool.poetry-version-plugin] +source = "git-tag" + [tool.poetry.dependencies] python = "^3.8" aiohttp = "^3.9.1"