Class: Emissary

Inherits:
Object
  • Object
show all
Defined in:
lib/emissary.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmissary

Returns a new instance of Emissary.



24
25
26
27
28
# File 'lib/emissary.rb', line 24

def initialize
  @loggrs = {}
  read_loggrs
  init_bot
end

Class Attribute Details

.bot_tokenObject

Returns the value of attribute bot_token.



8
9
10
# File 'lib/emissary.rb', line 8

def bot_token
  @bot_token
end

.header_formatObject

Returns the value of attribute header_format.



8
9
10
# File 'lib/emissary.rb', line 8

def header_format
  @header_format
end

.json_file_pathObject

Returns the value of attribute json_file_path.



8
9
10
# File 'lib/emissary.rb', line 8

def json_file_path
  @json_file_path
end

.server_nameObject

Returns the value of attribute server_name.



8
9
10
# File 'lib/emissary.rb', line 8

def server_name
  @server_name
end

.trello_member_tokenObject

Returns the value of attribute trello_member_token.



8
9
10
# File 'lib/emissary.rb', line 8

def trello_member_token
  @trello_member_token
end

.trello_public_keyObject

Returns the value of attribute trello_public_key.



8
9
10
# File 'lib/emissary.rb', line 8

def trello_public_key
  @trello_public_key
end

.webhooks_urlObject

Returns the value of attribute webhooks_url.



8
9
10
# File 'lib/emissary.rb', line 8

def webhooks_url
  @webhooks_url
end

Instance Attribute Details

#loggrsObject

Returns the value of attribute loggrs.



18
19
20
# File 'lib/emissary.rb', line 18

def loggrs
  @loggrs
end

Class Method Details

.configure(&block) ⇒ Object



9
10
11
# File 'lib/emissary.rb', line 9

def configure(&block)
  block.call(self)
end

.headerObject



13
14
15
# File 'lib/emissary.rb', line 13

def header
  header_format.gsub("{title}", server_name)
end

Instance Method Details

#configure(&block) ⇒ Object



20
21
22
# File 'lib/emissary.rb', line 20

def configure(&block)
  block.call(self)
end

#get_messageObject



30
31
# File 'lib/emissary.rb', line 30

def get_message
end

#init_botObject



47
48
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
# File 'lib/emissary.rb', line 47

def init_bot


  bot = Discordrb::Commands::CommandBot.new token: Emissary.bot_token, prefix: '!'

  bot.command :emy do |event, *args|
    puts "===> Receiving request bot"
    if args.count > 0
      command = args[0]
      loggr = loggrs[command]
      unless loggr.nil?
        if loggr.bash_command == ""
          if args.count > 1
            if args[1] == "report"
              loggr.report
              "#{Emissary.header}\nGenerating Last Report"
            elsif args[1] == "fetch"
              loggr.fetch
              "#{Emissary.header}\nFetching Report"
            elsif args[1] == "clear"
              loggr.clear
              "#{Emissary.header}\nClearing Report"
            elsif args[1] == "last"
              loggr.message_to_chat loggr.last_message
            elsif ![nil, ""].include?(args[1]) && args[1].include?(loggr.alias)
              if args.count > 2
                if args[2] == "trello"
                  card_url = loggr.create_trello_card loggr.message_by_id(args[1])
                  "#{Emissary.header}\n**Trello card added.**\n#{card_url}"
                end
              else
                loggr.message_to_chat loggr.message_by_id(args[1])
              end
            else
              "#{Emissary.header}\nWrong arguments for command #{command}:\n**last**: Last Message.\n**report**: Generate report before time.\n**{id}**: Message with ID"
            end
          else
            "#{Emissary.header}\nYou didn't write an argument:\n**last**: Last Message.\n**report**: Generate report before time.\n**{id}**: Message with ID"
          end
        else
          "#{Emissary.header}\n#{loggr.syscall}"
        end
      else
        "#{Emissary.header}\nCommand not found: #{command}"
      end
    else
      "#{Emissary.header}\nYou didn't write a command"
    end
  end

  bot.run
end

#read_loggrsObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/emissary.rb', line 36

def read_loggrs

  file = File.open Emissary.json_file_path
  raw_loggrs = JSON.load file
  raw_loggrs.each do |k, v|
    loggr = Loggr.new v
    loggrs[loggr.command] = loggr
  end
  file.close
end

#respondObject



33
34
# File 'lib/emissary.rb', line 33

def respond
end