dblruby 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dblruby.rb +18 -7
- data/lib/dblruby/bot.rb +12 -12
- data/lib/dblruby/errors.rb +7 -4
- data/lib/dblruby/search.rb +1 -1
- data/lib/dblruby/stats.rb +2 -2
- data/lib/dblruby/user.rb +11 -11
- data/lib/dblruby/weekend.rb +2 -2
- data/lib/dblruby/widget.rb +119 -0
- metadata +3 -3
- data/lib/dblruby/api.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3de08405f7a2efcc93b46c09448d9f0da4332a97
|
4
|
+
data.tar.gz: 76cc108bcfb280a6045329e6357780e80373acf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d369eb612d86b6dc4b7736813262fe4159e578e072cc7b6d4bfe2e42e065af5c81591203cc08ac516ec520fc6c331da3d24b0179d1d823755f08cba5ae973d5
|
7
|
+
data.tar.gz: 870a7b96543b4a18cb28bedb72d95d16c77e0172dbdd6dae244b080770b4329b19765feb56d60bcc9fda66155152f2f8385cb727f1986cfb5f683fafe86421e1
|
data/lib/dblruby.rb
CHANGED
@@ -23,7 +23,7 @@ class DBLRuby
|
|
23
23
|
Bot.new(id: id)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
alias_method :loadbot, :bot
|
27
27
|
|
28
28
|
# Get all of the bot's stats as if you just called DBL.bot(id)
|
29
29
|
# @return [Bot] the bot as a bot.
|
@@ -37,39 +37,49 @@ class DBLRuby
|
|
37
37
|
User.new(id)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
alias_method :loaduser, :user
|
41
41
|
|
42
42
|
# Change the API key
|
43
43
|
# @param apikey [String] API Key of the bot, taken from the DBL.
|
44
44
|
attr_writer :api
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
alias_method :updateapikey, :api=
|
47
|
+
alias_method :updateapi, :api=
|
48
|
+
alias_method :apikey=, :api=
|
49
49
|
|
50
50
|
# Change the bot ID
|
51
51
|
# @param id [Integer, String] Integer/String of the bot's id.
|
52
52
|
attr_writer :id
|
53
53
|
|
54
|
-
|
54
|
+
alias_method :updateid, :id=
|
55
55
|
|
56
56
|
# Define weekend
|
57
57
|
def weekend
|
58
58
|
Weekend.new
|
59
59
|
end
|
60
60
|
|
61
|
+
# Skip the middleman, let's just see if it's the weekend!
|
62
|
+
def weekend?
|
63
|
+
weekend.weekend?
|
64
|
+
end
|
65
|
+
|
61
66
|
# @see Search#initialize
|
62
67
|
def search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil)
|
63
68
|
Search.new(search: search, limit: limit, offset: offset, sort: sort, fields: fields)
|
64
69
|
end
|
65
70
|
|
71
|
+
# @see Widget#initialize
|
72
|
+
def widget(size: 'large', file_type: 'png', small_type: nil, topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil, avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, id: @id)
|
73
|
+
Widget.new(size: size, file_type: file_type, small_type: small_type, topcolor: topcolor, middlecolor: middlecolor, usernamecolor: usernamecolor, certifiedcolor: certifiedcolor, datacolor: datacolor, labelcolor: labelcolor, highlightcolor: highlightcolor, avatarbg: avatarbg, leftcolor: leftcolor, rightcolor: rightcolor, lefttextcolor: lefttextcolor, righttextcolor: righttextcolor, id: id)
|
74
|
+
end
|
75
|
+
|
66
76
|
# Get the ID from instantiation
|
67
77
|
attr_reader :id
|
68
78
|
|
69
79
|
# Get the API Key from instantiation
|
70
80
|
attr_reader :api
|
71
81
|
|
72
|
-
|
82
|
+
alias_method :apikey, :api
|
73
83
|
end
|
74
84
|
|
75
85
|
# Require files.
|
@@ -79,3 +89,4 @@ require 'dblruby/user'
|
|
79
89
|
require 'dblruby/search'
|
80
90
|
require 'dblruby/stats'
|
81
91
|
require 'dblruby/weekend'
|
92
|
+
require 'dblruby/widget'
|
data/lib/dblruby/bot.rb
CHANGED
@@ -18,7 +18,7 @@ class DBLRuby::Bot
|
|
18
18
|
# @return data in raw json form.
|
19
19
|
attr_reader :data
|
20
20
|
|
21
|
-
|
21
|
+
alias_method :to_s, :data
|
22
22
|
|
23
23
|
# Return the error if there is one, nil otherwise.
|
24
24
|
# @return [String, nil] the error.
|
@@ -110,8 +110,8 @@ class DBLRuby::Bot
|
|
110
110
|
@data['discriminator']
|
111
111
|
end
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
alias_method :discrim, :discriminator
|
114
|
+
alias_method :tag, :discriminator
|
115
115
|
|
116
116
|
# The username of the bot.
|
117
117
|
# @return [String] the bot's username.
|
@@ -156,8 +156,8 @@ class DBLRuby::Bot
|
|
156
156
|
@data['server_count'].to_i
|
157
157
|
end
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
alias_method :guild_count, :server_count
|
160
|
+
alias_method :server, :server_count
|
161
161
|
|
162
162
|
# Get the bot's "This Bot Powers the following Servers"
|
163
163
|
# @return [Array<String>] the bot's guilds.
|
@@ -165,7 +165,7 @@ class DBLRuby::Bot
|
|
165
165
|
@data['guilds']
|
166
166
|
end
|
167
167
|
|
168
|
-
|
168
|
+
alias_method :servers, :guilds
|
169
169
|
|
170
170
|
# Get the bot's shards.
|
171
171
|
# @return [Array<String>] the bot's shards.
|
@@ -179,7 +179,7 @@ class DBLRuby::Bot
|
|
179
179
|
@data['monthlyPoints'].to_i
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
alias_method :monthlyvotes, :monthlypoints
|
183
183
|
|
184
184
|
# The amount of upvotes the bot has.
|
185
185
|
# @return [Integer] the bot's total points/votes.
|
@@ -187,7 +187,7 @@ class DBLRuby::Bot
|
|
187
187
|
@data['points'].to_i
|
188
188
|
end
|
189
189
|
|
190
|
-
|
190
|
+
alias_method :votes, :points
|
191
191
|
|
192
192
|
# The certified status of the bot.
|
193
193
|
# @return [true, false] the bot's certified status.
|
@@ -195,9 +195,9 @@ class DBLRuby::Bot
|
|
195
195
|
@data['certifiedBot']
|
196
196
|
end
|
197
197
|
|
198
|
-
|
199
|
-
|
200
|
-
|
198
|
+
alias_method :certifiedbot, :certified?
|
199
|
+
alias_method :certified, :certified?
|
200
|
+
alias_method :certifiedbot?, :certified?
|
201
201
|
|
202
202
|
# The owners of the bot. First one in the array is the main owner.
|
203
203
|
# @return [Array<String>] the bot's owners in an array.
|
@@ -217,5 +217,5 @@ class DBLRuby::Bot
|
|
217
217
|
@data['donatebotguildid']
|
218
218
|
end
|
219
219
|
|
220
|
-
|
220
|
+
alias_method :donatebotserverid, :donatebotguildid
|
221
221
|
end
|
data/lib/dblruby/errors.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# Errors are cool.
|
2
2
|
module DBLRuby::Errors
|
3
|
-
#
|
3
|
+
# Raised if a 404 error is returned in #bot
|
4
4
|
class InvalidBot < RuntimeError; end
|
5
5
|
|
6
|
-
#
|
6
|
+
# Raised if a 404 error is returned in #user
|
7
7
|
class InvalidUser < RuntimeError; end
|
8
8
|
|
9
|
-
#
|
9
|
+
# Raised if a 401 unauthorized error is returned in stats.
|
10
10
|
class InvalidAPIKey < RuntimeError; end
|
11
11
|
|
12
|
-
#
|
12
|
+
# Raised if a 404 unknown error is returned in stats.
|
13
13
|
class InvalidID < RuntimeError; end
|
14
|
+
|
15
|
+
# Rasied if an invalid Widget parameter is specified
|
16
|
+
class InvalidWidget < RuntimeError; end
|
14
17
|
end
|
data/lib/dblruby/search.rb
CHANGED
data/lib/dblruby/stats.rb
CHANGED
@@ -18,7 +18,7 @@ class DBLRuby::Stats
|
|
18
18
|
'DBL Returned a 404 unknown error! Did you enter the correct ID?'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
alias_method :servers, :servercount
|
22
22
|
|
23
23
|
# Update the bot's server count.
|
24
24
|
# @param count [Integer, Array<Integer>] Integer/String of bot server count.
|
@@ -40,7 +40,7 @@ class DBLRuby::Stats
|
|
40
40
|
'There was an error posting stats to the DBL. Is your API key ok?'
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
alias_method :servers=, :updateservercount
|
44
44
|
|
45
45
|
# Check to see if a user really voted, via an ID.
|
46
46
|
# @param id [Integer, String] Integer/String ID of user you're requesting.
|
data/lib/dblruby/user.rb
CHANGED
@@ -14,7 +14,7 @@ class DBLRuby::User
|
|
14
14
|
# @return data in raw json form.
|
15
15
|
attr_reader :data
|
16
16
|
|
17
|
-
|
17
|
+
alias_method :to_s, :data
|
18
18
|
|
19
19
|
# Return the error if there is one, nil otherwise.
|
20
20
|
# @return [String, nil] the error.
|
@@ -46,8 +46,8 @@ class DBLRuby::User
|
|
46
46
|
@data['discriminator'].delete('#').to_i
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
alias_method :discrim, :discriminator
|
50
|
+
alias_method :tag, :discriminator
|
51
51
|
|
52
52
|
# Returns the user's distinct, which is the Username and Discriminator.
|
53
53
|
# @return [String] the user's username + discrim.
|
@@ -133,7 +133,7 @@ class DBLRuby::User
|
|
133
133
|
@data['color']
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
alias_method :colour, :color
|
137
137
|
|
138
138
|
# The supporter status of the user.
|
139
139
|
# @return [true, false] the user's supporter status.
|
@@ -141,7 +141,7 @@ class DBLRuby::User
|
|
141
141
|
@data['supporter']
|
142
142
|
end
|
143
143
|
|
144
|
-
|
144
|
+
alias_method :supporter, :supporter?
|
145
145
|
|
146
146
|
# The certified status of the user.
|
147
147
|
# @return [true, false] the user's certified status.
|
@@ -149,9 +149,9 @@ class DBLRuby::User
|
|
149
149
|
@data['certifiedDev']
|
150
150
|
end
|
151
151
|
|
152
|
-
|
153
|
-
|
154
|
-
|
152
|
+
alias_method :certified, :certified?
|
153
|
+
alias_method :certifieddev, :certified
|
154
|
+
alias_method :certifieddev?, :certified
|
155
155
|
|
156
156
|
# The mod status of the user.
|
157
157
|
# @return [true, false] the user's mod status.
|
@@ -159,7 +159,7 @@ class DBLRuby::User
|
|
159
159
|
@data['mod']
|
160
160
|
end
|
161
161
|
|
162
|
-
|
162
|
+
alias_method :mod, :mod?
|
163
163
|
|
164
164
|
# The website moderator status of the user.
|
165
165
|
# @return [true, false] the user's website mod status.
|
@@ -167,7 +167,7 @@ class DBLRuby::User
|
|
167
167
|
@data['webMod']
|
168
168
|
end
|
169
169
|
|
170
|
-
|
170
|
+
alias_method :webmod, :webmod?
|
171
171
|
|
172
172
|
# The admin status of the user.
|
173
173
|
# @return [true, false] the user's admin status.
|
@@ -175,5 +175,5 @@ class DBLRuby::User
|
|
175
175
|
@data['admin']
|
176
176
|
end
|
177
177
|
|
178
|
-
|
178
|
+
alias_method :admin, :admin?
|
179
179
|
end
|
data/lib/dblruby/weekend.rb
CHANGED
@@ -9,7 +9,7 @@ class DBLRuby::Weekend
|
|
9
9
|
# @return data in raw json form.
|
10
10
|
attr_reader :data
|
11
11
|
|
12
|
-
|
12
|
+
alias_method :to_s, :data
|
13
13
|
|
14
14
|
# Return the whether it's the weekend.
|
15
15
|
# @return [true, false] the weekend status.
|
@@ -17,5 +17,5 @@ class DBLRuby::Weekend
|
|
17
17
|
@data['is_weekend']
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
alias_method :isweekend, :weekend?
|
21
21
|
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Make a widget
|
2
|
+
class DBLRuby::Widget
|
3
|
+
BASE_URL = 'https://discordbots.org/api/widget/'.freeze
|
4
|
+
|
5
|
+
# Make a new widget
|
6
|
+
# @param size ['large', 'small'] The size of the widget.
|
7
|
+
# @param file_type ['png', 'svg'] The file type of the image
|
8
|
+
# @param small_type ['owner', 'status', 'upvotes', 'servers', 'lib'] The type of small widget.
|
9
|
+
# @param topcolor [Hexadecimal] The top color of the widget (Large)
|
10
|
+
# @param middlecolor [Hexadecimal] The middle color of the widget (Large)
|
11
|
+
# @param usernamecolor [Hexadecimal] The username color of the widget (Large)
|
12
|
+
# @param certifiedcolor [Hexadecimal] The certified color of the widget (Large)
|
13
|
+
# @param datacolor [Hexadecimal] The data color of the widget (Large)
|
14
|
+
# @param labelcolor [Hexadecimal] The label color of the widget (Large)
|
15
|
+
# @param highlightcolor [Hexadecimal] The highlight color of the widget (Large)
|
16
|
+
# @param avatarbg [Hexadecimal] The avatar background color of the widget (Small)
|
17
|
+
# @param leftcolor [Hexadecimal] The left color of the widget (Small)
|
18
|
+
# @param rightcolor [Hexadecimal] The right color of the widget (Small)
|
19
|
+
# @param lefttextcolor [Hexadecimal] The left text color of the widget (Small)
|
20
|
+
# @param righttextcolor [Hexadecimal] The right text color of the widget (Small)
|
21
|
+
# @param noavatar [true, false] Whether there should be an avatar (Small)
|
22
|
+
def initialize(size: 'large', file_type: 'png',
|
23
|
+
small_type: nil,
|
24
|
+
topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil,
|
25
|
+
avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, noavatar: nil,
|
26
|
+
id: nil)
|
27
|
+
@size = size
|
28
|
+
@file_type = file_type
|
29
|
+
@small_type = small_type
|
30
|
+
@topcolor = topcolor
|
31
|
+
@middlecolor = middlecolor
|
32
|
+
@usernamecolor = usernamecolor
|
33
|
+
@certifiedcolor = certifiedcolor
|
34
|
+
@datacolor = datacolor
|
35
|
+
@labelcolor = labelcolor
|
36
|
+
@highlightcolor = highlightcolor
|
37
|
+
@avatarbg = avatarbg
|
38
|
+
@leftcolor = leftcolor
|
39
|
+
@rightcolor = rightcolor
|
40
|
+
@lefttextcolor = lefttextcolor
|
41
|
+
@righttextcolor = righttextcolor
|
42
|
+
@noavatar = noavatar
|
43
|
+
@id = id
|
44
|
+
|
45
|
+
raise DBLRuby::Errors::InvalidWidget, 'Small size specified but no small type was provided' if @size == 'small' && @small_type.nil?
|
46
|
+
raise DBLRuby::Errors::InvalidWidget, 'Small parameter specified for large widget' if @size == 'large' && (!@avatarbg.nil? || !@leftcolor.nil? || !@rightcolor.nil? || !@lefttextcolor.nil? || !@righttextcolor.nil? || !@noavatar.nil?)
|
47
|
+
raise DBLRuby::Errors::InvalidWidget, 'Large parameter specified for small widget' if @size == 'small' && (!@topcolor.nil? || !@middlecolor.nil? || !@usernamecolor.nil? || !@certifiedcolor.nil? || !@datacolor.nil? || !@labelcolor.nil? || !@highlightcolor.nil?)
|
48
|
+
|
49
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? @size
|
50
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(@small_type)
|
51
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? @file_type
|
52
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' unless %w[true false].include? @noavatar
|
53
|
+
end
|
54
|
+
|
55
|
+
def size=(size)
|
56
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? size
|
57
|
+
|
58
|
+
@size = size
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_type=(file_type)
|
62
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? file_type
|
63
|
+
|
64
|
+
@file_type = file_type
|
65
|
+
end
|
66
|
+
|
67
|
+
def small_type=(small_type)
|
68
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(small_type)
|
69
|
+
|
70
|
+
@small_type = small_type
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_writer :topcolor
|
74
|
+
attr_writer :middlecolor
|
75
|
+
attr_writer :usernamecolor
|
76
|
+
attr_writer :certifiedcolor
|
77
|
+
attr_writer :datacolor
|
78
|
+
attr_writer :labelcolor
|
79
|
+
attr_writer :highlightcolor
|
80
|
+
attr_writer :avatarbg
|
81
|
+
attr_writer :leftcolor
|
82
|
+
attr_writer :rightcolor
|
83
|
+
attr_writer :lefttextcolor
|
84
|
+
attr_writer :righttextcolor
|
85
|
+
|
86
|
+
def noavatar=(noavatar)
|
87
|
+
raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' unless %w[true false].include? noavatar
|
88
|
+
|
89
|
+
@noavatar = noavatar
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [String] The URL, ready for linking.
|
93
|
+
def url
|
94
|
+
params = []
|
95
|
+
if @size == 'large'
|
96
|
+
params.push("topcolor=#{@topcolor}") unless @topcolor.nil?
|
97
|
+
params.push("middlecolor=#{@middlecolor}") unless @middlecolor.nil?
|
98
|
+
params.push("usernamecolor=#{@usernamecolor}") unless @usernamecolor.nil?
|
99
|
+
params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil?
|
100
|
+
params.push("datacolor=#{@datacolor}") unless @datacolor.nil?
|
101
|
+
params.push("labelcolor=#{@labelcolor}") unless @labelcolor.nil?
|
102
|
+
params.push("highlightcolor=#{@highlightcolor}") unless @highlightcolor.nil?
|
103
|
+
output = "#{BASE_URL}#{@id}.#{@file_type}"
|
104
|
+
elsif @size == 'small'
|
105
|
+
params.push("avatarbg=#{@avatarbg}") unless @avatarbg.nil?
|
106
|
+
params.push("leftcolor=#{@leftcolor}") unless @leftcolor.nil?
|
107
|
+
params.push("rightcolor=#{@rightcolor}") unless @rightcolor.nil?
|
108
|
+
params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil?
|
109
|
+
params.push("lefttextcolor=#{@lefttextcolor}") unless @lefttextcolor.nil?
|
110
|
+
params.push("righttextcolor=#{@labelcolor}") unless @righttextcolor.nil?
|
111
|
+
params.push("noavatar=#{@noavatar}") unless @noavatar.nil?
|
112
|
+
output = "#{BASE_URL}#{@small_type}/#{@id}.#{@file_type}"
|
113
|
+
end
|
114
|
+
output += "?#{params.join('&')}" unless params.length.zero?
|
115
|
+
output
|
116
|
+
end
|
117
|
+
|
118
|
+
alias_method :to_s, :url
|
119
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dblruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chewsterchew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -45,13 +45,13 @@ extensions: []
|
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
47
|
- lib/dblruby.rb
|
48
|
-
- lib/dblruby/api.rb
|
49
48
|
- lib/dblruby/bot.rb
|
50
49
|
- lib/dblruby/errors.rb
|
51
50
|
- lib/dblruby/search.rb
|
52
51
|
- lib/dblruby/stats.rb
|
53
52
|
- lib/dblruby/user.rb
|
54
53
|
- lib/dblruby/weekend.rb
|
54
|
+
- lib/dblruby/widget.rb
|
55
55
|
homepage: http://github.com/Chewsterchew/DBLRuby
|
56
56
|
licenses:
|
57
57
|
- MIT
|
data/lib/dblruby/api.rb
DELETED