dblista 0.3.2 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a839df00612d366d1a0184c647cdce72895f1ee02d71c25deb2e76ae78c7026
4
- data.tar.gz: 4922b94a22e10332f564ef628058664204c3904c794e1381cab452478c24af8f
3
+ metadata.gz: a670e074610d8c1087fe16c42b0864afe8b29f519092bb71b07ed202cce621f0
4
+ data.tar.gz: 98dcacb603967baab512b828b5fa34a06c3a528444776b93a0b96035b09db943
5
5
  SHA512:
6
- metadata.gz: c9131862894f3adfaba7fb2a0add9f7fb31f423a8a94ebbd19efb8d1f84f8c14e8ee9acec3c1742a3eef0cc2e02cb8f228f5ab3eb98b5e6ebe8de0427b4f2d14
7
- data.tar.gz: 3105e3459bea2a2c8f33f1f4470ead0d103d6757396bdde267e4b323cd5839e573d90d63d47ab6b3756083cf0e5f9a18740b2a844629ddc06ceca51ea6ab6150
6
+ metadata.gz: 2a7dc73182643455004db0a1a37a67b6ed5e185c02cea49265d21918ebecc737673a8ea929928cc3821cb17b8e7a4e7fa555da7ae76943530273869ae043a525
7
+ data.tar.gz: 323fa2c8c12a9cb6849118b4d38844c5c1261fd9a75d1279b0bac100458b318cd0c372011849c905bceff307d7a441d5069a87c252a9850376278cbc606b81d3
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dblista (0.3.2)
4
+ dblista (0.6.1)
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. Pozwala m.in. na automatyczne wysyłanie statystyk (dla botów napisanych w Discordrb), CRUD botów i serwerów oraz pare innych rzeczy.
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
 
@@ -38,4 +45,4 @@ puts top
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 nim co chcesz.
48
+ Ten gem jest dostępny na licencji [MIT License](https://opensource.org/licenses/MIT). Rób z tym co chcesz.
@@ -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"
@@ -0,0 +1,11 @@
1
+ require 'dblista'
2
+ require 'discordrb'
3
+
4
+ bot = Discordrb::Bot.new token: 'TOKEN'
5
+ dbl = DBLista::Stats.new 'DBLISTA_TOKEN', bot
6
+
7
+ bot.message(content: 'Ping!') do |event|
8
+ event.respond 'Pong!'
9
+ end
10
+
11
+ bot.run
@@ -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
+ })
@@ -0,0 +1,5 @@
1
+ require 'dblista'
2
+
3
+ DBLista::List::Bot.all.each do |server|
4
+ puts server['name']
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'dblista'
2
+
3
+ client = DBLista::User::Client.new('TOKEN')
4
+
5
+ puts client.notifications
6
+ client.clear_notifications
@@ -0,0 +1,5 @@
1
+ require 'dblista'
2
+
3
+ results = DBLista::List::Bot.search(DBLista::Tags::Bot::MUSIC)
4
+
5
+ puts results
@@ -0,0 +1,5 @@
1
+ require 'dblista'
2
+
3
+ user = DBLista::Information.user('ID')
4
+
5
+ puts DBLista::Helpers.get_avatar(user['id'], user['avatar'], 1024)
@@ -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
@@ -35,6 +35,34 @@ module DBLista
35
35
  USER = 0
36
36
  MODERATOR = 1
37
37
  BIG_MODERATOR = 2
38
- ADMINISTRATOR = 3
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
@@ -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._get("/bots/#{id}")
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._get("/servers/#{id}")
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._get("/users/#{id}")
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
@@ -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._get("/bots/list/top/#{page}?limit=#{limit}")
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._get("/bots/list/premium/#{page}?limit=#{limit}")
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._get('/bots/list/unverified')
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._get('/bots/list/rejected')
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::List::Bot.top(0, 100_000_000)
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._get("/bots/search/#{CGI.escape query.to_s}")
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
@@ -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._get("/servers/list/top/#{page}?limit=#{limit}")
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._get("/servers/list/premium/#{page}?limit=#{limit}")
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::List::Server.top(0, 100_000_000)
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._get("/servers/search/#{CGI.escape query.to_s}")
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
@@ -42,12 +42,13 @@ module DBLista
42
42
  #
43
43
  # @param members [Integer] member count
44
44
  # @param servers [Integer] server count
45
- # @return [Hash] raw data from DBLista
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
@@ -58,5 +58,23 @@ module DBLista::User
58
58
  }, @token)
59
59
  true
60
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
@@ -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
@@ -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
- DBLista._get('/users/me', @token)
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
- def guilds
53
- DBLista._get('/users/me/guilds', @token)
59
+ def joined_guilds
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
@@ -34,5 +34,40 @@ module DBLista::User
34
34
  DBLista._delete("/#{type}s/#{id}/rate/#{target_id}", nil, @token)
35
35
  true
36
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
@@ -13,7 +13,7 @@ module DBLista::User
13
13
  def approve(id, reason = 'Brak powodu')
14
14
  DBLista._validate_id id
15
15
 
16
- DBLista._post("/bots/#{id}/approve?reason=#{CGI.escape reason}", nil, @token)
16
+ DBLista._post("/bots/verify/#{id}/approve?reason=#{CGI.escape reason}", nil, @token)
17
17
  true
18
18
  end
19
19
 
@@ -25,7 +25,7 @@ module DBLista::User
25
25
  def reject(id, reason = 'Brak powodu')
26
26
  DBLista._validate_id id
27
27
 
28
- DBLista._post("/bots/#{id}/reject?reason=#{CGI.escape reason}", nil, @token)
28
+ DBLista._post("/bots/verify/#{id}/reject?reason=#{CGI.escape reason}", nil, @token)
29
29
  true
30
30
  end
31
31
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module DBLista
4
4
  # Wrapper version
5
- VERSION = '0.3.2'
5
+ VERSION = '0.6.1'
6
6
  end
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.3.2
4
+ version: 0.6.1
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-05 00:00:00.000000000 Z
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
- - example/info.rb
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
@@ -1,3 +0,0 @@
1
- require 'dblista'
2
-
3
- puts DBLista::Information.bot('594589970740543490')