mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-31 01:10:50 +00:00
fix tests, start addon implementation
This commit is contained in:
parent
9f74bcfec4
commit
7bad01b258
41
addons/example.sh
Normal file
41
addons/example.sh
Normal 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]}*"
|
||||||
|
}
|
||||||
|
|
17
bashbot.sh
17
bashbot.sh
|
@ -11,7 +11,7 @@
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-18-g6b88656
|
#### $$VERSION$$ v0.80-26-g9f74bcf
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
|
@ -341,6 +341,7 @@ process_inline() {
|
||||||
iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")"
|
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[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","last_name"]}")"
|
||||||
iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
|
iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
|
||||||
|
# event_inline &
|
||||||
}
|
}
|
||||||
process_message() {
|
process_message() {
|
||||||
local num="$1"
|
local num="$1"
|
||||||
|
@ -420,7 +421,21 @@ process_message() {
|
||||||
# Location
|
# Location
|
||||||
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
|
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
|
||||||
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
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
|
||||||
|
#}
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# 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,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# works together with git pre-push.sh and ADD all changed files since last push
|
# 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,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/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!
|
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/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!
|
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# 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,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# file: make-distribution.sh
|
# file: make-distribution.sh
|
||||||
# creates files and arcchives to dirtribute bashbot
|
# 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,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -36,11 +36,14 @@ mkdir -p "${DISTDIR}" 2>/dev/null
|
||||||
cp -r ${DISTFILES} "${DISTDIR}"
|
cp -r ${DISTFILES} "${DISTDIR}"
|
||||||
cd "${DISTDIR}" || exit 1
|
cd "${DISTDIR}" || exit 1
|
||||||
|
|
||||||
# additional stuff
|
# do not overwrite on update
|
||||||
mv "bashbot.rc" "bashbot.rc.dist"
|
for file in mycommands.sh bashbot.rc addons/*.sh
|
||||||
# mv "commands.sh" "commands.sh.dist" # will be overwritten from v0.80 on
|
do
|
||||||
mv "mycommands.sh" "mycommands.sh.dist"
|
[ "${file}" = "addons/*.sh" ] && continue
|
||||||
|
mv "${file}" "${file}.dist"
|
||||||
|
done
|
||||||
|
|
||||||
|
# dwonload JSON.sh
|
||||||
JSONSHFILE="JSON.sh/JSON.sh"
|
JSONSHFILE="JSON.sh/JSON.sh"
|
||||||
if [ ! -f "${JSONSHFILE}" ]; then
|
if [ ! -f "${JSONSHFILE}" ]; then
|
||||||
mkdir "JSON.sh" 2>/dev/null
|
mkdir "JSON.sh" 2>/dev/null
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# If you your bot is finished you can use make-standalone.sh to create the
|
# 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!
|
# 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,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# list of additional files to check from shellcheck
|
# list of additional files to check from shellcheck
|
||||||
#### $$VERSION$$ v0.80-18-g6b88656
|
#### $$VERSION$$ v0.80-26-g9f74bcf
|
||||||
bashbot.rc
|
bashbot.rc
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-18-g6b88656
|
#### $$VERSION$$ v0.80-26-g9f74bcf
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
#
|
#
|
||||||
# Easy Versioning in git:
|
# Easy Versioning in git:
|
||||||
|
|
|
@ -1,64 +1,64 @@
|
||||||
chat:123456 JSON:"text":"# test for text only output"
|
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"
|
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
|
chat:123456 JSON:"text":"This is a normal text
|
||||||
with a line break"
|
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"
|
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
|
chat:123456 JSON:"text":" This is a <b>HTML</b> text
|
||||||
with a line break","parse_mode":"html"
|
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"
|
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
|
chat:123456 JSON:"text":" This is a *MARKDOWN* text
|
||||||
with a line break","parse_mode":"markdown"
|
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"
|
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}
|
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
|
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"
|
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"
|
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..."}] ]}
|
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
|
chat:123456 JSON:"text":"STABILO 88/240 Fineliner point 88
|
||||||
|
|
||||||
[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg]
|
[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg]
|
||||||
second part of text
|
second part of text
|
||||||
plus newline.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
|
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"
|
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"
|
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"
|
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"
|
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"
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user