mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
function download(), downloads URL to file in data-bot-bash
This commit is contained in:
parent
e5f7b2da50
commit
d34c22f156
16
bashbot.sh
16
bashbot.sh
@ -12,7 +12,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-pre-4-gd1a3372
|
||||
#### $$VERSION$$ v0.80-pre-5-ge5f7b2d
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -132,6 +132,20 @@ fi
|
||||
|
||||
|
||||
# internal functions
|
||||
# $1 URL, $2 filename in TMPDIR
|
||||
# outputs final filename
|
||||
download() {
|
||||
local empty="no.file" file="${2:-${empty}}"
|
||||
if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi
|
||||
while [ -f "${TMPDIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done
|
||||
getJson "$1" >"${TMPDIR:-.}/${file}" || return
|
||||
printf '%s\n' "${TMPDIR:-.}/${file}"
|
||||
}
|
||||
|
||||
# easy handling of users:
|
||||
_is_botadmin() {
|
||||
user_is_botadmin "${USER[ID]}"
|
||||
}
|
||||
# $1 postfix, e.g. chatid
|
||||
# $2 prefix, back- or startbot-
|
||||
procname(){
|
||||
|
@ -544,6 +544,20 @@ You must include ```source modules/aliases.sh``` in 'commands.sh' to have the f
|
||||
|
||||
### Helper functions
|
||||
|
||||
##### download
|
||||
Download the fiven URL ans returns the final filename in TMPDIR. If the given filename exists,the filename is prefixed with a
|
||||
random number. filename is not allowed to contain '/' or '..'.
|
||||
|
||||
*usage:* download URL filename
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")"
|
||||
echo "$file" -> ./data-bot-bash/avatar.jpg
|
||||
file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg")"
|
||||
echo "$file" -> ./data-bot-bash/12345-avatar.jpg
|
||||
```
|
||||
|
||||
##### _exists
|
||||
Returns true if the given function exist, can be used to check if a module is loaded.
|
||||
|
||||
@ -629,5 +643,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.80-pre-0-gdd7c66d
|
||||
#### $$VERSION$$ v0.80-pre-5-ge5f7b2d
|
||||
|
||||
|
@ -5,14 +5,10 @@
|
||||
# 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-pre-0-gdd7c66d
|
||||
#### $$VERSION$$ v0.80-pre-5-ge5f7b2d
|
||||
#
|
||||
# source from commands.sh to use the aliases
|
||||
|
||||
# easy handling of users:
|
||||
_is_botadmin() {
|
||||
user_is_botadmin "${USER[ID]}"
|
||||
}
|
||||
_is_admin() {
|
||||
user_is_admin "${CHAT[ID]}" "${USER[ID]}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user