Compare commits
3 Commits
228484de6f
...
4b2d6fcabb
Author | SHA1 | Date |
---|---|---|
Nick Chambers | 4b2d6fcabb | |
Nick Chambers | a39c3ce06a | |
Nick Chambers | 474ba22817 |
45
rowbot
45
rowbot
|
@ -80,7 +80,7 @@ is_chan() {
|
|||
[[ ${msg_args[0]:0:1} = \# ]]
|
||||
}
|
||||
|
||||
# cryptography secure (almost probably) random number generators
|
||||
# cryptographically secure (almost maybe) pseudo random number utilities
|
||||
|
||||
random() {
|
||||
local min=$1 max=$2
|
||||
|
@ -97,6 +97,18 @@ any_file() {
|
|||
fi
|
||||
}
|
||||
|
||||
shuffle() {
|
||||
local idx=0 spot tmp
|
||||
declare -n rowbot_array=$1
|
||||
|
||||
for (( ; idx < ${#rowbot_array[@]}; idx += 1 )); do
|
||||
spot=$(random 0 "${#rowbot_array[@]}")
|
||||
tmp=${rowbot_array[$idx]}
|
||||
rowbot_array[$idx]=${rowbot_array[$spot]}
|
||||
rowbot_array[$spot]=$tmp
|
||||
done
|
||||
}
|
||||
|
||||
# misc
|
||||
|
||||
is_running () {
|
||||
|
@ -137,6 +149,17 @@ run_callbacks() {
|
|||
return "$status"
|
||||
}
|
||||
|
||||
prints() {
|
||||
# This is a wrapper around printf so the format string isn't known ahead of
|
||||
# time.
|
||||
# shellcheck disable=SC2059
|
||||
printf "$@"
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
printf \\n
|
||||
fi
|
||||
}
|
||||
|
||||
# The variables are checked dynamically
|
||||
# shellcheck disable=SC2034
|
||||
seconds() {
|
||||
|
@ -160,11 +183,7 @@ seconds() {
|
|||
fi
|
||||
done
|
||||
|
||||
printf -- %s "$time"
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
printf \\n
|
||||
fi
|
||||
prints %s "$time"
|
||||
}
|
||||
|
||||
url() {
|
||||
|
@ -174,11 +193,7 @@ url() {
|
|||
printf ircs://
|
||||
fi
|
||||
|
||||
printf %s:%s "${config[server]}" "${config[port]}"
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
printf \\n
|
||||
fi
|
||||
prints %s:%s "${config[server]}" "${config[port]}"
|
||||
}
|
||||
|
||||
b64_encode() {
|
||||
|
@ -194,19 +209,19 @@ b64_encode() {
|
|||
(( table_idxs[1] = (((numerics[0] & 0x03) << 6) | (numerics[1] & 0xF0) >> 2) >> 2 ))
|
||||
(( table_idxs[2] = (((numerics[1] & 0x0F) << 4) | (numerics[2] & 0xC0) >> 4) >> 2 ))
|
||||
(( table_idxs[3] = numerics[2] & 0x3F ))
|
||||
|
||||
for table_idx in "${table_idxs[@]}"; do
|
||||
encoded+=${table[$table_idx]}
|
||||
done
|
||||
done
|
||||
|
||||
if (( ${#1} % 3 == 1 )); then
|
||||
encoded=${encoded::-2}==
|
||||
elif (( ${#1} % 3 == 2 )); then
|
||||
encoded=${encoded::-1}=
|
||||
fi
|
||||
printf %s "$encoded"
|
||||
if [[ -t 1 ]]; then
|
||||
printf \\n
|
||||
fi
|
||||
|
||||
prints %s "$encoded"
|
||||
}
|
||||
|
||||
###
|
||||
|
|
Loading…
Reference in New Issue