Module: CommandrbBot::Helper

Defined in:
lib/helper.rb

Class Method Summary collapse

Class Method Details

.avatar_embed(color: nil, colour: nil, url: nil, username: nil, time: Time.now.getutc.asctime) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/helper.rb', line 19

def self.avatar_embed(color: nil, colour: nil, url: nil, username: nil, time: Time.now.getutc.asctime)
  if url.nil?
    raise 'Invalid arguments for Helper.avatar_embed!'
  else
    if color.nil? and colour.nil?
      colour = 0x22ef1f
    end
    username = username.nil? ? 'Unknown User' : username
    Discordrb::Webhooks::Embed.new(
        colour: colour || color,
        image: Discordrb::Webhooks::EmbedImage.new(url: url),
        author: Discordrb::Webhooks::EmbedAuthor.new(name: "Avatar for #{username}", url: url),
        footer: Discordrb::Webhooks::EmbedFooter.new(text: "Avatar correct as of #{time}")
    )
  end
end

.error_embed(error: nil, footer: nil, colour: nil, color: nil, code_error: true) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/helper.rb', line 3

def self.error_embed(error: nil, footer: nil, colour: nil, color: nil, code_error: true)
  if error.nil? or footer.nil?
    raise 'Invalid arguments for Helper.error_embed!'
  else
    if color.nil? and colour.nil?
      colour = 0x22ef1f
    end
    Discordrb::Webhooks::Embed.new(
        title:  '❌ An error has occured!',
        description: code_error ?  "```ruby\n#{error}```" :  error,
        colour: colour || color,
        footer: Discordrb::Webhooks::EmbedFooter.new(text: footer)
    )
  end
end