This commit is contained in:
poka 2020-05-03 01:32:28 +02:00
commit 07f93699a5
37 changed files with 3644 additions and 0 deletions

10
.env.example Normal file
View File

@ -0,0 +1,10 @@
BOT_LOG_LEVEL=debug
BOT_NAME=brocket
BOT_SHELL_USER_NAME=user
BOT_SHELL_ROOM_NAME=shell
ROCKETCHAT_URL=http://localhost:3000
ROCKETCHAT_USER=brocket
ROCKETCHAT_PASSWORD=pass
RESPOND_TO_DM=true
RESPOND_TO_EDITED=true
LISTEN_ON_ALL_PUBLIC=false

68
.gitignore vendored Normal file
View File

@ -0,0 +1,68 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env-axiom-chat
# next.js build output
.next
# npm lockfile (using yarn)
package-lock.json
# Memo
memo.txt

29
Dockerfile Normal file
View File

@ -0,0 +1,29 @@
FROM node:8.11.2-alpine
LABEL maintainer="Rocket.Chat Team <buildmaster@rocket.chat>"
ENV npm_config_loglevel=error
ENV BOT_OWNER "No owner specified"
ENV BOT_DESC "bBot with the Rocket.Chat adapter"
USER root
COPY bin/bbot /home/bbot/bin/
COPY package.json /home/bbot/
COPY index.js /home/bbot/
COPY src/* /home/bbot/src/
RUN apk add --update --no-cache \
git && \
adduser -S bbot && \
addgroup -S bbot && \
touch ~/.bashrc && \
npm install --global npm@latest && \
chown -R bbot:bbot /home/bbot/
WORKDIR /home/bbot/
USER bbot
RUN npm install --no-audit
CMD ["/bin/ash", "/home/bbot/bin/bbot"]

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Amazebot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
README.md Normal file
View File

@ -0,0 +1,25 @@
Coabot - le gentil robot de la mare aux crapauds
==================================================
Coabot est basé sur [bbot](http://bbot.chat), un framework de bot pour rocketchat qui est encore en cours de développement. bbot est librement inspiré de hubot, le bot de chez github.
Voir https://wiki.crapaud-fou.org/coabot pour plus d'information à propos de ce bot.
Développement
------------
- `clone`
- `npm install`
- `edit .env`
- `npm start -- -m shell` (pour tester en local)
- `npm start`
Author
--------
- mose
License
---------
(c) copyright 2019 - mose - available under [MIT](LICENSE) License

148
bin/bbot Normal file
View File

@ -0,0 +1,148 @@
#!/bin/bash
# Stop NPM from complaining about useless stuff.
export npm_config_loglevel=error
# Listen for SIGINT/SIGTERM so the container can be killed with CTRL+C
# Also prevents reboot bug where the container freezes for 30-60 seconds
asyncRun() {
"$@" &
pid="$!"
trap "echo 'Stopping PID $pid'; kill -SIGTERM $pid" SIGINT SIGTERM
# Signal emitted while waiting will make the wait command return code > 128
# Wrap it in a loop that doesn't end before the process is indeed stopped
while kill -0 $pid >/dev/null 2>&1; do
wait
done
}
cat <<EOF
888 888888b. 888
888 888 "88b 888
888 888 .88P 888
88888b. 8888888K. .d88b. 888888
888 "88b 888 "Y88b d88""88b 888
888 888 888 888 888 888 888
888 d88P 888 d88P Y88..88P Y88b.
88888P" 8888888P" "Y88P" "Y888
8888888b. 888 888 .d8888b. 888 888
888 Y88b 888 888 d88P Y88b 888 888
888 888 888 888 888 888 888 888
888 d88P .d88b. .d8888b 888 888 .d88b. 888888 888 88888b. 8888b. 888888
8888888P" d88""88b d88P" 888 .88P d8P Y8b 888 888 888 "88b "88b 888
888 T88b 888 888 888 888888K 88888888 888 888 888 888 888 .d888888 888
888 T88b Y88..88P Y88b. 888 "88b Y8b. Y88b. d8b Y88b d88P 888 888 888 888 Y88b.
888 T88b "Y88P" "Y8888P 888 888 "Y8888 "Y888 Y8P "Y8888P" 888 888 "Y888888 "Y888
EOF
echo "Your bBot Rocket.Chat Docker container is now starting. Please wait..."
# Check if the Rocket.Chat URL has been set
if [[ -z "${ROCKETCHAT_URL}" ]]; then
echo "-------------"
echo "----ERROR----"
echo "-------------"
echo "ROCKETCHAT_URL environment variable has not been set."
echo "Set this to your Rocket.Chat Server URL. e.g."
echo "ROCKETCHAT_URL=https://bots.rocket.chat"
echo "-------------"
echo "Exiting...."
exit 1
fi
# Check if the Rocket.Chat User has been set
if [[ -z "${ROCKETCHAT_USER}" ]]; then
echo "-------------"
echo "----ERROR----"
echo "-------------"
echo "ROCKETCHAT_USER environment variable has not been set."
echo "Set this to the bot account username on your Rocket.Chat server. e.g."
echo "ROCKETCHAT_USER=brocket"
echo "-------------"
echo "Exiting...."
exit 1
fi
# Check if the Rocket.Chat password has been set
if [[ -z "${ROCKETCHAT_PASSWORD}" ]]; then
echo "-------------"
echo "----ERROR----"
echo "-------------"
echo "The ROCKETCHAT_PASSWORD Environment Variable has not been set."
echo "Set this to the bot account password on your Rocket.Chat server. e.g."
echo "ROCKETCHAT_PASSWORD=supersecret"
echo "-------------"
echo "Exiting...."
exit 1
fi
# Check there's either rooms defined, or the bot is listening to all
if [[ -z "${ROCKETCHAT_ROOM}" ]]; then
if [[ -z "${LISTEN_ON_ALL_PUBLIC}" ]]; then
echo "-------------"
echo "----ERROR----"
echo "-------------"
echo "Either ROCKETCHAT_ROOM or LISTEN_ON_ALL_PUBLIC need to be defined."
echo "Without rooms to join, if it's not listening on all public rooms,"
echo "the bot won't receive any messages to respond to. e.g."
echo "ROCKETCHAT_ROOM=general,my-private-room"
echo "or"
echo "LISTEN_ON_ALL_PUBLIC=true"
echo "-------------"
echo "Exiting...."
exit 1
fi
fi
# Install any required deps.
cd /home/bbot/
# Allow using custom registry for node modules
if [[ -z "${NPM_REGISTRY}" ]]; then
echo "INFO: The NPM_REGISTRY environment variable has not been set."
echo "INFO: Using npmjs as the default."
else
echo "INFO: The NPM_REGISTRY environment variable is $NPM_REGISTRY."
echo "INFO: NPM will use this registry to pull packages from."
npm set registry $NPM_REGISTRY
fi
# This happens here as well as during the container build process.
# This is insurance that no dependencies were missed.
# If node_modules externally mounted, insures the base deps are there.
echo "INFO: Attempting to install this containers dependancies"
npm install --no-audit
# Report information about optional behviour environment variables
if [[ -z "${RESPOND_TO_DM}" ]]; then
echo "-------------"
echo "INFO: The RESPOND_TO_DM environment variable has not been set."
echo "INFO: Set RESPOND_TO_DM=true to respond to direct messages."
echo "Default: RESPOND_TO_DM=false"
echo "-------------"
fi
if [[ -z "${RESPOND_TO_EDITED}" ]]; then
echo "-------------"
echo "INFO: The RESPOND_TO_EDITED environment varialbe is not set."
echo "INFO: Set RESPOND_TO_EDITED=true to respond to messages after edits."
echo "Default: RESPOND_TO_EDITED=false"
echo "-------------"
fi
if [[ -z "${RESPOND_TO_LIVECHAT}" ]]; then
echo "-------------"
echo "INFO: The RESPOND_TO_LIVECHAT environment varialbe is not set."
echo "INFO: Set RESPOND_TO_LIVECHAT=true to respond to livechat messages."
echo "Default: RESPOND_TO_LIVECHAT=false"
echo "-------------"
fi
set -e
export PATH="node_modules/.bin:node_modules/bbot/node_modules/.bin:$PATH"
# Start bBot using the asyncRun function
asyncRun node index.js "$@"

4
bin/bbot.cmd Normal file
View File

@ -0,0 +1,4 @@
@echo off
call npm install
SETLOCAL
node ../index.js %*

BIN
img/avatar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
img/banner.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

18
index.js Normal file
View File

@ -0,0 +1,18 @@
var glob = require( 'glob' )
, path = require( 'path' );
const bot = require('bbot')
/** This is a workaround for Heroku to confirm web binding. */
// @todo Remove this when bBot includes Express (next release)
const http = require('http')
const handle = (req, res) => res.end('hit')
const server = http.createServer(handle)
server.listen(process.env.PORT || 5000)
/** Add your bot logic here. Removing the imported examples. */
// require('./src/examples')
glob.sync( './src/*.js' ).forEach( function( file ) {
require( path.resolve( file ) );
});
bot.start() // 🚀

