dblista 0.3.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +10 -3
- data/dblista.gemspec +2 -0
- data/examples/auto_stats.rb +11 -0
- data/examples/bot_add.rb +26 -0
- data/examples/full_bot_name_list.rb +5 -0
- data/examples/notifications.rb +6 -0
- data/examples/tag_search.rb +5 -0
- data/examples/user_avatar.rb +5 -0
- data/lib/dblista.rb +11 -2
- data/lib/dblista/constants.rb +29 -1
- data/lib/dblista/info.rb +9 -3
- data/lib/dblista/list/bot.rb +19 -7
- data/lib/dblista/list/server.rb +12 -4
- data/lib/dblista/stats.rb +2 -1
- data/lib/dblista/user/actions.rb +68 -50
- data/lib/dblista/user/boosting.rb +22 -22
- data/lib/dblista/user/client.rb +13 -4
- data/lib/dblista/user/info.rb +20 -0
- data/lib/dblista/user/notifications.rb +42 -42
- data/lib/dblista/user/rating.rb +65 -30
- data/lib/dblista/user/verification.rb +29 -29
- data/lib/dblista/user/voting.rb +11 -11
- data/lib/dblista/version.rb +1 -1
- metadata +23 -3
- data/example/info.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da619767906bab1f464fbac5de79c8d511b4aba91e29f6610df0e946808c2324
|
4
|
+
data.tar.gz: 017cb53f927e7d792fd05abfcf816dbe865b8754755e27f564b7bb19cf5953e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414b7641847d8f459d162fe5bed6934f294b7281b2f696074f978c27ce7909b8e360be0beeb8c9628f527b661fb04306f7c8986222e9bf6d27af8a668e442191
|
7
|
+
data.tar.gz: a1928a8603ac4abd09e5b924b986ac5cd73578db9edb752793debc727f51de14ddeabaa243270d2b8a66b436db5e127c91944b5159a4ad0f92c6834451d5c25f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dblista (0.
|
4
|
+
dblista (0.6.0)
|
5
|
+
zache
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -21,6 +22,7 @@ GEM
|
|
21
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
23
|
rspec-support (~> 3.9.0)
|
23
24
|
rspec-support (3.9.3)
|
25
|
+
zache (0.12.0)
|
24
26
|
|
25
27
|
PLATFORMS
|
26
28
|
x86-mingw32
|
data/README.md
CHANGED
@@ -2,7 +2,14 @@
|
|
2
2
|
|
3
3
|
[Dokumentacja](https://www.rubydoc.info/github/marek12306/dblista-wrapper-ruby)
|
4
4
|
|
5
|
-
Gem pozwalający na komunikację z API DBListy.
|
5
|
+
Gem pozwalający na komunikację z API DBListy.
|
6
|
+
|
7
|
+
Pozwala na:
|
8
|
+
|
9
|
+
- Automatyczne/ręczne wysyłanie statystyk
|
10
|
+
- Kontrolowanie kontem użytkownika
|
11
|
+
- Pobieranie różnych list botów oraz serwerów oraz wyszukiwanie
|
12
|
+
- Pobieranie informacji o botach, serwerach oraz użytkownikach
|
6
13
|
|
7
14
|
## Instalacja
|
8
15
|
|
@@ -33,9 +40,9 @@ Pobieranie topki botów:
|
|
33
40
|
|
34
41
|
```ruby
|
35
42
|
top = DBLista::List::Bot.top
|
36
|
-
puts top
|
43
|
+
puts top
|
37
44
|
```
|
38
45
|
|
39
46
|
## Licencja
|
40
47
|
|
41
|
-
Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z
|
48
|
+
Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z tym co chcesz.
|
data/dblista.gemspec
CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
+
spec.add_dependency "zache"
|
28
|
+
|
27
29
|
spec.add_development_dependency "bundler", "~> 1.17"
|
28
30
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
29
31
|
spec.add_development_dependency "rspec", "~> 3.2"
|
data/examples/bot_add.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'dblista'
|
2
|
+
|
3
|
+
client = DBLista::User::Client.new('TOKEN')
|
4
|
+
|
5
|
+
client.add({
|
6
|
+
id: 'id',
|
7
|
+
info: {
|
8
|
+
library: 'NiceBot',
|
9
|
+
tags: [
|
10
|
+
DBLista::Tags::Bot::FUN,
|
11
|
+
DBLista::Tags::Bot::TOOLS
|
12
|
+
],
|
13
|
+
prefix: '!',
|
14
|
+
fullDescription: 'long description',
|
15
|
+
shortDescription: 'summary'
|
16
|
+
},
|
17
|
+
links: {
|
18
|
+
gitRepository: 'http://github.com/example/example',
|
19
|
+
website: 'http://example.com',
|
20
|
+
discordServer: 'discord server'
|
21
|
+
},
|
22
|
+
owners: [
|
23
|
+
'id 1',
|
24
|
+
'id 2'
|
25
|
+
]
|
26
|
+
})
|
data/lib/dblista.rb
CHANGED
@@ -4,6 +4,7 @@ require 'net/http'
|
|
4
4
|
require 'net/https'
|
5
5
|
require 'open-uri'
|
6
6
|
require 'json'
|
7
|
+
require 'zache'
|
7
8
|
|
8
9
|
require_relative 'dblista/version'
|
9
10
|
require_relative 'dblista/info'
|
@@ -24,6 +25,11 @@ module DBLista
|
|
24
25
|
# Regexp for checking if string is a number
|
25
26
|
IS_NUMBER = /^\d+$/.freeze
|
26
27
|
|
28
|
+
# Cache
|
29
|
+
Cache = Zache.new
|
30
|
+
# Cache entry lifetime
|
31
|
+
CACHE_LIFETIME = 15
|
32
|
+
|
27
33
|
def self._https(uri)
|
28
34
|
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
29
35
|
http.use_ssl = true
|
@@ -38,6 +44,7 @@ module DBLista
|
|
38
44
|
response = _https(uri).request(req)
|
39
45
|
result = JSON.parse response.body
|
40
46
|
raise DBLista::Error, result['error'].capitalize unless result['status'] == 'success'
|
47
|
+
|
41
48
|
result['data']
|
42
49
|
end
|
43
50
|
|
@@ -81,8 +88,10 @@ module DBLista
|
|
81
88
|
|
82
89
|
# @!visibility private
|
83
90
|
def self._limit_integer(input)
|
84
|
-
puts input
|
85
|
-
puts input.is_a?(Integer)
|
86
91
|
raise DBLista::Error, DBLista::Errors::LIMIT_INTEGER unless input.is_a?(Integer)
|
87
92
|
end
|
93
|
+
|
94
|
+
def self._cache(name)
|
95
|
+
DBLista::Cache.get(name.to_sym, lifetime: DBLista::CACHE_LIFETIME) { yield }
|
96
|
+
end
|
88
97
|
end
|
data/lib/dblista/constants.rb
CHANGED
@@ -35,6 +35,34 @@ module DBLista
|
|
35
35
|
USER = 0
|
36
36
|
MODERATOR = 1
|
37
37
|
BIG_MODERATOR = 2
|
38
|
-
ADMINISTRATOR =
|
38
|
+
ADMINISTRATOR = 10
|
39
|
+
end
|
40
|
+
# Bot libraries
|
41
|
+
module Libraries
|
42
|
+
DISCORD_JS = :'discord.js'
|
43
|
+
ERIS = :eris
|
44
|
+
DSHARP_PLUS = :DSharpPlus
|
45
|
+
DISCORD_NET = :'Discord.Net'
|
46
|
+
DISCORDGO = :DiscordGo
|
47
|
+
DISGORD = :DisGord
|
48
|
+
JDA = :JDA
|
49
|
+
DISCORD4J = :Discord4J
|
50
|
+
JAVACORD = :Javacord
|
51
|
+
AEGIS_CPP = :'aegis.cpp'
|
52
|
+
NYXX = :nyxx
|
53
|
+
RESTCORD = :RestCord
|
54
|
+
DISCORD_PY = :'discord.py'
|
55
|
+
DISCO = :disco
|
56
|
+
DISCORDRB = :discordrb
|
57
|
+
DISCORDRS = :'discord-rs'
|
58
|
+
SERENITY = :serenity
|
59
|
+
INNA = :inna
|
60
|
+
end
|
61
|
+
# Card style
|
62
|
+
module CardStyle
|
63
|
+
GREEN = :green
|
64
|
+
ORANGE = :orange
|
65
|
+
PINK = :pink
|
66
|
+
BLUE = :blue
|
39
67
|
end
|
40
68
|
end
|
data/lib/dblista/info.rb
CHANGED
@@ -16,7 +16,9 @@ module DBLista
|
|
16
16
|
# @return [Hash] raw data from DBLista
|
17
17
|
def self.bot(id)
|
18
18
|
DBLista._validate_id id
|
19
|
-
DBLista.
|
19
|
+
DBLista._cache(id.to_s.to_sym) do
|
20
|
+
DBLista._get("/bots/#{id}")
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
# Fetches DBLista server information
|
@@ -25,7 +27,9 @@ module DBLista
|
|
25
27
|
# @return [Hash] raw data from DBLista
|
26
28
|
def self.server(id)
|
27
29
|
DBLista._validate_id id
|
28
|
-
DBLista.
|
30
|
+
DBLista._cache(id.to_s.to_sym) do
|
31
|
+
DBLista._get("/servers/#{id}")
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
# Fetches DBLista user information
|
@@ -34,7 +38,9 @@ module DBLista
|
|
34
38
|
# @return [Hash] raw data from DBLista
|
35
39
|
def self.user(id)
|
36
40
|
DBLista._validate_id id
|
37
|
-
DBLista.
|
41
|
+
DBLista._cache(id.to_s.to_sym) do
|
42
|
+
DBLista._get("/users/#{id}")
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
data/lib/dblista/list/bot.rb
CHANGED
@@ -8,7 +8,7 @@ require 'cgi'
|
|
8
8
|
#
|
9
9
|
# @example Fetch top 25 bots
|
10
10
|
# top = DBLista::List::Bot.top
|
11
|
-
# puts top
|
11
|
+
# puts top
|
12
12
|
module DBLista::List
|
13
13
|
# Bot lists
|
14
14
|
module Bot
|
@@ -20,7 +20,9 @@ module DBLista::List
|
|
20
20
|
def self.top(page = 0, limit = 10)
|
21
21
|
DBLista._page_integer page
|
22
22
|
DBLista._limit_integer limit
|
23
|
-
DBLista.
|
23
|
+
DBLista._cache("botstop#{page}-#{limit}") do
|
24
|
+
DBLista._get("/bots/list/top/#{page}?limit=#{limit}")
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
# Fetches premium bots
|
@@ -31,28 +33,36 @@ module DBLista::List
|
|
31
33
|
def self.premium(page = 0, limit = 10)
|
32
34
|
DBLista._page_integer page
|
33
35
|
DBLista._limit_integer limit
|
34
|
-
DBLista.
|
36
|
+
DBLista._cache("botspremium#{page}-#{limit}") do
|
37
|
+
DBLista._get("/bots/list/premium/#{page}?limit=#{limit}")
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# Fetches unverified bots
|
38
42
|
#
|
39
43
|
# @return [Hash] raw data from DBLista
|
40
44
|
def self.unverified
|
41
|
-
DBLista.
|
45
|
+
DBLista._cache(:botsunverified) do
|
46
|
+
DBLista._get('/bots/list/unverified')
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
# Fetches rejected bots
|
45
51
|
#
|
46
52
|
# @return [Hash] raw data from DBLista
|
47
53
|
def self.rejected
|
48
|
-
DBLista.
|
54
|
+
DBLista._cache(:botsrejected) do
|
55
|
+
DBLista._get('/bots/list/rejected')
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
# Fetches all bots
|
52
60
|
#
|
53
61
|
# @return [Array] array of raw bot data from DBLista
|
54
62
|
def self.all
|
55
|
-
DBLista
|
63
|
+
DBLista._cache(:botsall) do
|
64
|
+
DBLista._get('/bots/list/top/0?limit=1000000')
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
# Bot search
|
@@ -62,7 +72,9 @@ module DBLista::List
|
|
62
72
|
def self.search(query)
|
63
73
|
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
64
74
|
|
65
|
-
DBLista.
|
75
|
+
DBLista._cache("botsearch#{query}") do
|
76
|
+
DBLista._get("/bots/search/#{CGI.escape query.to_s}")
|
77
|
+
end
|
66
78
|
end
|
67
79
|
end
|
68
80
|
end
|
data/lib/dblista/list/server.rb
CHANGED
@@ -13,7 +13,9 @@ module DBLista::List
|
|
13
13
|
def self.top(page = 0, limit = 10)
|
14
14
|
DBLista._page_integer page
|
15
15
|
DBLista._limit_integer limit
|
16
|
-
DBLista.
|
16
|
+
DBLista._cache("serverstop#{page}-#{limit}") do
|
17
|
+
DBLista._get("/servers/list/top/#{page}?limit=#{limit}")
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
# Fetches premium servers
|
@@ -24,14 +26,18 @@ module DBLista::List
|
|
24
26
|
def self.premium(page = 0, limit = 10)
|
25
27
|
DBLista._page_integer page
|
26
28
|
DBLista._limit_integer limit
|
27
|
-
DBLista.
|
29
|
+
DBLista._cache("serverspremium#{page}-#{limit}") do
|
30
|
+
DBLista._get("/servers/list/premium/#{page}?limit=#{limit}")
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
# Fetches all servers
|
31
35
|
#
|
32
36
|
# @return [Array] array of raw server data from DBLista
|
33
37
|
def self.all
|
34
|
-
DBLista
|
38
|
+
DBLista._cache(:serversall) do
|
39
|
+
DBLista._get('/servers/list/top/0?limit=1000000')
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
# Server search
|
@@ -41,7 +47,9 @@ module DBLista::List
|
|
41
47
|
def self.search(query)
|
42
48
|
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
43
49
|
|
44
|
-
DBLista.
|
50
|
+
DBLista._cache("serversearch#{query}") do
|
51
|
+
DBLista._get("/servers/search/#{CGI.escape query.to_s}")
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
47
55
|
end
|
data/lib/dblista/stats.rb
CHANGED
@@ -42,12 +42,13 @@ module DBLista
|
|
42
42
|
#
|
43
43
|
# @param members [Integer] member count
|
44
44
|
# @param servers [Integer] server count
|
45
|
-
# @return [
|
45
|
+
# @return [Boolean] true if operation succeded
|
46
46
|
def update_stats(members, servers)
|
47
47
|
DBLista._post('/bots/stats', {
|
48
48
|
'servers' => servers,
|
49
49
|
'members' => members
|
50
50
|
}, @token)
|
51
|
+
true
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
data/lib/dblista/user/actions.rb
CHANGED
@@ -5,58 +5,76 @@ require 'json'
|
|
5
5
|
module DBLista::User
|
6
6
|
# User client - actions
|
7
7
|
module Actions
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
DBLista._post("/#{type}s", body, @token)
|
18
|
-
true
|
19
|
-
end
|
8
|
+
# Adds bot/server to DBLista
|
9
|
+
#
|
10
|
+
# @param body [Hash] raw body to send
|
11
|
+
# @param type [Symbol] type of entity (bot/server)
|
12
|
+
# @return [Boolean] true if operation succeded
|
13
|
+
def add(body, type = 'bot')
|
14
|
+
raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
|
15
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# @param type [Symbol] type of entity (bot/server)
|
25
|
-
# @return [Boolean] true if operation succeded
|
26
|
-
def edit(body, type = :bot)
|
27
|
-
raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
|
28
|
-
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
29
|
-
|
30
|
-
DBLista._put("/#{type}s", body, @token)
|
31
|
-
true
|
32
|
-
end
|
17
|
+
DBLista._post("/#{type}s", body, @token)
|
18
|
+
true
|
19
|
+
end
|
33
20
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
DBLista._delete("/#{type}s/#{id}", nil, @token)
|
44
|
-
true
|
45
|
-
end
|
21
|
+
# Edits bot/server in DBLista
|
22
|
+
#
|
23
|
+
# @param body [Hash] raw body to send
|
24
|
+
# @param type [Symbol] type of entity (bot/server)
|
25
|
+
# @return [Boolean] true if operation succeded
|
26
|
+
def edit(body, type = :bot)
|
27
|
+
raise DBLista::Error, DBLista::Errors::BODY_HASH unless body.is_a?(Hash)
|
28
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
46
29
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
30
|
+
DBLista._put("/#{type}s", body, @token)
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
# Deletes bot/server from DBLista
|
35
|
+
#
|
36
|
+
# @param id [Integer] entity ID
|
37
|
+
# @param type [Symbol] type of entity (bot/server)
|
38
|
+
# @return [Boolean] true if operation succeded
|
39
|
+
def delete(id, type = :bot)
|
40
|
+
DBLista._validate_id id
|
41
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
42
|
+
|
43
|
+
DBLista._delete("/#{type}s/#{id}", nil, @token)
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
# Manages user (bans or adds premium)
|
48
|
+
# Available only for DBLista staff
|
49
|
+
#
|
50
|
+
# @param id [Integer] user ID
|
51
|
+
# @param banned [Boolean] user ban status
|
52
|
+
# @param premium [Integer] days for premium
|
53
|
+
# @return [Boolean] true if operation succeded
|
54
|
+
def manage_user(id, banned = false, premium = 0)
|
55
|
+
DBLista._post("/users/#{id}/manage", {
|
56
|
+
premium: premium,
|
57
|
+
ban: banned
|
58
|
+
}, @token)
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
# Generates token for bot
|
63
|
+
#
|
64
|
+
# @param id [Integer] bot ID
|
65
|
+
# @return [Hash] raw data from DBLista
|
66
|
+
def generate_token(id)
|
67
|
+
DBLista._validate_id id
|
68
|
+
DBLista._get("/bots/stats/#{id}?token=#{@token}")
|
69
|
+
end
|
70
|
+
|
71
|
+
# Resets token for bot
|
72
|
+
#
|
73
|
+
# @param id [Integer] bot ID
|
74
|
+
# @return [Hash] raw data from DBLista
|
75
|
+
def reset_token(id)
|
76
|
+
DBLista._validate_id id
|
77
|
+
DBLista._post("/bots/stats/#{id}/reset", nil, @token)
|
78
|
+
end
|
61
79
|
end
|
62
80
|
end
|
@@ -3,30 +3,30 @@
|
|
3
3
|
module DBLista::User
|
4
4
|
# User client - boosting
|
5
5
|
module Boosting
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
# Boosts selected bot/server
|
7
|
+
#
|
8
|
+
# @param id [Integer] entity ID
|
9
|
+
# @param type [Symbol] type of entity (bot/server)
|
10
|
+
# @return [Boolean] true if operation succeded
|
11
|
+
def boost(id, type = :bot)
|
12
|
+
DBLista._validate_id id
|
13
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
DBLista._post("/#{type}s/#{id}/boost", nil, @token)
|
16
|
+
true
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
# Removes boost from a selected bot/server
|
20
|
+
#
|
21
|
+
# @param id [Integer] entity ID
|
22
|
+
# @param type [Symbol] type of entity (bot/server)
|
23
|
+
# @return [Boolean] true if operation succeded
|
24
|
+
def delete_boost(id, type = :bot)
|
25
|
+
DBLista._validate_id id
|
26
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
DBLista._delete("/#{type}s/#{id}/boost", nil, @token)
|
29
|
+
true
|
30
|
+
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/dblista/user/client.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'zache'
|
4
|
+
|
3
5
|
require_relative './actions'
|
4
6
|
require_relative './boosting'
|
5
7
|
require_relative './rating'
|
6
8
|
require_relative './voting'
|
7
9
|
require_relative './notifications'
|
8
10
|
require_relative './verification'
|
11
|
+
require_relative './info'
|
9
12
|
|
10
13
|
# User module - client + client modules
|
11
14
|
module DBLista::User
|
@@ -13,11 +16,11 @@ module DBLista::User
|
|
13
16
|
#
|
14
17
|
# @example Server voting
|
15
18
|
# client = DBLista::User::Client.new "USER_TOKEN"
|
16
|
-
#
|
19
|
+
# client.vote(123456789012345678, :server)
|
17
20
|
#
|
18
21
|
# @example Bot rating
|
19
22
|
# client = DBLista::User::Client.new "USER_TOKEN"
|
20
|
-
#
|
23
|
+
# client.rate(123456789012345678, 5, 'Nice bot')
|
21
24
|
class Client
|
22
25
|
include DBLista::User::Voting
|
23
26
|
include DBLista::User::Actions
|
@@ -25,6 +28,7 @@ module DBLista::User
|
|
25
28
|
include DBLista::User::Rating
|
26
29
|
include DBLista::User::Notifications
|
27
30
|
include DBLista::User::Verification
|
31
|
+
include DBLista::User::Information
|
28
32
|
|
29
33
|
# Allowed entity types to use
|
30
34
|
ALLOWED_TYPES = %i[bot server].freeze
|
@@ -35,6 +39,7 @@ module DBLista::User
|
|
35
39
|
raise DBLista::Error, DBLista::Errors::TOKEN_NOT_PROVIDED unless token
|
36
40
|
|
37
41
|
@token = token
|
42
|
+
@cache = Zache.new
|
38
43
|
|
39
44
|
me
|
40
45
|
end
|
@@ -43,14 +48,18 @@ module DBLista::User
|
|
43
48
|
#
|
44
49
|
# @return [Hash] raw data from DBLista
|
45
50
|
def me
|
46
|
-
|
51
|
+
@cache.get(:guilds, lifetime: DBLista::CACHE_LIFETIME) do
|
52
|
+
DBLista._get('/users/me', @token)
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
# Fetches current user guilds
|
50
57
|
#
|
51
58
|
# @return [Hash] raw data from DBLista
|
52
59
|
def guilds
|
53
|
-
|
60
|
+
@cache.get(:guilds, lifetime: DBLista::CACHE_LIFETIME) do
|
61
|
+
DBLista._get('/users/me/guilds', @token)
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
56
65
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DBLista::User
|
4
|
+
# User client - information
|
5
|
+
module Information
|
6
|
+
# Fetches your servers
|
7
|
+
#
|
8
|
+
# @return [Hash] raw data from DBLista
|
9
|
+
def servers
|
10
|
+
DBLista._get('/servers/user/me', nil, @token)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fetches your bots
|
14
|
+
#
|
15
|
+
# @return [Hash] raw data from DBLista
|
16
|
+
def bots
|
17
|
+
DBLista._get('/bots/user/me', nil, @token)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,50 +3,50 @@
|
|
3
3
|
module DBLista::User
|
4
4
|
# User client - notifications
|
5
5
|
module Notifications
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
# Fetches user notifications
|
7
|
+
#
|
8
|
+
# @return [Hash] raw data from DBLista
|
9
|
+
def notifications
|
10
|
+
DBLista._get('/users/me/notifications/read', @token)
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
# Clears user notifications
|
14
|
+
#
|
15
|
+
# @return [Boolean] true if operation succeded
|
16
|
+
def clear_notifications
|
17
|
+
DBLista._get('/users/me/notifications/clear', @token)
|
18
|
+
true
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
# Sends notification to specified user
|
22
|
+
# Available only for DBLista staff
|
23
|
+
#
|
24
|
+
# @param rank [Integer] user ID
|
25
|
+
# @param details [String] details (content)
|
26
|
+
# @param url [String] url to redirect if clicked
|
27
|
+
# @return [Boolean] true if operation succeded
|
28
|
+
def send_notification(id, details, url = '#')
|
29
|
+
DBLista._validate_id id
|
30
|
+
DBLista._post("/users/#{id}/notifications", {
|
31
|
+
text: details,
|
32
|
+
url: url || '#'
|
33
|
+
}, @token)
|
34
|
+
true
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
# Sends notification to specified group (rank)
|
38
|
+
# Available only for DBLista staff
|
39
|
+
#
|
40
|
+
# @param rank [Integer] rank ID
|
41
|
+
# @param details [String] details (content)
|
42
|
+
# @param url [String] url to redirect if clicked
|
43
|
+
# @return [Boolean] true if operation succeded
|
44
|
+
def send_group_notification(rank, details, url = '#')
|
45
|
+
DBLista._post("/users/group/#{rank}/notifications", {
|
46
|
+
text: details,
|
47
|
+
url: url || '#'
|
48
|
+
}, @token)
|
49
|
+
true
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
data/lib/dblista/user/rating.rb
CHANGED
@@ -3,36 +3,71 @@
|
|
3
3
|
module DBLista::User
|
4
4
|
# User client - rating
|
5
5
|
module Rating
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
DBLista._post("/#{type}s/#{id}/rate", {
|
18
|
-
rating: rating,
|
19
|
-
details: details
|
20
|
-
}, @token)
|
21
|
-
true
|
22
|
-
end
|
6
|
+
# Sends rate for a selected bot/server
|
7
|
+
#
|
8
|
+
# @param id [Integer] entity ID
|
9
|
+
# @param rating [Integer] rating from 0 to 5
|
10
|
+
# @param details [String] details (description)
|
11
|
+
# @param type [Symbol] type of entity (bot/server)
|
12
|
+
# @return [Boolean] true if operation succeded
|
13
|
+
def rate(id, rating, details, type = :bot)
|
14
|
+
DBLista._validate_id id
|
15
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
17
|
+
DBLista._post("/#{type}s/#{id}/rate", {
|
18
|
+
rating: rating,
|
19
|
+
details: details
|
20
|
+
}, @token)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
# Removes rate for a selected bot/server
|
25
|
+
#
|
26
|
+
# @param id [Integer] entity ID
|
27
|
+
# @param target_id [Integer] target user to remove rate from (for owners only)
|
28
|
+
# @param type [Symbol] type of entity (bot/server)
|
29
|
+
# @return [Boolean] true if operation succeded
|
30
|
+
def delete_rate(id, target_id = nil, type = :bot)
|
31
|
+
DBLista._validate_id id
|
32
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
33
|
+
|
34
|
+
DBLista._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Reports rate of a selected bot/server
|
39
|
+
#
|
40
|
+
# @param id [Integer] ID
|
41
|
+
# @param target_id [Integer] target user to remove rate from (for owners only)
|
42
|
+
# @param report_reason [String] reason of report (details)
|
43
|
+
# @param type [Symbol] type of entity (bot/server)
|
44
|
+
# @return [Boolean] true if operation succeded
|
45
|
+
def report_rate(id, rate_id, report_reason = 'Brak powodu', type = :bot)
|
46
|
+
DBLista._validate_id id
|
47
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
48
|
+
|
49
|
+
DBLista._post("/#{type}s/#{id}/ratings/#{rate_id}/report", {
|
50
|
+
reportReason: report_reason.to_s
|
51
|
+
}, @token)
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
# Fetches all rate reports
|
56
|
+
#
|
57
|
+
# @return [Hash] raw data from DBLista
|
58
|
+
def reports
|
59
|
+
DBLista._get('/reports')
|
60
|
+
end
|
61
|
+
|
62
|
+
# Deletes rate report
|
63
|
+
#
|
64
|
+
# @param id [Integer] report ID
|
65
|
+
# @return [Hash] raw data from DBLista
|
66
|
+
def delete_report(id, type = :bot)
|
67
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
68
|
+
|
69
|
+
DBLista._delete("/reports/#{id}", nil, @token)
|
70
|
+
true
|
71
|
+
end
|
37
72
|
end
|
38
73
|
end
|
@@ -5,39 +5,39 @@ require 'cgi'
|
|
5
5
|
module DBLista::User
|
6
6
|
# User client - verification (only for staff)
|
7
7
|
module Verification
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
# Approves specified bot
|
9
|
+
#
|
10
|
+
# @param id [Integer] bot ID
|
11
|
+
# @param reason [String] reason for approving
|
12
|
+
# @return [Boolean] true if operation succeded
|
13
|
+
def approve(id, reason = 'Brak powodu')
|
14
|
+
DBLista._validate_id id
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
DBLista._post("/bots/verify/#{id}/approve?reason=#{CGI.escape reason}", nil, @token)
|
17
|
+
true
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
# Rejects specified bot
|
21
|
+
#
|
22
|
+
# @param id [Integer] bot ID
|
23
|
+
# @param reason [String] reason for rejecting
|
24
|
+
# @return [Boolean] true if operation succeded
|
25
|
+
def reject(id, reason = 'Brak powodu')
|
26
|
+
DBLista._validate_id id
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
DBLista._post("/bots/verify/#{id}/reject?reason=#{CGI.escape reason}", nil, @token)
|
29
|
+
true
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
# Sets specified bot verification status to pending
|
33
|
+
#
|
34
|
+
# @param id [Integer] bot ID
|
35
|
+
# @return [Boolean] true if operation succeded
|
36
|
+
def set_pending(id)
|
37
|
+
DBLista._validate_id id
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
DBLista._post("/bots/#{id}/set-pending", nil, @token)
|
40
|
+
true
|
41
|
+
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/dblista/user/voting.rb
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
module DBLista::User
|
4
4
|
# User client - voting
|
5
5
|
module Voting
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
# Votes for a selected bot/server
|
7
|
+
#
|
8
|
+
# @param id [Integer] entity ID
|
9
|
+
# @param type [Symbol] type of entity (bot/server)
|
10
|
+
# @return [Boolean] true if operation succeded
|
11
|
+
def vote(id, type = :bot)
|
12
|
+
DBLista._validate_id id
|
13
|
+
raise DBLista::Error, DBLista::Errors::TYPE_NOT_ALLOWED unless DBLista::User::Client::ALLOWED_TYPES.include?(type)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
DBLista._post("/#{type}s/#{id}/vote", nil, @token)
|
16
|
+
true
|
17
|
+
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/dblista/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dblista
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- deepivin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zache
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,7 +82,12 @@ files:
|
|
68
82
|
- bin/console
|
69
83
|
- bin/setup
|
70
84
|
- dblista.gemspec
|
71
|
-
-
|
85
|
+
- examples/auto_stats.rb
|
86
|
+
- examples/bot_add.rb
|
87
|
+
- examples/full_bot_name_list.rb
|
88
|
+
- examples/notifications.rb
|
89
|
+
- examples/tag_search.rb
|
90
|
+
- examples/user_avatar.rb
|
72
91
|
- lib/dblista.rb
|
73
92
|
- lib/dblista/constants.rb
|
74
93
|
- lib/dblista/errors.rb
|
@@ -80,6 +99,7 @@ files:
|
|
80
99
|
- lib/dblista/user/actions.rb
|
81
100
|
- lib/dblista/user/boosting.rb
|
82
101
|
- lib/dblista/user/client.rb
|
102
|
+
- lib/dblista/user/info.rb
|
83
103
|
- lib/dblista/user/notifications.rb
|
84
104
|
- lib/dblista/user/rating.rb
|
85
105
|
- lib/dblista/user/verification.rb
|
data/example/info.rb
DELETED