dblista 0.2.0 → 0.4.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 +2 -2
- 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 +17 -0
- data/lib/dblista/constants.rb +68 -0
- data/lib/dblista/errors.rb +2 -0
- data/lib/dblista/info.rb +9 -3
- data/lib/dblista/list/bot.rb +31 -8
- data/lib/dblista/list/server.rb +24 -5
- data/lib/dblista/stats.rb +2 -1
- data/lib/dblista/user/actions.rb +53 -49
- data/lib/dblista/user/boosting.rb +22 -20
- data/lib/dblista/user/client.rb +11 -4
- data/lib/dblista/user/notifications.rb +42 -39
- data/lib/dblista/user/rating.rb +28 -26
- data/lib/dblista/user/verification.rb +29 -29
- data/lib/dblista/user/voting.rb +11 -10
- 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: 20bc126654c09a9c27d1a5601a5fd6ca6f78d97b434c4c72d0f053b790a55bcf
|
4
|
+
data.tar.gz: b37f3e82284ca081f443422a5b2b1a34c2beafa3ae5233f5533e2b2ce557e87d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e8c060120beae4594c8b5e9faa0b81bbc29dbe08c4fb0f27a61afe7816092594dc5ef205565538599aa17a97352b53b853c256b5faa5dca68c6dcbce11c613d
|
7
|
+
data.tar.gz: 6992b4c8b78a17f307d2ed2c2225c5e333cee7630c9cbf485af5c661fc89b89348c595848a8ea205e0435136555a3dcbbf85cbca0505fce87d603126b2987073
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dblista (0.
|
4
|
+
dblista (0.4.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
@@ -33,9 +33,9 @@ Pobieranie topki botów:
|
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
top = DBLista::List::Bot.top
|
36
|
-
puts top
|
36
|
+
puts top
|
37
37
|
```
|
38
38
|
|
39
39
|
## Licencja
|
40
40
|
|
41
|
-
Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z
|
41
|
+
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'
|
@@ -13,6 +14,7 @@ require_relative 'dblista/list/bot'
|
|
13
14
|
require_relative 'dblista/list/server'
|
14
15
|
require_relative 'dblista/user/client'
|
15
16
|
require_relative 'dblista/helpers'
|
17
|
+
require_relative 'dblista/constants'
|
16
18
|
|
17
19
|
# Main module
|
18
20
|
module DBLista
|
@@ -23,6 +25,11 @@ module DBLista
|
|
23
25
|
# Regexp for checking if string is a number
|
24
26
|
IS_NUMBER = /^\d+$/.freeze
|
25
27
|
|
28
|
+
# Cache
|
29
|
+
Cache = Zache.new
|
30
|
+
# Cache entry lifetime
|
31
|
+
CACHE_LIFETIME = 15
|
32
|
+
|
26
33
|
def self._https(uri)
|
27
34
|
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
28
35
|
http.use_ssl = true
|
@@ -37,6 +44,7 @@ module DBLista
|
|
37
44
|
response = _https(uri).request(req)
|
38
45
|
result = JSON.parse response.body
|
39
46
|
raise DBLista::Error, result['error'].capitalize unless result['status'] == 'success'
|
47
|
+
|
40
48
|
result['data']
|
41
49
|
end
|
42
50
|
|
@@ -77,4 +85,13 @@ module DBLista
|
|
77
85
|
def self._page_integer(input)
|
78
86
|
raise DBLista::Error, DBLista::Errors::PAGE_INTEGER unless input.is_a?(Integer)
|
79
87
|
end
|
88
|
+
|
89
|
+
# @!visibility private
|
90
|
+
def self._limit_integer(input)
|
91
|
+
raise DBLista::Error, DBLista::Errors::LIMIT_INTEGER unless input.is_a?(Integer)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self._cache(name)
|
95
|
+
DBLista::Cache.get(name.to_sym, lifetime: DBLista::CACHE_LIFETIME) { yield }
|
96
|
+
end
|
80
97
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DBLista
|
4
|
+
# Tags
|
5
|
+
module Tags
|
6
|
+
# Bot tags
|
7
|
+
module Bot
|
8
|
+
MODERATION = :moderacja
|
9
|
+
TOOLS = :narzędzia
|
10
|
+
MUSIC = :muzyka
|
11
|
+
DASHBOARD = :panel
|
12
|
+
FUN = :rozrywka
|
13
|
+
LEVELS = :poziomy
|
14
|
+
GAMES = :gry
|
15
|
+
ROLEPLAY = :roleplay
|
16
|
+
ECONOMY = :ekonomia
|
17
|
+
ANIME = :anime
|
18
|
+
NSFW = :nsfw
|
19
|
+
OTHER = :inne
|
20
|
+
end
|
21
|
+
# Server tags
|
22
|
+
module Server
|
23
|
+
COMMUNITY = :community
|
24
|
+
PROGRAMMING = :programowanie
|
25
|
+
GAMES = :gry
|
26
|
+
YOUTUBE = :youtube
|
27
|
+
HOBBY = :hobby
|
28
|
+
ANIME = :anime
|
29
|
+
ROLEPLAY = :roleplay
|
30
|
+
OTHER = :inne
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# Permissions
|
34
|
+
module Permissions
|
35
|
+
USER = 0
|
36
|
+
MODERATOR = 1
|
37
|
+
BIG_MODERATOR = 2
|
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
|
67
|
+
end
|
68
|
+
end
|
data/lib/dblista/errors.rb
CHANGED
@@ -8,6 +8,8 @@ module DBLista::Errors
|
|
8
8
|
PAGE_INTEGER = 'Page must be an integer'
|
9
9
|
# Raised when rank is not an integer
|
10
10
|
RANK_INTEGER = 'Rank must be an integer'
|
11
|
+
# Raised when provided limit is not an integer
|
12
|
+
LIMIT_INTEGER = 'Limit must be an integer'
|
11
13
|
# Raised when token is not provided
|
12
14
|
TOKEN_NOT_PROVIDED = 'Token is not provided'
|
13
15
|
# Raised when type symbol is invalid
|
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,40 +8,61 @@ 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
|
15
15
|
# Fetches top bots
|
16
16
|
#
|
17
17
|
# @param page [Integer] page
|
18
|
+
# @param limit [Integer] limit of bots per page
|
18
19
|
# @return [Hash] raw data from DBLista
|
19
|
-
def self.top(page = 0)
|
20
|
+
def self.top(page = 0, limit = 10)
|
20
21
|
DBLista._page_integer page
|
21
|
-
DBLista.
|
22
|
+
DBLista._limit_integer limit
|
23
|
+
DBLista._cache("botstop#{page}-#{limit}") do
|
24
|
+
DBLista._get("/bots/list/top/#{page}?limit=#{limit}")
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
# Fetches premium bots
|
25
29
|
#
|
26
30
|
# @param page [Integer] page
|
31
|
+
# @param limit [Integer] limit of bots per page
|
27
32
|
# @return [Hash] raw data from DBLista
|
28
|
-
def self.premium(page = 0)
|
33
|
+
def self.premium(page = 0, limit = 10)
|
29
34
|
DBLista._page_integer page
|
30
|
-
DBLista.
|
35
|
+
DBLista._limit_integer limit
|
36
|
+
DBLista._cache("botspremium#{page}-#{limit}") do
|
37
|
+
DBLista._get("/bots/list/premium/#{page}?limit=#{limit}")
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
41
|
# Fetches unverified bots
|
34
42
|
#
|
35
43
|
# @return [Hash] raw data from DBLista
|
36
44
|
def self.unverified
|
37
|
-
DBLista.
|
45
|
+
DBLista._cache(:botsunverified) do
|
46
|
+
DBLista._get('/bots/list/unverified')
|
47
|
+
end
|
38
48
|
end
|
39
49
|
|
40
50
|
# Fetches rejected bots
|
41
51
|
#
|
42
52
|
# @return [Hash] raw data from DBLista
|
43
53
|
def self.rejected
|
44
|
-
DBLista.
|
54
|
+
DBLista._cache(:botsrejected) do
|
55
|
+
DBLista._get('/bots/list/rejected')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Fetches all bots
|
60
|
+
#
|
61
|
+
# @return [Array] array of raw bot data from DBLista
|
62
|
+
def self.all
|
63
|
+
DBLista._cache(:botsall) do
|
64
|
+
DBLista::List::Bot.top(0, 100_000_000)
|
65
|
+
end
|
45
66
|
end
|
46
67
|
|
47
68
|
# Bot search
|
@@ -51,7 +72,9 @@ module DBLista::List
|
|
51
72
|
def self.search(query)
|
52
73
|
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
53
74
|
|
54
|
-
DBLista.
|
75
|
+
DBLista._cache("botsearch#{query}") do
|
76
|
+
DBLista._get("/bots/search/#{CGI.escape query.to_s}")
|
77
|
+
end
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|
data/lib/dblista/list/server.rb
CHANGED
@@ -8,19 +8,36 @@ module DBLista::List
|
|
8
8
|
# Fetches top servers
|
9
9
|
#
|
10
10
|
# @param page [Integer] page
|
11
|
+
# @param limit [Integer] limit of servers per page
|
11
12
|
# @return [Hash] raw data from DBLista
|
12
|
-
def self.top(page = 0)
|
13
|
+
def self.top(page = 0, limit = 10)
|
13
14
|
DBLista._page_integer page
|
14
|
-
DBLista.
|
15
|
+
DBLista._limit_integer limit
|
16
|
+
DBLista._cache("serverstop#{page}-#{limit}") do
|
17
|
+
DBLista._get("/servers/list/top/#{page}?limit=#{limit}")
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
# Fetches premium servers
|
18
22
|
#
|
19
23
|
# @param page [Integer] page
|
24
|
+
# @param limit [Integer] limit of servers per page
|
20
25
|
# @return [Hash] raw data from DBLista
|
21
|
-
def self.premium(page = 0)
|
26
|
+
def self.premium(page = 0, limit = 10)
|
22
27
|
DBLista._page_integer page
|
23
|
-
DBLista.
|
28
|
+
DBLista._limit_integer limit
|
29
|
+
DBLista._cache("serverspremium#{page}-#{limit}") do
|
30
|
+
DBLista._get("/servers/list/premium/#{page}?limit=#{limit}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Fetches all servers
|
35
|
+
#
|
36
|
+
# @return [Array] array of raw server data from DBLista
|
37
|
+
def self.all
|
38
|
+
DBLista._cache(:serversall) do
|
39
|
+
DBLista::List::Server.top(0, 100_000_000)
|
40
|
+
end
|
24
41
|
end
|
25
42
|
|
26
43
|
# Server search
|
@@ -30,7 +47,9 @@ module DBLista::List
|
|
30
47
|
def self.search(query)
|
31
48
|
raise DBLista::Error, DBLista::Errors::QUERY_NOT_PROVIDED unless query
|
32
49
|
|
33
|
-
DBLista.
|
50
|
+
DBLista._cache("serversearch#{query}") do
|
51
|
+
DBLista._get("/servers/search/#{CGI.escape query.to_s}")
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
36
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,54 +5,58 @@ 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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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)
|
16
|
+
|
17
|
+
DBLista._post("/#{type}s", body, @token)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
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)
|
29
|
+
|
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
|
57
61
|
end
|
58
62
|
end
|
@@ -3,28 +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
|
-
|
15
|
+
DBLista._post("/#{type}s/#{id}/boost", nil, @token)
|
16
|
+
true
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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)
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
DBLista._delete("/#{type}s/#{id}/boost", nil, @token)
|
29
|
+
true
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/dblista/user/client.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
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'
|
@@ -13,11 +15,11 @@ module DBLista::User
|
|
13
15
|
#
|
14
16
|
# @example Server voting
|
15
17
|
# client = DBLista::User::Client.new "USER_TOKEN"
|
16
|
-
#
|
18
|
+
# client.vote(123456789012345678, :server)
|
17
19
|
#
|
18
20
|
# @example Bot rating
|
19
21
|
# client = DBLista::User::Client.new "USER_TOKEN"
|
20
|
-
#
|
22
|
+
# client.rate(123456789012345678, 5, 'Nice bot')
|
21
23
|
class Client
|
22
24
|
include DBLista::User::Voting
|
23
25
|
include DBLista::User::Actions
|
@@ -35,6 +37,7 @@ module DBLista::User
|
|
35
37
|
raise DBLista::Error, DBLista::Errors::TOKEN_NOT_PROVIDED unless token
|
36
38
|
|
37
39
|
@token = token
|
40
|
+
@cache = Zache.new
|
38
41
|
|
39
42
|
me
|
40
43
|
end
|
@@ -43,14 +46,18 @@ module DBLista::User
|
|
43
46
|
#
|
44
47
|
# @return [Hash] raw data from DBLista
|
45
48
|
def me
|
46
|
-
|
49
|
+
@cache.get(:guilds, lifetime: DBLista::CACHE_LIFETIME) do
|
50
|
+
DBLista._get('/users/me', @token)
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
# Fetches current user guilds
|
50
55
|
#
|
51
56
|
# @return [Hash] raw data from DBLista
|
52
57
|
def guilds
|
53
|
-
|
58
|
+
@cache.get(:guilds, lifetime: DBLista::CACHE_LIFETIME) do
|
59
|
+
DBLista._get('/users/me/guilds', @token)
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
@@ -3,47 +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
|
-
|
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
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
48
51
|
end
|
49
52
|
end
|
data/lib/dblista/user/rating.rb
CHANGED
@@ -3,34 +3,36 @@
|
|
3
3
|
module DBLista::User
|
4
4
|
# User client - rating
|
5
5
|
module Rating
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
DBLista._post("/#{type}s/#{id}/rate", {
|
18
|
+
rating: rating,
|
19
|
+
details: details
|
20
|
+
}, @token)
|
21
|
+
true
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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)
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
DBLista._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
|
35
|
+
true
|
36
|
+
end
|
35
37
|
end
|
36
38
|
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/#{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/#{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,16 +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
|
-
|
15
|
+
DBLista._post("/#{type}s/#{id}/vote", nil, @token)
|
16
|
+
true
|
17
|
+
end
|
17
18
|
end
|
18
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.4.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-05 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,8 +82,14 @@ 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
|
92
|
+
- lib/dblista/constants.rb
|
73
93
|
- lib/dblista/errors.rb
|
74
94
|
- lib/dblista/helpers.rb
|
75
95
|
- lib/dblista/info.rb
|
data/example/info.rb
DELETED