dblista 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- 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 +10 -0
- data/lib/dblista/constants.rb +29 -1
- data/lib/dblista/info.rb +9 -3
- data/lib/dblista/list/bot.rb +18 -6
- data/lib/dblista/list/server.rb +12 -4
- data/lib/dblista/stats.rb +2 -1
- data/lib/dblista/user/client.rb +9 -2
- data/lib/dblista/version.rb +1 -1
- metadata +21 -2
- 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
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
|
@@ -84,4 +90,8 @@ module DBLista
|
|
84
90
|
def self._limit_integer(input)
|
85
91
|
raise DBLista::Error, DBLista::Errors::LIMIT_INTEGER unless input.is_a?(Integer)
|
86
92
|
end
|
93
|
+
|
94
|
+
def self._cache(name)
|
95
|
+
DBLista::Cache.get(name.to_sym, lifetime: DBLista::CACHE_LIFETIME) { yield }
|
96
|
+
end
|
87
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
@@ -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::List::Bot.top(0, 100_000_000)
|
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::List::Server.top(0, 100_000_000)
|
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/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'
|
@@ -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
|
data/lib/dblista/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
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,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
|
data/example/info.rb
DELETED