Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1 plantnet identification on BlueSky #2

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[ < Back](../README.md)

# HowTo Contribute

Please create an [issue](https://github.com/boly38/botEnSky/issues) describing your goal / question / bug description...

If you're interested in an existing issue, please contribute by up-voting for it by adding a :+1:.

If you want to push some code :
- fork and prepare a feature-git-branch, then create a [pull request](https://github.com/boly38/botEnSky/pulls) that link your issue.
- execute tests

You could also be critic with existing ticket/PR : all constructive feedbacks are welcome.

## HowTo execute tests
* launch tests using `npm test`.

Think about environment setup.


## Basis reminder
Clone this repository from GitHub:

```
$ git clone https://github.com/boly38/botEnSky.git
```

### Prerequisites

1. Install NodeJs (https://nodejs.org/en/download/)
2. Install dependencies
```bash
npm install
```

### Set your own private environment

- study each required environment variable in the [template](../env/.env.template)
- copy the template in a private file
```bash
cp ./env/.env.template ./env/.env.development
```

### Start the bot

Execute the application
```bash
npm startDev
```
or (production mode)
```bash
npm run start
```

## PullRequests additional information
Activated bot:
- [houndci](https://houndci.com/)
43 changes: 43 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: botensky-audit

on:
schedule:
- cron: '0 10 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
scan:
name: npm audit
runs-on: ubuntu-latest

strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
# - run: npm ci # need package.json.lock
run: |
echo "install"
npm install
echo "show outdated (if any)"
npm outdated --depth=3 || echo "you must think about update your dependencies :)"

- name: Audit backend
uses: oke-py/npm-audit-action@v2.4.4
with:
audit_level: moderate
github_token: ${{ secrets.GITHUB_TOKEN }}
issue_assignees: boly38
issue_labels: cybersecurity,bot-created
dedupe_issues: true
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# continuous integration
name: botensky-ci

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the prod branch
push:
branches: [ main ]
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x]

environment: github_actions_bes #NODE_ENV=test
steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
# npx force-resolutions : in case of Permission denied: run it locally to fix package-lock.json
run: |
echo "install"
npm install
echo "show outdated (if any)"
npm outdated --depth=3 || echo "you must think about update your dependencies :)"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ
.idea/
*.iml

# wip
draft/
9 changes: 9 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# jshint last release was 2 years ago, and hang locally
jshint:
config_file: .jshintrc
# ESLint supported version
# http://help.houndci.com/en/articles/2461415-supported-linters
eslint:
enabled: true
version: 8.1.0
config_file: .hound_eslint_config.json
19 changes: 19 additions & 0 deletions .hound_eslint_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"root": true,
"extends": [
"eslint:recommended"
],
"env" : {
"browser" : true,
"node" : true,
"es6" : true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2022
},
"plugins": [
],
"rules": {
}
}
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 6
}
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
#botEnSky
# botEnSky

botEnSky is a bot [BlueSky social app](https://bsky.app/)
botEnSky is a [BlueSky social app](https://bsky.app/) bot born on May 16, 2024.
- written in JavaScript (Node.js ESM Project),
- the worthy successor to [@botentrain1](https://twitter.com/botentrain1) (ex Twitter bot - [code](https://github.com/boly38/botEnTrain)) but for BlueSky.

- status: **Started May 16, work in progress**
The goal is to bring happiness to Bluesky users.

It is a NodeJs application that relies on [bsky api](https://docs.bsky.app/).
## References

The goal is to be the worthy successor to [@botentrain1](https://twitter.com/botentrain1) ([src](https://github.com/boly38/botEnTrain)) but for BlueSky.
- **BlueSky 🤖 Bot account : [@botensky.bsky.social](https://bsky.app/profile/botensky.bsky.social)** 🤖
- Bot webPage : [botensky.onrender.com](https://botensky.onrender.com/)

The search is not the same between the two networks (X, Bsky), so we will have to think about new designs, but the first function considered is plant identification
## Bot features (plugins)

- French help - cf. [botensky.onrender.com](https://botEnSky.onrender.com)
- English [releases notes](https://github.com/boly38/botEnSky/releases) - via [![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/)

## How to contribute ?

cf. [CONTRIBUTING](.github/CONTRIBUTING.md)

### Credits

Application and code structure:
- [NodeJs](https://nodejs.org/) and Node dependencies (cf. [graph](https://github.com/boly38/botEnSky/network/dependencies))
- [BlueSky API](https://docs.bsky.app/)

Services ( having free plan 🚀 🌷 )
- [GitHub Actions](https://github.com/features/actions)
- [Render](https://render.com/) free app hosting and automated deployments
- [Cron-job.org](https://cron-job.org/) scheduler
- [PlantNet.org](https://plantnet.org) ([API](https://my.plantnet.org/)) - plant identification service

Team:
- cf. [contributors](https://github.com/boly38/botEnSky/graphs/contributors)
5 changes: 5 additions & 0 deletions bin/commonEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import dotEnvFlow from 'dotenv-flow';
export const initEnv = () => {
//~ project init of environment
dotEnvFlow.config({ path: './env/' });
}
15 changes: 15 additions & 0 deletions bin/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import console from "node:console";
import {initEnv} from "./commonEnv.js";
import ApplicationConfig from '../src/config/ApplicationConfig.js';

initEnv();
const appConfig = ApplicationConfig.getInstance();

const showResultAsJson = result => console.log(JSON.stringify(result, null, 2));

let botService = appConfig.get('botService');
botService.run();
const pluginName = "Plantnet";
await botService.process("0.0.0.0", true, pluginName)
.then(showResultAsJson)
.catch(console.log)
3 changes: 3 additions & 0 deletions bin/startDev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
. ./env/.env.bash.development
exec node ./bin/www
3 changes: 3 additions & 0 deletions bin/startServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
. ./env/.env.bash.production
exec node --unhandled-rejections=strict ./bin/www
7 changes: 7 additions & 0 deletions bin/www.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import console from "node:console";
import {initEnv} from "./commonEnv.js";
import ApplicationConfig from '../src/config/ApplicationConfig.js';

initEnv();
ApplicationConfig.startServerMode()
.catch(console.error);
2 changes: 2 additions & 0 deletions env/.env.bash.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
export NODE_ENV=development
2 changes: 2 additions & 0 deletions env/.env.bash.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
export NODE_ENV=production
17 changes: 17 additions & 0 deletions env/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# server default timezone
TZ=Europe/Paris

## BlueSky
##########
# https://bsky.app/settings/app-passwords
BLUESKY_SERVICE=https://bsky.social
# BLUESKY_USERNAME may be full username (user.bsky.social), or user email
BLUESKY_USERNAME=XXXXXXXXXXXX.bsky.social
# PASSWORD may be user password or app password
BLUESKY_PASSWORD=YYYYYYYYYYYYY

## Pla@ntNet
############
PLANTNET_API_PRIVATE_KEY=ZZZZZZZZZZZZZZ
# PLANTNET_SIMULATE=true will simulate Pl@ntNet API result
BOT_PLANTNET_SIMULATE=true
8 changes: 8 additions & 0 deletions env/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.env
.env.*
.env.test
!.env.githubaction
!.env.template
!.env.bash.development
!.env.bash.production
deprecated
31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// https://eslint.org/docs/latest
import js from "@eslint/js";
import globals from "globals";
import mochaPlugin from 'eslint-plugin-mocha'; // https://www.npmjs.com/package/eslint-plugin-mocha
import stylisticJs from '@stylistic/eslint-plugin-js'
export default [
js.configs.recommended, // Recommended config applied to all files
mochaPlugin.configs.flat.recommended, // or `mochaPlugin.configs.flat.all` to enable all
{
"files": ["lib/**/*.js", "examples/**/*.js", "tests/**/*.js"],
"languageOptions": {
ecmaVersion: 2022,
sourceType: "module",
globals: {
...globals.node,
"process": true
},
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
},
},
plugins: {
'@stylistic/js': stylisticJs
},
"rules": {
"mocha/no-mocha-arrows": "off", /* pff */
'@stylistic/js/no-extra-semi': "error", /* to match houndci : https://eslint.org/docs/latest/rules/no-extra-semi */
}
}
];
Loading
Loading