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:]'` OS=`uname | tr '[:upper:]' '[:lower:]'`
VERSION=`cat shard.yml | grep -m 1 'version: ' | sed -e 's/version: //g'` VERSION=`cat shard.yml | grep -m 1 'version: ' | sed -e 's/version: //g'`
echo "Build $VERSION for `uname` `uname -m`" if [ "$1" = "all" ]
then
crystal build --progress --no-debug --release src/vk0nline.cr -o bin/vk0nline-$VERSION.$OS-$ARCH 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 name: vk0nline
version: 2.0.0 version: 2.0.1
authors: authors:
- Alexander Popov <iiiypuk@fastmail.fm> - Alexander Popov <iiiypuk@fastmail.fm>
targets: targets:
src: vk0nline:
main: src/vk0nline.cr main: src/vk0nline.cr
dependencies: dependencies:

View File

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