Compare commits
9 Commits
2abb14e7c0
...
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 975c3a4131 | |||
| 5b9d8920de | |||
|
|
1a58e61d36 | ||
| 41902ad080 | |||
| 9f8c08e561 | |||
| 6126bc3bb1 | |||
| 98c84ff171 | |||
|
|
9525d8dc9d | ||
|
|
f91f0d229a |
73
.gitea/workflows/build-and-release.yml
Normal file
73
.gitea/workflows/build-and-release.yml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
name: Build and Release Maubot Plugin
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build Plugin
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install maubot
|
||||||
|
|
||||||
|
- name: Build Plugin
|
||||||
|
run: |
|
||||||
|
mbc build .
|
||||||
|
env:
|
||||||
|
MB_PLUGIN_DIR: ${{ github.workspace }}
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
|
- name: Upload Build Artifact
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: plugin
|
||||||
|
path: fr.mrraph.hoarder-bot-*.mbp
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: gitea/create-release@v1
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
with:
|
||||||
|
gitea_url: https://git.mrraph.fr # Remplacez par l'URL de votre Gitea
|
||||||
|
token: ${{ secrets.TOKEN }}
|
||||||
|
owner: ${{ github.repository_owner }}
|
||||||
|
repo: ${{ github.event.repository.name }}
|
||||||
|
tag: ${{ github.ref_name }}
|
||||||
|
name: "Release ${{ github.ref_name }}"
|
||||||
|
body: |
|
||||||
|
## Description
|
||||||
|
Plugin Maubot compilé à partir du tag `${{ github.ref_name }}`.
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
|
||||||
|
- name: Upload Release Asset
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: fr.mrraph.hoarder-bot-*.mbp
|
||||||
|
asset_name: r.mrraph.hoarder-bot-${{ github.ref_name }}.mbp
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
25
hoarder.py
25
hoarder.py
@@ -78,14 +78,7 @@ class HoarderForwarder(Plugin):
|
|||||||
|
|
||||||
hoarder_url = self.config["hoarder_url"]
|
hoarder_url = self.config["hoarder_url"]
|
||||||
api_key = self.config["hoarder_api_key"]
|
api_key = self.config["hoarder_api_key"]
|
||||||
create_endpoint = f"{hoarder_url}/api/trpc/bookmarks.createBookmark"
|
create_endpoint = f"{hoarder_url}/api/v1/bookmarks"
|
||||||
|
|
||||||
self.log.info(hoarder_url)
|
|
||||||
#title = await self.get_page_title(url) # Récupère le titre de la page
|
|
||||||
|
|
||||||
if not hoarder_url or not api_key:
|
|
||||||
self.log.warning("L'URL ou la clé API de Hoarder n'est pas configurée.")
|
|
||||||
return
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {api_key}",
|
"Authorization": f"Bearer {api_key}",
|
||||||
@@ -93,10 +86,8 @@ class HoarderForwarder(Plugin):
|
|||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
}
|
}
|
||||||
payload = {
|
payload = {
|
||||||
"json": {
|
"type": "link",
|
||||||
"type": "link",
|
"url": url
|
||||||
"url": url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -104,9 +95,9 @@ class HoarderForwarder(Plugin):
|
|||||||
async with session.post(create_endpoint, json=payload, headers=headers) as response:
|
async with session.post(create_endpoint, json=payload, headers=headers) as response:
|
||||||
if response.status == 200 or response.status == 201 or response.status == 204:
|
if response.status == 200 or response.status == 201 or response.status == 204:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
bookmark_id = data[0]["result"]["data"]["json"]["id"]
|
bookmark_id = data["id"]
|
||||||
await self.send_message(evt, f"Bookmark créé avec succès : {bookmark_id}", in_thread=False)
|
await self.send_message(evt, f"Bookmark créé avec succès : {bookmark_id}", in_thread=False)
|
||||||
self.add_bookmark_to_list(bookmark_id, hoarder_list)
|
await self.add_bookmark_to_list(evt, bookmark_id)
|
||||||
return bookmark_id
|
return bookmark_id
|
||||||
else:
|
else:
|
||||||
await self.send_message(evt, f"Erreur lors de la création du bookmark : {response.status}", in_thread=False)
|
await self.send_message(evt, f"Erreur lors de la création du bookmark : {response.status}", in_thread=False)
|
||||||
@@ -202,7 +193,7 @@ class HoarderForwarder(Plugin):
|
|||||||
api_key = self.config["hoarder_api_key"]
|
api_key = self.config["hoarder_api_key"]
|
||||||
|
|
||||||
list_id = await self.ensure_list_exists(evt, self.config["hoarder_list_name"])
|
list_id = await self.ensure_list_exists(evt, self.config["hoarder_list_name"])
|
||||||
add_to_list_endpoint = f"{hoarder_url}/api/v1/lists/{list_id}/bookmarks"
|
add_to_list_endpoint = f"{hoarder_url}/api/v1/lists/{list_id}/bookmarks/{bookmark_id}"
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {api_key}",
|
"Authorization": f"Bearer {api_key}",
|
||||||
@@ -210,10 +201,6 @@ class HoarderForwarder(Plugin):
|
|||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = {
|
|
||||||
"bookmarkId": bookmark_id
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.put(add_to_list_endpoint, headers=headers) as response:
|
async with session.put(add_to_list_endpoint, headers=headers) as response:
|
||||||
|
|||||||
Reference in New Issue
Block a user