76
init.js Normal file
View File

@ -0,0 +1,76 @@
const fs = require('fs')
const cpm = require('child_process')
const { promisify } = require('util')
const inquirer = require('./node_modules/inquirer')
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
const copyFile = promisify(fs.copyFile)
const exec = promisify(cpm.exec)
async function replaceInFile (file, regex, value) {
const content = await readFile(file, 'utf8')
const update = content.replace(regex, value)
await writeFile(file, update, 'utf8')
}
inquirer.prompt([
{
type: 'input',
name: 'package',
message: 'Name your node package',
default: 'bbot-bot',
validate: (name) => (new RegExp('^[a-z@/-]*$').test(name))
? true
: 'Invalid name for npm package.'
},
{
type: 'input',
name: 'bot',
message: 'Name your new bot',
default: 'bot'
},
{
type: 'input',
name: 'author',
message: 'What is your name?'
},
{
type: 'input',
name: 'email',
message: 'Email (for package author field)'
},
{
type: 'confirm',
name: 'env',
message: 'Create .env with defaults?'
}
]).then(async (answers) => {
if (answers.package) {
await replaceInFile(
'./package.json',
/^(\s\s"name":\s")(.*?)(")/gm,
`$1${answers.package}$3`
)
}
if (answers.bot) {
await replaceInFile(
'./package.json',
/^(\s{2}"bot": {\n\s{4}"name": ")(.*?)(")/gm,
`$1${answers.bot}$3`
)
}
if (answers.author || answers.email) {
let author = answers.author ? answers.author : ''
if (answers.email) author += `<${answers.email}>`
await replaceInFile(
'./package.json',
/^(\s\s"author":\s")(.*?)(")/gm,
`$1${author}$3`
)
}
if (answers.env) {
await copyFile('.env.example', '.env')
await replaceInFile('.env', /brocket/g, answers.bot)
await exec('open .env')
}
})

53
package.json Normal file
View File

@ -0,0 +1,53 @@
{
"name": "bbot-bot",
"version": "1.0.0",
"description": "bRocket is a bBot boilerplate for building Rocket.Chat bots",
"main": "index.js",
"files": [
"index.js",
"src"
],
"repository": "git@github.com:Amazebot/bbot-rocketchat-boilerplate.git",
"author": "mose<mose@mose.com>",
"contributors": [],
"license": "MIT",
"private": false,
"engines": {
"node": "> 8.0.0",
"npm": "> 5.0.0"
},
"keywords": [
"bBot",
"Rocket.Chat",
"rocketchat",
"chatbot",
"chat",
"messaging",
"conversation",
"CUI"
],
"bot": {
"name": "bot",
"message-adapter": "rocketchat",
"avatar": "https://cloud.p2p.legal/apps/files_sharing/publicpreview/PGw3GwgWZbDMYSt"
},
"dependencies": {
"bbot": "^1.4.0",
"decode-entities": "^1.0.7",
"exec": "^0.2.1",
"glob": "^7.1.6",
"html-entities": "^1.2.1",
"path": "^0.12.7",
"unescape": "^1.0.1",
"util": "^0.12.1"
},
"devDependencies": {
"nodemon": "^1.18.3"
},
"scripts": {
"setup": "node init.js",
"start": "node index.js",
"watch": "nodemon index.js",
"debug": "nodemon --inspect index.js"
}
}

19
src/aide.js Normal file
View File

@ -0,0 +1,19 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('util')
bot.global.text({
contains: ['biz aide','biz help']
}, (b) => {
membres = exec("src/shell/aide.sh text", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'biz-aide'
});

51
src/axiom.js Normal file
View File

@ -0,0 +1,51 @@
const bot = require('bbot');
const exec = require('child_process').exec;
//ADMINS
var adminRooms = ["pokabizbot", "_recrutement", "compta-axiom", "_admin-at", "test-bot-chat", "poka", "equipe"];
//var adminRooms = exec("cat admins-chan.txt");
bot.global.text({
contains: ['axiom adhérent','axiom adhérents','axiom adherent','axiom adherents']
}, (b) => {
// cmd = b.message.text
// roomName = b.message.user.room.name
if (b.message.user.room.type == "p") {
roomName = b.message.user.room.name
} else {
roomName = b.message.user.name
}
if (adminRooms.indexOf(roomName) == -1) {
cmd = "adherentsSoft"
} else {
cmd = "adherents"
}
process.env.hb_cmd = cmd
pubkey = exec("src/shell/helloasso.sh $hb_cmd", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'axiom-adherents'
});
bot.global.text({
contains: ['axiom cagnotte']
}, (b) => {
membres = exec("src/shell/helloasso.sh cagnotte", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'axiom-cagnotte'
});

17
src/debug.js Normal file
View File

@ -0,0 +1,17 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const util = require('util');
bot.global.text({
contains: ['debug user']
}, (b) => {
username = b.message
// const userId = res.message.user.id
// username = robot.adapter.api.get('users.info', { userId })
// process.env.hb_username = username
b.reply("```" + util.inspect(username, {showHidden: false, depth: null}) + "```")
}, {
id: 'debug'
});

201
src/disabled/examples.js Normal file
View File

@ -0,0 +1,201 @@
const bot = require('bbot')
/**
* All branch examples start from the "global" conversation scope.
* We are working on features to provide branching within a conversational
* context, but as those methods are changing in the beta, they aren't included
* as examples to follow just yet.
*/
/**
* Branch types are declared from their scope, see all available types here:
* http://bbot.chat/docs/path#builtforbranching
*
* `text` branches take the following arguments:
* - matcher: expression, semantic conditions object, or array of conditions
* - callback: to fire on successful match, given the state object (b)
* - [options]: object with `id` (string) and/or `force` (boolean) attributes
*
* Test with "Hello bots!"
*/
bot.global.text(/(hi|hello).*bots?/, (b) => b.respond('Hello :wave:'), {
id: 'hello-bots'
})
/**
* `direct` branch type requires the bot to be explicitly addressed.
*
* `reply` instead of `respond` prepends messages with user's name.
*
* In Rocket.Chat all messages to a bot in a direct room have the name prepended
* by the Rocket.Chat SDK before it's processed by the bot framework.
*
* Test with "@brocket Hello" or just "Hello" in a DM.
*/
bot.global.direct(/hi|hello/i, (b) => b.reply('Hey there.'), {
id: 'hello-direct'
})
/**
* `respondVia` allows using custom platform methods to dispatch response.
*
* Matcher conditions allow semantic attributes with a string or array of
* optional values to match against, possibly capturing content.
* Accepted atts: is, starts, ends, contains, excludes, after, before, range
*
* Test with "Hello anyone?"
*/
bot.global.text({
contains: ['hi', 'hello']
}, (b) => b.respondVia('react', ':wave:'), {
id: 'hello-react'
})
/**
* Branch callbacks allow asynchronous responding, if they return a promise.
* State (b) includes branch matching attributes, see bbot.chat/docs/thought.
*
* Test with "@brocket ping back in 5 seconds"
*/
bot.global.direct(/ping back in (\d*)/i, async (b) => {
const ms = parseInt(b.match[1]) * 1000
await new Promise((resolve) => setTimeout(resolve, ms))
return b.respond('Ping :ping_pong:')
}, {
id: 'ping-delay'
})
/**
* The `respond` method can accept attachment objects as well as strings.
* Rendering support depends on the message platform and adapter. In shell,
* it will display the fallback text.
*
* Test with "bot attach image"
*/
bot.global.text(/attach image/i, (b) => {
return b.respond({
fallback: `See: https://www.wikiwand.com/en/Three_Laws_of_Robotics`,
image: `https://upload.wikimedia.org/wikipedia/en/8/8e/I_Robot_-_Runaround.jpg`,
title: {
text: `Asimov's Three Laws of Robotics`,
link: `https://www.wikiwand.com/en/Three_Laws_of_Robotics`
}
})
}, { id: 'attach-image' })
/**
* The `envelope` provides helpers for adding rich-message payloads before
* responding. Preparing envelopes before dispatch also allows changing the
* user/room the envelope is addressed to or dispatching multiple envelopes.
*
* Test with "I want a prize"
*/
bot.global.text({
contains: 'prize'
}, (b) => {
b.envelope.write('Choose your fate! 🚪... 🎁 ')
b.envelope.attach({ color: '#f4426e' })
b.envelope.payload
.quickReply({ text: 'Door number 1' })
.quickReply({ text: 'Door number 2' })
.quickReply({ text: 'Door number 3' })
return b.respond().catch((err) => console.error(err))
}, { id: 'door-prize-intro' })
/**
* The `conditions` attribute contains results of semantic condition matching
* and capture groups. Each condition can be given a key for easy reference.
*
* Test with "what's behind door number 2"
*/
bot.global.text({
door: { after: 'door', range: '1-3' }
}, (b) => {
switch (b.conditions.captured.door) {
case '1': return b.respond(`You win nothing 💔`)
case '2': return b.respond(`You win a monkey 🐒`)
case '3': return b.respond(`It's a new car!! 🚗`)
}
}, { id: 'door-prize-award' })
/**
* Branch callbacks can be async functions, to awaiting one or more processes
* before responding. This example uses API requests to fill a dynamic array
* of actions, using the url property to provide link action buttons.
*
* Test with "@brocket plan meeting" in a public or private room.
*/
bot.global.direct({
is: 'plan meeting'
}, async (b) => {
if (bot.adapters.message.name !== 'rocketchat-message-adapter') return
b.envelope.write('Please review time zones in the room...')
const { id, type } = b.message.user.room
let room
const q = { roomId: id }
if (type === 'c') {
room = await bot.adapters.message.api.get('channels.members', q, true)
} else if (type === 'p') {
room = await bot.adapters.message.api.get('groups.members', q, true)
} else {
return b.respond('Sorry, that only works in channels and private groups.')
}
const offsets = room.members
.map((member) => member.utcOffset || undefined)
.filter((offset) => !!offset)
for (let utc of offsets) {
b.envelope.payload.quickReply({
text: `🌐 UTC ${utc}`,
url: `https://www.timeanddate.com/worldclock/timezone/utc${utc}`
})
}
b.respond()
})
/**
* @todo This example requires PR #11811 to be merged. Room names are undefined.
*/
bot.global.text(/where am i/i, (b) => {
const { name, type } = b.message.user.room
switch (type) {
case 'c': return b.respond(`You're in the #${name} public channel.`)
case 'p': return b.respond(`You're in a private group called **${name}**.`)
case 'l': return b.respond(`You're in a livechat channel.`)
case 'd': return b.respond(`You're in a DM with me :hugging:`)
}
}, {
id: 'location-check'
})
/**
* Custom options can be added to the bot, with the full config utility of bBot,
* allowing them to be defined as environment variables, command line args or
* package.json attributes. Extend settings with a yargs option format.
*
* Try any of the following:
* - `node index.js --avatar <YOUR_AVATAR_URL>`
* - BOT_AVATAR=<YOUR_AVATAR_URL> in .env
* - `{ "bot": { "avatar": "<YOUR_AVATAR_URL>" } }` in package.json
*/
bot.settings.extend({
avatar: {
'type': 'string',
'description': 'Set a custom avatar for your bot account profile'
}
})
/**
* The bot can access lower level methods of the Rocket.Chat SDK through the
* message adapter, once it's connected. This example sets an avatar on login.
*
* Try replacing the avatar configured in package.json with your own.
*/
bot.events.on('started', () => {
if (bot.adapters.message.name !== 'rocketchat-message-adapter') return
if (bot.settings.get('avatar')) {
bot.logger.info('Setting bot avatar')
bot.adapters.message.api.post('users.setAvatar', {
avatarUrl: bot.settings.get('avatar')
})
}
})

33
src/disabled/tpl.js Normal file
View File

@ -0,0 +1,33 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('util')
bot.global.text({ contains: [''] }, (b) => b.respond(""), {
id: 'id-tpl'
})
// --------
bot.global.text({ contains: [''] }, (b) => {
b.respond("")
}, {
id: 'id-tpl-2'
});
// --------
bot.global.text({
contains: ['']
}, (b) => {
membres = exec("src/shell/.sh", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'id-tpl-3'
});

View File

@ -0,0 +1,57 @@
const bot = require('bbot');
const request = require('request');
const decodeEntities = require('decode-entities');
//var decode = require('unescape');
var request_options = {
headers: {
'User-Agent': 'crabot retrieving url metadata (https://wiki.crapaud-fou.org/crabot)'
}
};
bot.global.text(/(https?:\/\/[^ ,\)"\n]*)/ig, async (b) => {
// console.log(JSON.stringify(b.match, null, 2));
for (url of b.match) {
// console.log(JSON.stringify(url, null, 2));
if (!/(coa|pad)\.crapaud-fou\.org/.test(url)) {
request_options.url = url;
request(request_options, (err, res, body) => {
// console.log(JSON.stringify(res, null, 2));
if (!err && res.statusCode === 200) {
var re = /<title[^>]*>([^<]*)<\/title>/gi;
var match = re.exec(body);
if (match && match[1]) {
var extra = "";
var link = res.request.uri.href;
link = link.replace(/[\?&]fbclid=.+/gi, "");
link = link.replace(/[\?&]ncid=.+/gi, "");
//kopa match[1] = match[1].replace("&#039;", "'");
if (/youtube.com/.test(link)) {
if (t = /[?&]v=([^&]+)/.exec(link)) {
link = "https://www.youtube.com/watch?v=" + t[1];
extra += " - [no-cookie](https://www.youtube-nocookie.com/embed/" + t[1] + ")";
extra += " - [invidious](https://invidio.us/watch?v=" + t[1] + ")";
}
}
b.respond(decodeEntities("[>>>](" + link + ") _" + match[1].replace(/\n/g, " ").trim() + "_" + extra));
// b.respond("\>\>\>\> _" + match[1].replace(/\n/g, " ").trim() + "_" + extra);
}
} else {
console.log('-----------------------------------');
console.log('URL: ' + url);
console.log('ERR - - - - - - - - - - - - - - - -');
console.log(JSON.stringify(err, null, 2));
console.log('RES - - - - - - - - - - - - - - - -');
console.log(JSON.stringify(res, null, 2));
console.log('-----------------------------------');
}
});
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}, {
id: 'get-url-metadata'
});

34
src/g1-info.js Normal file
View File

@ -0,0 +1,34 @@
const bot = require('bbot');
const exec = require('child_process').exec;
bot.global.text({
starts: ['pubkey','rib','biz rib', 'biz pubkey']
}, (b) => {
username = b.message.user.name
cmd = b.message.text
process.env.hb_cmd = cmd
process.env.hb_username = username
pubkey = exec("src/shell/g1-infos.sh pubkey $hb_username $hb_cmd", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'g1-pubkey'
});
bot.global.text({
contains: ['membre','membres']
}, (b) => {
membres = exec("src/shell/g1-infos.sh membres", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'g1-membres'
});

20
src/g1sms.js Normal file
View File

@ -0,0 +1,20 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('util')
bot.global.text({
contains: ['TEST BSMS']
}, (b) => {
b.respond("Test de G1SMS ...")
membres = exec("g1sms/test.sh chat", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'sms-test'
});

16
src/hubot_scripts/aide.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = (robot) =>
{
robot.respond( /aide/i, (res) =>
res.reply( `QWant est ton ami...
... Nan j'déconne, voici ce que je connais:
- *biz aide*: Affiche cette aide
- *biz liens*: Donne des liens utiles
- *index pads*: Donne le lien vers l'index de nos pads
- *membres*: Affiche le nombre de membres actuelles de la Ğ1
- *pubkey*: Affiche sa propre clé publique Ğ1
- *axiom adhérents*: Affiche les adhérents de l'association
- *axiom cagnotte*: Affiche le status de la cagnotte de l'association
- Massages Viet pour 150Ğ1
- Et bien d'autres choses, je vais pas tout te dire non plus !! :rofl:` )
)
}

View File

@ -0,0 +1,12 @@
module.exports = (robot) =>
{
robot.hear( /index pad/i, res=> res.send(":arrow_right: https://pad.p2p.legal/axiom_index-pads") )
robot.hear( /index des pad/i, res=> res.send(":arrow_right: https://pad.p2p.legal/axiom_index-pads") )
robot.respond( /lien/i, res=> res.send(`*Index de tous nos documents* :arrow_right: https://pad.p2p.legal/axiom_index-pads
*Site officiel de l'association Axiom-Team* :arrow_right: https://axiom-team.fr/
*Forum de l'asso axiom-team* :arrow_right: https://forum.axiom-team.fr/
*Cloud publique axiom - Ressources Agora* :arrow_right: https://cloud.p2p.legal/s/DDbKi2pqdEmixS9
*Cloud interne axiom - Nécessite un accès* :arrow_right: https://cloud.p2p.legal/f/204193`
) )
}

11
src/inc/aide.txt Normal file
View File

@ -0,0 +1,11 @@
*Voici ce que je sais faire ...*
```
- biz aide: Affiche cette aide
- biz liens: Donne des liens utiles
- index pads: Donne le lien vers l'index de nos pads
- membres: Affiche le nombre de membres actuelles de la Ğ1
- pubkey [pseudo]: Affiche sa propre clé publique Ğ1 si [pseudo] n'est pas renseigné, ou bien celle du pseudo indiqué
- axiom adhérents: Affiche les adhérents de l'association
- axiom cagnotte: Affiche le status de la cagnotte de l'association
```

6
src/inc/liens.txt Normal file
View File

@ -0,0 +1,6 @@
index pad !! https://pad.p2p.legal/axiom_index-pads
Site officiel de l'association Axiom-Team !! https://axiom-team.fr/
Forum de l'asso axiom-team !! https://forum.axiom-team.fr/
Cloud publique axiom - Ressources Agora !! https://cloud.p2p.legal/s/DDbKi2pqdEmixS9
Cloud interne axiom _(Nécessite un accès)_ !! https://cloud.p2p.legal/f/204193`

9
src/inc/need-certif.txt Normal file
View File

@ -0,0 +1,9 @@
5 personnes membres vous connaissent-elles bien ? Peuvent-elles vous contacter ? Contacter votre entourage ? Avez-vous sauvegardé votre document de révocation ? Avez-vous installé un client local sur votre ordinateur/smartphone comme Cesium ?
Si oui -> vous connaissez certainement ces personnes vous aussi, et pouvez leur demander.
Si non -> il va vous falloir créer des liens avec des membres, conformément à la **[licence](https://duniter.org/fr/wiki/licence-g1/)** que vous devez lire, comprendre et accepter.
Je vous invite également à lire le **[guide du débutant](https://forum.monnaie-libre.fr/t/00-intro-guide-du-debutant-en-monnaie-libre-g1-june/2777)**, et surtout à vous renseigner sur les rencontres de présentation de la monnaie libre autour de chez vous, pour créer des relations humaines réelles.
Bienvenue, et bonnes découvertes !

View File

@ -0,0 +1,6 @@
OBSCURANTISTE!
MENTEUR!
Toute mlc ne sert qu'à nuire à leveil de conscience sur la création monétaire.
Avez vous déjà vérifié les arguments (fallacieux) servis par les rabatteurs de mlc?
Les mlc coutent un bras au profit des banques et de quelques « chiens de garde» de leur salaire en unl qui en découle (rabatteurs).
La plus grosse mlc de lhistoire jai analysé: La mlc argentine en 2001. Elle a permis lemergence de Monsanto compagny en 2002. Nhésitez pas à vérifier.

23
src/jokes.js Normal file
View File

@ -0,0 +1,23 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
bot.global.text({ contains: ['vtfn','si tes pas content','si t\'es pas content'] }, (b) => b.respond(":arrow_right: https://vatefairecuireunnem.com/"), {
id: 'joke-vtfn'
})
bot.global.text({ contains: ['biz présente toi'] }, (b) => b.respond(":arrow_right: https://matiou.biz"), {
id: 'joke-presente'
})
// L'infernal matiou sur les MLC ...
let bizbi = fs.readFileSync('./src/inc/repliques-mlc.txt', 'utf8');
bizbi = bizbi.split('\n')
function randomize(toRand) {
resultRand = toRand[Math.floor(Math.random()*toRand.length)]
return resultRand;
}
bot.global.text({ contains: ['mlc'] }, (b) => b.respond(randomize(bizbi)), {
id: 'joke-presente'
})

21
src/liens.js Normal file
View File

@ -0,0 +1,21 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('util')
bot.global.text({
contains: ['biz lien','biz liens']
}, (b) => {
cmd = b.message.text
process.env.hb_cmd = cmd
membres = exec("src/shell/liens.sh $hb_cmd", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu ...")
} else {
b.respond(stdout)
}
});
}, {
id: 'biz-liens'
});

23
src/reactions.js Normal file
View File

@ -0,0 +1,23 @@
const bot = require('bbot');
const globe_delay = 60000; // 1 minute
var globe_said = {};
bot.global.text({
contains: ['facebook', 'google', 'amazon', 'apple', 'microsoft']
}, (b) => {
b.respondVia('react', ':hear_no_evil:');
}, {
id: 'gafam-react'
});
bot.global.text(
/pe?tit? globe/i
, (b) => {
if (!globe_said[b.message.user.room] || new Date().getTime() > globe_said[b.message.user.room] + globe_delay) {
b.respond('![pti globe](https://crapaud-fou.org/images/chat-ptiglobe.png)');
globe_said[b.message.user.room] = new Date().getTime();
}
}, {
id: 'ptiglobe-direct'
})

22
src/reload.js Normal file
View File

@ -0,0 +1,22 @@
const bot = require('bbot');
const exec = require('child_process').exec;
bot.global.text({
is: ['biz reload']
}, (b) => {
function reload() {
pubkey = exec("pm2 reload index --force", function(err, stdout, stderr) {
if (err) {
b.respond("Une erreur est survenu: " + " - " + stderr)
} else {
b.respond("Biz a été rechargé")
}
});
};
b.respond("Biz redémarre ... OK dans 5 secondes")
setTimeout(reload, 10);
}, {
id: 'reload-scripts'
});

12
src/repondeur.js Normal file
View File

@ -0,0 +1,12 @@
const bot = require('bbot');
const exec = require('child_process').exec;
const fs = require('fs');
const util = require('util')
bot.global.text({ contains: ['me certifier','me faire certifier','je cherche une certification','je cherche des certifications'] }, (b) => {
// Lisez la licence Ḡ1 ...
let newml = fs.readFileSync('./src/inc/need-certif.txt', 'utf8');
b.respond("Bonjour, et bienvenue @" + b.message.user.name + " ! =)" + newml)
}, {
id: 'rep-certif'
});

21
src/shell/aide.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
auto() {
echo "*Je suis l'aide auto*"
cd src
#cmds=$(grep "^bot\." *.js -A3 | grep -E "\['|aide = ")
cmds=$(grep "\['" *.js | awk -F "[" '{ print $2 }' | awk -F "]" '{ print $1 }')
IFS=$'\n'
for i in $cmds; do
echo "$i" | awk -F "'" '{ print $2 }'
done
}
text() {
cat src/inc/aide.txt
}
$@
exit 0

30
src/shell/g1-infos.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
node="http://192.168.9.54:45000"
pubkey() {
url="$node/wot/members"
# if [[ "$@" =~ "brocket" ]]; then
# [[ $4 ]] && username=$4 || username=$1
# else
# [[ $3 ]] && username=$3 || username=$1
# fi
args=$(echo $@ | tr ' ' '\n' | grep -v 'biz' | tr '\n' ' ')
[ $(echo $args | wc -w) -ge 3 ] && username=$(echo $args | awk '{ print $3 }') || username=$1
username=$(echo $username | tr -d '@')
local pubkey=$(curl -m 5 -s $url | grep -w -i -B 1 $username | grep "pubkey" | awk -F '"' '{ print $4 }')
# TODO: local pubkey=$(curl -m 5 -s $url | jq -r --arg username "$username" '.results[] | select(.uid=="$username") | .pubkey')
[[ $pubkey ]] && echo "@$username Ta clé publique Ğ1 est: $pubkey" || echo "@$username n'est pas pseudo membre de la Ḡ1"
}
membres() {
url="$node/blockchain/current"
local nbr_membres=$(curl -m 5 -s $url | jq '.membersCount')
[[ $nbr_membres ]] && echo "Il y a actuellement $nbr_membres membres de la Ğ1 !" || echo "Service en maintenance, réessayez dans un instant :coffee:"
}
$@
exit 0

25
src/shell/helloasso.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
ids="axiom-team:tYrjD6rrfStJXBqHhzNET"
ha="https://api.helloasso.com/v3"
adherents() {
url="$ha/campaigns/000001053192/actions.json?type"
curl -m 5 --user $ids -s $url | jq -r '.resources[] | .date + " , " + .first_name + " " + .last_name + " - " + .email' | sed 's/T.*,//'
}
adherentsSoft() {
url="$ha/campaigns/000001053192/actions.json?type"
curl -m 5 --user $ids -s $url | jq -r '.resources[] | .date + " , " + .first_name + " " + .last_name' | sed 's/T.*,//'
}
cagnotte() {
url="$ha/campaigns/000001053192.json"
curl -m 5 --user $ids -s $url | jq -r '.name, {"Donnateurs": .supporters},{"Fonds":.funding},.url' | grep -vE '{|}'
}
$@
exit 0

12
src/shell/liens.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
if [[ -z $3 ]]; then
res=$(sed 's/!!/:arrow_right:/g' src/inc/liens.txt)
else
shift 2
res=$(sed 's/!!/:arrow_right:/g' src/inc/liens.txt | grep -i "$@")
fi
[[ $res ]] && echo "$res" || echo "Aucun lien trouvé avec **$@**"
exit 0

22
src/shell/tata.txt Normal file
View File

@ -0,0 +1,22 @@
2019-05-03 Rémi Colomb - gepi@riseup.net
2019-05-13 Chrystel MAGENC - chrystel.magenc@gmail.com
2019-05-17 Cédric Dumond - cedric.dumond@free.fr
2019-05-17 lisette MARCAHOSSE - monnaielibre66@gmail.com
2019-05-18 ELOIS SANCHEZ - elois@ifee.fr
2019-05-30 Rémi Colomb - gepi@riseup.net
2019-06-12 Genevieve GARCIA - g1.genevieve@lilo.org
2019-09-04 Pi nguyen - contact@axiom-team.fr
2019-09-10 Jean-Yves Toumit - saiolar-c@yahoo.fr
2019-09-13 Nicolas Chenu - scanlegentil@hotmail.com
2019-09-22 Jules EMERY - j.emeryan@outlook.com
2019-09-25 Etienne BOUCHE - poka@p2p.legal
2019-09-27 vincent dardel - ehvince@mailz.org
2019-10-30 Arnaud Langlois - ar.langlois@gmail.com
2019-11-04 Nicolas Chenu - scanlegentil@hotmail.com
2019-11-22 ELOIS SANCHEZ - c@elo.tf
2020-01-07 daniel leporini - daniel.leporini@gmail.com
2020-01-15 Emmanuel Salomon - emmanuel.salomon@gmail.com
2020-01-17 Fanch DAUBORD - fanchdaub@gmail.com
2020-01-30 Damien Leroy - damienleroy77@gmail.com
2019-10-04 Nicolas Chenu - scanlegentil@hotmail.com

2489
yarn.lock Normal file

File diff suppressed because it is too large Load Diff