add color output

This commit is contained in:
Alexander Popov 2022-05-16 21:18:04 +03:00
parent 2f9c1ad76c
commit 99331d966b
Signed by: iiiypuk
GPG Key ID: 3F76816AEE08F908
4 changed files with 35 additions and 21 deletions

10
HISTORY.md Normal file
View File

@ -0,0 +1,10 @@
## Legend
- 🐛 - Bug
- ✔️ - Fixed
- ❌ - Removed
- - Added
- - Information
- ♻️ - Edited
## 2.0.1 - [16/05/2022]
- - Added colors to output

View File

@ -9,7 +9,10 @@ ARCH=`uname -m`
OS=`uname | tr '[:upper:]' '[:lower:]'`
VERSION=`cat shard.yml | grep -m 1 'version: ' | sed -e 's/version: //g'`
echo "Build $VERSION for `uname` `uname -m`"
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline-$VERSION.$OS-$ARCH
if [ "$1" = "all" ]
then
echo "..in progress.."
else
echo "Build $VERSION for `uname` `uname -m`"
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline-$VERSION.$OS-$ARCH
fi

View File

@ -1,11 +1,11 @@
name: vk0nline
version: 2.0.0
version: 2.0.1
authors:
- Alexander Popov <iiiypuk@fastmail.fm>
targets:
src:
vk0nline:
main: src/vk0nline.cr
dependencies:

View File

@ -1,4 +1,5 @@
require "json"
require "colorize"
require "crest"
begin # JSON::ParseException
@ -6,19 +7,19 @@ begin # JSON::ParseException
JSON.parse(file)
end
rescue
puts "Parse config.json error"
puts "Parse config.json error".colorize(:red)
exit
end
def get_access_token(app_id : Int32)
puts "Open this page, and save token to config.json\n\n"
puts "Open this page, and save token to config.json:".colorize(:yellow)
token_url = "https://oauth.vk.com/authorize?client_id="\
"#{app_id}&redirect_uri=vk.com&response_type=token"\
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
token_url = "https://oauth.vk.com/authorize?client_id=" \
"#{app_id}&redirect_uri=vk.com&response_type=token" \
"&display=mobile&v=5.131&revoke=1&state=01010&scope=offline"
puts token_url
puts token_url.colorize(:green).mode(:bold)
end
if json["accessToken"] == nil
@ -26,29 +27,29 @@ if json["accessToken"] == nil
else
response = Crest.get(
"https://api.vk.com/method/account.setOnline",
params: { :voip => "0", :v => "5.131",
:access_token => json["accessToken"].as_s,
:user_ids => json["userIds"].as_i }
params: {:voip => "0", :v => "5.131",
:access_token => json["accessToken"].as_s,
:user_ids => json["userIds"].as_i}
)
status = JSON.parse(response.body)
begin # Missing hash key
if status["error"]
puts status["error"]["error_msg"]
puts "Error code #{status["error"]["error_code"]}"
puts status["error"]["error_msg"].colorize(:yellow).mode(:bold)
puts "Error code #{status["error"]["error_code"]}".colorize(:red)
puts "---"
puts "---".colorize(:dark_gray)
get_access_token(json["appID"].as_i)
end
rescue
# execute if an exception is raised
rescue
# execute if an exception is raised
end
begin # Status set
if status["response"] == 1
puts "Complete!"
puts "Complete!".colorize(:green).mode(:bold)
end
rescue
# execute if an exception is raised