Compare commits
4 Commits
d2517bb3f2
...
d31f591f52
Author | SHA1 | Date |
---|---|---|
Alexander Popov | d31f591f52 | |
Alexander Popov | 5511a355d4 | |
Alexander Popov | 99331d966b | |
Alexander Popov | 2f9c1ad76c |
|
@ -1,5 +0,0 @@
|
|||
language: crystal
|
||||
install:
|
||||
- shards install
|
||||
script:
|
||||
- crystal bin/ameba.cr
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
# Будь __ОНЛАЙН__ в контакте.
|
||||
# Будь **ОНЛАЙН** ВКонтакте
|
||||
|
||||
## Установка
|
||||
|
||||
|
|
11
build.sh
11
build.sh
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue