fix tests, start addon implementation

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-25 17:02:25 +02:00
parent 9f74bcfec4
commit 7bad01b258
12 changed files with 92 additions and 33 deletions

41
addons/example.sh Normal file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# file: addons/example.sh.dist
#
# Addons can register to bashbot events at statup
# by providing their name and a callback per event
#
# If an event occours a subprocess is spawned and call
# all registered event functions.
# Availible events:
#
# BASBOT_EVENT_INLINE inline query received
# BASBOT_EVENT_MESSAGE any type of message received
# BASBOT_EVENT_REPLY reply to message received
# BASBOT_EVENT_FORWARD forwarded message received
# BASBOT_EVENT_CONTACT contact received
# BASBOT_EVENT_LOCATION location or venue received
# BASBOT_EVENT_FILE file received
#
# all global variables and functions can be used.
# any global variable defined by addons MUST be prefixed by addon name
# funtion local varibales can have an name
EXAMPLE_ME="example"
# register to inline
export BASBOT_EVENT_INLINE["${EXAMPLE_ME}"]="${EXAMPLE_ME}_inline"
# any function defined by addons MUST be prefixed by addon name
example_inline(){
send_normal_message "${CHAT[ID]}" "Inline query received: ${MESSAGE}"
}
# register to reply
export BASBOT_EVENT_REPLY["${EXAMPLE_ME}"]="${EXAMPLE_ME}_reply"
# any function defined by addons MUST be prefixed by addon name
example_reply(){
send_markdown_message "${CHAT[ID]}" "User *${USER[USERNAME]}* replied to message from *${REPLYTO[USERNAME]}*"
}

View File

@ -11,7 +11,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -341,6 +341,7 @@ process_inline() {
iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")"
iQUERY[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","last_name"]}")"
iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
# event_inline &
}
process_message() {
local num="$1"
@ -420,7 +421,21 @@ process_message() {
# Location
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
# event_message &
}
declare -A BASBOT_EVENT_INLINE BASBOT_EVENT_MESSAGE BASBOT_EVENT_REPLY BASBOT_EVENT_FORWARD BASBOT_EVENT_CONTACT BASBOT_EVENT_LOCATION BASBOT_EVENT_FILE
export BASBOT_EVENT_INLINE BASBOT_EVENT_MESSAGE BASBOT_EVENT_REPLY BASBOT_EVENT_FORWARD BASBOT_EVENT_CONTACT BASBOT_EVENT_LOCATION BASBOT_EVENT_FILE
# event_inline() {
#}
# event_message() {
# # ${REPLYTO[*]} event_reply
# # ${FORWARD[*]} event_forward
# # ${CONTACT[*]} event_contact
# # ${VENUE[*]} event_location
# # ${LOCALTION[*]} event_location
# # ${URL[*]} event_file
#}
#########################

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -3,7 +3,7 @@
#
# works together with git pre-push.sh and ADD all changed files since last push
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -2,7 +2,7 @@
# file: make-distribution.sh
# creates files and arcchives to dirtribute bashbot
#
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
@ -36,11 +36,14 @@ mkdir -p "${DISTDIR}" 2>/dev/null
cp -r ${DISTFILES} "${DISTDIR}"
cd "${DISTDIR}" || exit 1
# additional stuff
mv "bashbot.rc" "bashbot.rc.dist"
# mv "commands.sh" "commands.sh.dist" # will be overwritten from v0.80 on
mv "mycommands.sh" "mycommands.sh.dist"
# do not overwrite on update
for file in mycommands.sh bashbot.rc addons/*.sh
do
[ "${file}" = "addons/*.sh" ] && continue
mv "${file}" "${file}.dist"
done
# dwonload JSON.sh
JSONSHFILE="JSON.sh/JSON.sh"
if [ ! -f "${JSONSHFILE}" ]; then
mkdir "JSON.sh" 2>/dev/null

View File

@ -5,7 +5,7 @@
# If you your bot is finished you can use make-standalone.sh to create the
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
#
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,3 +1,3 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
bashbot.rc

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v0.80-18-g6b88656
#### $$VERSION$$ v0.80-26-g9f74bcf
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -1,64 +1,64 @@
chat:123456 JSON:"text":"# test for text only output"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"This is a normal text"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"This is a normal text
with a line break"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":" This is a <b>HTML</b> text","parse_mode":"html"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":" This is a <b>HTML</b> text
with a line break","parse_mode":"html"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":" This is a *MARKDOWN* text
with a line break","parse_mode":"markdown"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"# test for keyboard, file, venue output"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true}
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"latitude": la10, "longitude": lo20
URL:https://api.telegram.org/botbashbottestscript/sendLocation
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendLocation
chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home"
URL:https://api.telegram.org/botbashbottestscript/sendVenue
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendVenue
chat:123456 JSON:"text":"# test for new inline button"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]}
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"STABILO 88/240 Fineliner point 88
[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg]
second part of text
plus newline.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"text":"# test for sendfile"
URL:https://api.telegram.org/botbashbottestscript/sendMessage
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
chat:123456 JSON:"action": "upload_photo"
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendChatAction
chat:123456 JSON:"photo":"/tmp/allowed/this_is_my.gif","caption":"Text plus absolute file will appear in chat"
URL:https://api.telegram.org/botbashbottestscript/sendPhoto
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendPhoto
chat:123456 JSON:"action": "upload_document"
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendChatAction
chat:123456 JSON:"document":"/tmp/allowed/this_is_my.doc","caption":"Text plus absolute file will appear in chat"
URL:https://api.telegram.org/botbashbottestscript/sendDocument
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendDocument