commandrb 0.4.3 → 0.4.4
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/lib/commandrb.rb +278 -278
- data/lib/helper.rb +37 -37
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e9df314b41310e8efa2142d628ed0c7ecbf9c4c
|
4
|
+
data.tar.gz: b79dbcade06d8c7cf39c6a974b5b0257f6126c5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a2630312374f10a2d30986c9bf130102b7bba611a0f5efca17e53de67b0aad5cf4ed1a5382f786fcfa8e62ed33d044426209d5280917488380ed7198d89753
|
7
|
+
data.tar.gz: e9cc3ba89ec2457186d6548621753a82e03fb675f5b4f7851b9b71c0047c80bce9301b900e57738bc2ce95786c652701c6cd43205241743762a9fb0d0c86e6e7
|
data/lib/commandrb.rb
CHANGED
@@ -1,278 +1,278 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
class CommandrbBot
|
4
|
-
|
5
|
-
ENV['COMMANDRB_MODE'] == 'debug' ? @debug_mode = true : @debug_mode = false
|
6
|
-
|
7
|
-
# Be able to adjust the config on the fly.
|
8
|
-
attr_accessor :config
|
9
|
-
|
10
|
-
# Needed to run the bot, or create custom events.
|
11
|
-
attr_accessor :bot
|
12
|
-
|
13
|
-
# Can manually manipulate commands using this.
|
14
|
-
attr_accessor :commands
|
15
|
-
|
16
|
-
# Lets you change global prefixes while the bot is running (Not recommended!)
|
17
|
-
attr_accessor :prefixes
|
18
|
-
|
19
|
-
|
20
|
-
def add_command(name, attributes = {})
|
21
|
-
@commands[name.to_sym] = attributes
|
22
|
-
end
|
23
|
-
|
24
|
-
def remove_command(name)
|
25
|
-
begin
|
26
|
-
@commands.delete(name)
|
27
|
-
rescue
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
true
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize(init_hash)
|
34
|
-
|
35
|
-
# Setup the variables for first use.
|
36
|
-
@commands = {}
|
37
|
-
@prefixes = []
|
38
|
-
@config = init_hash
|
39
|
-
|
40
|
-
# Load sane defaults for options that aren't specified.
|
41
|
-
|
42
|
-
# @config[:prefix_type] = 'rescue' if @config[:prefix_type].nil?
|
43
|
-
@config[:typing_default] = false if @config[:typing_default].nil?
|
44
|
-
@config[:selfbot] = false if @config[:selfbot].nil?
|
45
|
-
@config[:delete_activators] = false if @config[:delete_activators].nil?
|
46
|
-
|
47
|
-
if @config[:token].nil? or init_hash[:token] == ''
|
48
|
-
raise 'No token supplied in init hash!'
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
@
|
64
|
-
|
65
|
-
@
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@
|
87
|
-
@
|
88
|
-
@
|
89
|
-
@
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
triggers
|
99
|
-
|
100
|
-
|
101
|
-
@activator =
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
puts "Final
|
133
|
-
|
134
|
-
break if @config[:selfbot] && event.user.id != @bot.profile.id
|
135
|
-
|
136
|
-
# Command flag defaults
|
137
|
-
command[:catch_errors] = @config[:catch_errors] if command[:catch_errors].nil?
|
138
|
-
command[:owners_only] = false if command[:owners_only].nil?
|
139
|
-
command[:max_args] = 2000 if command[:max_args].nil?
|
140
|
-
command[:server_only] = false if command[:server_only].nil?
|
141
|
-
command[:typing] = @config[:typing_default] if command[:typing_default].nil?
|
142
|
-
command[:delete_activator] = @config[:delete_activators] if command[:delete_activator].nil?
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
puts "[DEBUG]
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
#
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
embed.
|
174
|
-
embed.
|
175
|
-
embed.
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
#
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
event.channel.send_message('', false,
|
221
|
-
Helper.error_embed(
|
222
|
-
error: "Too many arguments! \nMax arguments: `#{command[:max_args]}`",
|
223
|
-
footer: "Command: `#{event.message.content}`",
|
224
|
-
colour: 0xFA0E30,
|
225
|
-
code_error: false
|
226
|
-
)
|
227
|
-
)
|
228
|
-
@finished = true
|
229
|
-
break
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
unless command[:required_permissions].nil?
|
234
|
-
command[:required_permissions].each { |x|
|
235
|
-
unless event.user.on(event.server).permission?(x,event.channel)
|
236
|
-
event.channel.send_message('', false,
|
237
|
-
Helper.error_embed(
|
238
|
-
error: "You don't have permission for that!\nPermission required: `#{x.to_s}`",
|
239
|
-
footer: "Command: `#{event.message.content}`",
|
240
|
-
colour: 0xFA0E30,
|
241
|
-
code_error: false
|
242
|
-
)
|
243
|
-
)
|
244
|
-
@finished = true
|
245
|
-
break
|
246
|
-
end
|
247
|
-
}
|
248
|
-
end
|
249
|
-
|
250
|
-
unless @finished
|
251
|
-
# If the command is configured to catch all errors, thy shall be done.
|
252
|
-
if !command[:catch_errors] || @config['catch_errors']
|
253
|
-
# Run the command code!
|
254
|
-
command[:code].call(event, args, rawargs)
|
255
|
-
else
|
256
|
-
# Run the command code, but catch all errors and output accordingly.
|
257
|
-
begin
|
258
|
-
command[:code].call(event, args, rawargs)
|
259
|
-
rescue Exception => e
|
260
|
-
event.respond("❌ An error has occured!! ```ruby\n#{e}```Please contact the bot owner with the above message for assistance.")
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# All done here.
|
266
|
-
puts "Finished!! Executed command: #{@chosen}" if @debug_mode
|
267
|
-
@command = command
|
268
|
-
@event = event
|
269
|
-
@args = args
|
270
|
-
@rawargs = rawargs
|
271
|
-
@finished = true
|
272
|
-
break
|
273
|
-
}
|
274
|
-
end
|
275
|
-
}
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class CommandrbBot
|
4
|
+
|
5
|
+
ENV['COMMANDRB_MODE'] == 'debug' ? @debug_mode = true : @debug_mode = false
|
6
|
+
|
7
|
+
# Be able to adjust the config on the fly.
|
8
|
+
attr_accessor :config
|
9
|
+
|
10
|
+
# Needed to run the bot, or create custom events.
|
11
|
+
attr_accessor :bot
|
12
|
+
|
13
|
+
# Can manually manipulate commands using this.
|
14
|
+
attr_accessor :commands
|
15
|
+
|
16
|
+
# Lets you change global prefixes while the bot is running (Not recommended!)
|
17
|
+
attr_accessor :prefixes
|
18
|
+
|
19
|
+
|
20
|
+
def add_command(name, attributes = {})
|
21
|
+
@commands[name.to_sym] = attributes
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove_command(name)
|
25
|
+
begin
|
26
|
+
@commands.delete(name)
|
27
|
+
rescue
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(init_hash)
|
34
|
+
|
35
|
+
# Setup the variables for first use.
|
36
|
+
@commands = {}
|
37
|
+
@prefixes = []
|
38
|
+
@config = init_hash
|
39
|
+
|
40
|
+
# Load sane defaults for options that aren't specified.
|
41
|
+
|
42
|
+
# @config[:prefix_type] = 'rescue' if @config[:prefix_type].nil?
|
43
|
+
@config[:typing_default] = false if @config[:typing_default].nil?
|
44
|
+
@config[:selfbot] = false if @config[:selfbot].nil?
|
45
|
+
@config[:delete_activators] = false if @config[:delete_activators].nil?
|
46
|
+
|
47
|
+
if @config[:token].nil? or init_hash[:token] == ''
|
48
|
+
raise 'No token supplied in init hash!'
|
49
|
+
end
|
50
|
+
|
51
|
+
init_parse_self = init_hash[:parse_self] rescue nil
|
52
|
+
init_type = @config[:type]
|
53
|
+
|
54
|
+
if init_type == :bot
|
55
|
+
if init_hash[:client_id].nil?
|
56
|
+
raise 'No client ID or invalid client ID supplied in init hash!'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
@config[:owners] = init_hash[:owners]
|
61
|
+
@config[:owners] = [] if @config[:owners].nil?
|
62
|
+
|
63
|
+
@prefixes = init_hash[:prefixes]
|
64
|
+
|
65
|
+
@bot = Discordrb::Bot.new(
|
66
|
+
token: @config[:token],
|
67
|
+
client_id: @config[:client_id],
|
68
|
+
parse_self: init_parse_self,
|
69
|
+
type: @config[:type]
|
70
|
+
)
|
71
|
+
|
72
|
+
unless init_hash[:ready].nil?
|
73
|
+
@bot.ready do |event|
|
74
|
+
event.bot.game = @config[:game] unless config[:game].nil?
|
75
|
+
init_hash[:ready].call(event)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Command processing
|
81
|
+
@bot.message do |event|
|
82
|
+
@finished = false
|
83
|
+
@command = nil
|
84
|
+
@event = nil
|
85
|
+
@chosen = nil
|
86
|
+
@args = nil
|
87
|
+
@rawargs = nil
|
88
|
+
@continue = false
|
89
|
+
@prefixes.each { |prefix|
|
90
|
+
break if @finished
|
91
|
+
if event.message.content.start_with?(prefix)
|
92
|
+
|
93
|
+
@commands.each { | key, command |
|
94
|
+
break if @finished
|
95
|
+
puts ":: Considering #{key.to_s}" if @debug_mode
|
96
|
+
triggers = command[:triggers].nil? ? [key.to_s] : command[:triggers]
|
97
|
+
|
98
|
+
triggers.each { |trigger|
|
99
|
+
@activator = prefix + trigger.to_s
|
100
|
+
puts @activator if @debug_mode
|
101
|
+
@activator = @activator.downcase
|
102
|
+
if event.message.content.downcase.start_with?(@activator)
|
103
|
+
puts "Prefix matched! #{@activator}" if @debug_mode
|
104
|
+
|
105
|
+
# Continue only if you've already chosen a choice.
|
106
|
+
if @chosen.nil?
|
107
|
+
puts "First match obtained!" if @debug_mode
|
108
|
+
@continue = true
|
109
|
+
@chosen = @activator
|
110
|
+
else
|
111
|
+
# If the new activator begins with the chosen one, then override it.
|
112
|
+
# Example: sh is chosen, shell is the new one.
|
113
|
+
# In this example, shell would override sh, preventing ugly bugs.
|
114
|
+
if @activator.start_with?(@chosen)
|
115
|
+
puts "#{@activator} just overrode #{@chosen}" if @debug_mode
|
116
|
+
@chosen = @activator
|
117
|
+
# Otherwhise, just give up.
|
118
|
+
else
|
119
|
+
puts "Match failed..." if @debug_mode
|
120
|
+
next
|
121
|
+
end
|
122
|
+
# If you haven't chosen yet, get choosing!
|
123
|
+
end
|
124
|
+
end
|
125
|
+
}
|
126
|
+
|
127
|
+
puts "Result: #{@chosen}" if @debug_mode
|
128
|
+
|
129
|
+
unless @continue
|
130
|
+
next
|
131
|
+
end
|
132
|
+
puts "Final result: #{@chosen}" if @debug_mode
|
133
|
+
|
134
|
+
break if @config[:selfbot] && event.user.id != @bot.profile.id
|
135
|
+
|
136
|
+
# Command flag defaults
|
137
|
+
command[:catch_errors] = @config[:catch_errors] if command[:catch_errors].nil?
|
138
|
+
command[:owners_only] = false if command[:owners_only].nil?
|
139
|
+
command[:max_args] = 2000 if command[:max_args].nil?
|
140
|
+
command[:server_only] = false if command[:server_only].nil?
|
141
|
+
command[:typing] = @config[:typing_default] if command[:typing_default].nil?
|
142
|
+
command[:delete_activator] = @config[:delete_activators] if command[:delete_activator].nil?
|
143
|
+
command[:owner_override] = false if command[:owner_override].nil?
|
144
|
+
|
145
|
+
# If the command is set to owners only and the user is not the owner, show error and abort.
|
146
|
+
puts "[DEBUG] Command being processed: '#{command}'" if @debug_mode
|
147
|
+
puts "[DEBUG] Owners only? #{command[:owners_only]}" if @debug_mode
|
148
|
+
if command[:owners_only]
|
149
|
+
unless @config[:owners].include?(event.user.id)
|
150
|
+
event.channel.send_message('', false,
|
151
|
+
Helper.error_embed(
|
152
|
+
error: "You don't have permission for that!\nOnly owners are allowed to access this command.",
|
153
|
+
footer: "Command: `#{event.message.content}`",
|
154
|
+
colour: 0xFA0E30,
|
155
|
+
code_error: false
|
156
|
+
)
|
157
|
+
)
|
158
|
+
puts 'Were returning!'
|
159
|
+
@finished = true
|
160
|
+
next
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# If the settings are to delete activating messages, then do that.
|
165
|
+
# I'm *hoping* this doesn't cause issues with argument extraction.
|
166
|
+
event.message.delete if command[:delete_activator]
|
167
|
+
|
168
|
+
# If the command is only for use in servers, display error and abort.
|
169
|
+
if command[:server_only] && event.channel.private?
|
170
|
+
# For selfbots, a fancy embed will be used. WIP.
|
171
|
+
if @config[:selfbot]
|
172
|
+
event.channel.send_embed do |embed|
|
173
|
+
embed.colour = 0x221461
|
174
|
+
embed.title = '❌ An error has occured!'
|
175
|
+
embed.description = 'This command can only be used in servers!'
|
176
|
+
embed.footer = Discordrb::Webhooks::EmbedFooter.new(text: "Command: '#{event.message.content}'")
|
177
|
+
end
|
178
|
+
else
|
179
|
+
# If its not a selfbot, an ordinary message will be shown, may be changed to embed later.
|
180
|
+
event.respond('❌ This command will only work in servers!')
|
181
|
+
end
|
182
|
+
# Abort!
|
183
|
+
@finished = true
|
184
|
+
next
|
185
|
+
end
|
186
|
+
|
187
|
+
# If the user is a bot and the command is set to not pass bots OR the user is a bot and the global config is to not parse bots...
|
188
|
+
# ...then abort :3
|
189
|
+
if (event.user.bot_account? && command[:parse_bots] == false) || (event.user.bot_account? && @config[:parse_bots] == false)
|
190
|
+
# Abort!
|
191
|
+
@finished = true
|
192
|
+
next
|
193
|
+
end
|
194
|
+
|
195
|
+
# If the config is setup to show typing messages, then do so.
|
196
|
+
event.channel.start_typing if command[:typing]
|
197
|
+
|
198
|
+
args = event.message.content.split(' ')
|
199
|
+
# Parse args if args exist !
|
200
|
+
begin
|
201
|
+
spaces = 1
|
202
|
+
# Prefixes with spaces are special and need to be parsed differently : )
|
203
|
+
if prefix.include? " "
|
204
|
+
spaces += prefix.count(' ')
|
205
|
+
args = event.message.content.slice!(args[0].size + args[1].size + spaces, event.message.content.size)
|
206
|
+
else
|
207
|
+
args = event.message.content.slice!(args[0].size + spaces, event.message.content.size)
|
208
|
+
end
|
209
|
+
# Split the argmuents into an array for easy usage but keep the raw args !!
|
210
|
+
rawargs = args
|
211
|
+
args = args.split(/ /)
|
212
|
+
rescue NoMethodError # Not the most elegant solution but it'll do. TODO: Make a more elegant solution.
|
213
|
+
args = []
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
# Check the number of args for the command.
|
218
|
+
unless command[:max_args].nil?
|
219
|
+
if command[:max_args] > 0 && args.length > command[:max_args]
|
220
|
+
event.channel.send_message('', false,
|
221
|
+
Helper.error_embed(
|
222
|
+
error: "Too many arguments! \nMax arguments: `#{command[:max_args]}`",
|
223
|
+
footer: "Command: `#{event.message.content}`",
|
224
|
+
colour: 0xFA0E30,
|
225
|
+
code_error: false
|
226
|
+
)
|
227
|
+
)
|
228
|
+
@finished = true
|
229
|
+
break
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
unless command[:required_permissions].nil?
|
234
|
+
command[:required_permissions].each { |x|
|
235
|
+
unless event.user.on(event.server).permission?(x,event.channel) || (command[:owner_override] && @config[:owners].include?(event.user.id) )
|
236
|
+
event.channel.send_message('', false,
|
237
|
+
Helper.error_embed(
|
238
|
+
error: "You don't have permission for that!\nPermission required: `#{x.to_s}`",
|
239
|
+
footer: "Command: `#{event.message.content}`",
|
240
|
+
colour: 0xFA0E30,
|
241
|
+
code_error: false
|
242
|
+
)
|
243
|
+
)
|
244
|
+
@finished = true
|
245
|
+
break
|
246
|
+
end
|
247
|
+
}
|
248
|
+
end
|
249
|
+
|
250
|
+
unless @finished
|
251
|
+
# If the command is configured to catch all errors, thy shall be done.
|
252
|
+
if !command[:catch_errors] || @config['catch_errors']
|
253
|
+
# Run the command code!
|
254
|
+
command[:code].call(event, args, rawargs)
|
255
|
+
else
|
256
|
+
# Run the command code, but catch all errors and output accordingly.
|
257
|
+
begin
|
258
|
+
command[:code].call(event, args, rawargs)
|
259
|
+
rescue Exception => e
|
260
|
+
event.respond("❌ An error has occured!! ```ruby\n#{e}```Please contact the bot owner with the above message for assistance.")
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# All done here.
|
266
|
+
puts "Finished!! Executed command: #{@chosen}" if @debug_mode
|
267
|
+
@command = command
|
268
|
+
@event = event
|
269
|
+
@args = args
|
270
|
+
@rawargs = rawargs
|
271
|
+
@finished = true
|
272
|
+
break
|
273
|
+
}
|
274
|
+
end
|
275
|
+
}
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
data/lib/helper.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
class CommandrbBot
|
2
|
-
module Helper
|
3
|
-
def self.error_embed(error: nil, footer: nil, colour: nil, color: nil, code_error: true)
|
4
|
-
if error.nil? or footer.nil?
|
5
|
-
raise 'Invalid arguments for Helper.error_embed!'
|
6
|
-
else
|
7
|
-
if color.nil? and colour.nil?
|
8
|
-
colour = 0x22ef1f
|
9
|
-
end
|
10
|
-
Discordrb::Webhooks::Embed.new(
|
11
|
-
title: '❌ An error has occured!',
|
12
|
-
description: code_error ? "```ruby\n#{error}```" : error,
|
13
|
-
colour: colour || color,
|
14
|
-
footer: Discordrb::Webhooks::EmbedFooter.new(text: footer)
|
15
|
-
)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.avatar_embed(color: nil, colour: nil, url: nil, username: nil, time: Time.now.getutc.asctime)
|
20
|
-
if url.nil?
|
21
|
-
raise 'Invalid arguments for Helper.avatar_embed!'
|
22
|
-
else
|
23
|
-
if color.nil? and colour.nil?
|
24
|
-
colour = 0x22ef1f
|
25
|
-
end
|
26
|
-
username = username.nil? ? 'Unknown User' : username
|
27
|
-
Discordrb::Webhooks::Embed.new(
|
28
|
-
colour: colour || color,
|
29
|
-
image: Discordrb::Webhooks::EmbedImage.new(url: url),
|
30
|
-
author: Discordrb::Webhooks::EmbedAuthor.new(name: "Avatar for #{username}", url: url),
|
31
|
-
footer: Discordrb::Webhooks::EmbedFooter.new(text: "Avatar correct as of #{time}")
|
32
|
-
)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
1
|
+
class CommandrbBot
|
2
|
+
module Helper
|
3
|
+
def self.error_embed(error: nil, footer: nil, colour: nil, color: nil, code_error: true)
|
4
|
+
if error.nil? or footer.nil?
|
5
|
+
raise 'Invalid arguments for Helper.error_embed!'
|
6
|
+
else
|
7
|
+
if color.nil? and colour.nil?
|
8
|
+
colour = 0x22ef1f
|
9
|
+
end
|
10
|
+
Discordrb::Webhooks::Embed.new(
|
11
|
+
title: '❌ An error has occured!',
|
12
|
+
description: code_error ? "```ruby\n#{error}```" : error,
|
13
|
+
colour: colour || color,
|
14
|
+
footer: Discordrb::Webhooks::EmbedFooter.new(text: footer)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.avatar_embed(color: nil, colour: nil, url: nil, username: nil, time: Time.now.getutc.asctime)
|
20
|
+
if url.nil?
|
21
|
+
raise 'Invalid arguments for Helper.avatar_embed!'
|
22
|
+
else
|
23
|
+
if color.nil? and colour.nil?
|
24
|
+
colour = 0x22ef1f
|
25
|
+
end
|
26
|
+
username = username.nil? ? 'Unknown User' : username
|
27
|
+
Discordrb::Webhooks::Embed.new(
|
28
|
+
colour: colour || color,
|
29
|
+
image: Discordrb::Webhooks::EmbedImage.new(url: url),
|
30
|
+
author: Discordrb::Webhooks::EmbedAuthor.new(name: "Avatar for #{username}", url: url),
|
31
|
+
footer: Discordrb::Webhooks::EmbedFooter.new(text: "Avatar correct as of #{time}")
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commandrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erisa Komuro (Seriel)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discordrb
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.6.
|
61
|
+
rubygems_version: 2.6.13
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Commandrb
|