Compare commits

...

4 Commits

Author SHA1 Message Date
Alexander Popov d31f591f52
added mkconfig 2022-05-16 22:58:59 +03:00
Alexander Popov 5511a355d4
add help 2022-05-16 22:43:32 +03:00
Alexander Popov 99331d966b
add color output 2022-05-16 21:18:04 +03:00
Alexander Popov 2f9c1ad76c
update 3party libs 2022-05-16 20:55:40 +03:00
7 changed files with 78 additions and 33 deletions

View File

@ -1,5 +0,0 @@
language: crystal
install:
- shards install
script:
- crystal bin/ameba.cr

12
HISTORY.md Normal file
View File

@ -0,0 +1,12 @@
## Legend
- 🐛 - Bug
- ✔️ - Fixed
- ❌ - Removed
- - Added
- - Information
- ♻️ - Edited
## 2.0.1 - [16/05/2022]
- - Added colors to output
- - Added help
- - Added `--mkconfig` param to make new config file

View File

@ -1,4 +1,4 @@
# Будь __ОНЛАЙН__ в контакте.
# Будь **ОНЛАЙН** ВКонтакте
## Установка

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

@ -2,11 +2,11 @@ version: 2.0
shards:
ameba:
git: https://github.com/crystal-ameba/ameba.git
version: 0.13.4
version: 1.0.0
crest:
git: https://github.com/mamantoha/crest.git
version: 0.27.0
version: 1.2.1
http-client-digest_auth:
git: https://github.com/mamantoha/http-client-digest_auth.git
@ -14,5 +14,5 @@ shards:
http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.8.0
version: 0.9.0

View File

@ -1,11 +1,11 @@
name: vk0nline
version: 2.0.0
version: 2.0.1
authors:
- Alexander Popov <iiiypuk@iiiypuk.me>
- Alexander Popov <iiiypuk@fastmail.fm>
targets:
src:
vk0nline:
main: src/vk0nline.cr
dependencies:
@ -15,8 +15,7 @@ dependencies:
development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 0.13.0
crystal: 1.1.1
crystal: 1.4.1
license: MIT

View File

@ -1,24 +1,60 @@
require "option_parser"
require "json"
require "colorize"
require "crest"
# program options
begin
OptionParser.parse do |parser|
parser.banner = "Make ONLINE on vk.com\n"
parser.on "--version", "Show version" do
print "vk0nline ".colorize(:green).mode(:bold)
puts "2.0.1".colorize(:yellow)
exit(0)
end
parser.on "--mkconfig", "Make new empty config" do
new_config = {appID: nil, userIds: nil, accessToken: nil}
File.open("config.json.new", "w") do |f|
f.puts new_config.to_json.to_s
end
print "Config saved to "
print "config.json.new".colorize(:yellow).mode(:bold)
puts " file."
exit(0)
end
parser.on "-h", "--help", "Show help" do
puts parser
exit(0)
end
end
rescue ex
puts ex.message, ""
end
begin # JSON::ParseException
json = File.open("config.json") do |file|
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 +62,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