Class: Emissary
- Inherits:
-
Object
- Object
- Emissary
- Defined in:
- lib/emissary.rb
Class Attribute Summary collapse
-
.bot_token ⇒ Object
Returns the value of attribute bot_token.
-
.header_format ⇒ Object
Returns the value of attribute header_format.
-
.json_file_path ⇒ Object
Returns the value of attribute json_file_path.
-
.server_name ⇒ Object
Returns the value of attribute server_name.
-
.trello_member_token ⇒ Object
Returns the value of attribute trello_member_token.
-
.trello_public_key ⇒ Object
Returns the value of attribute trello_public_key.
-
.webhooks_url ⇒ Object
Returns the value of attribute webhooks_url.
Instance Attribute Summary collapse
-
#loggrs ⇒ Object
Returns the value of attribute loggrs.
Class Method Summary collapse
Instance Method Summary collapse
- #configure(&block) ⇒ Object
- #get_message ⇒ Object
- #init_bot ⇒ Object
-
#initialize ⇒ Emissary
constructor
A new instance of Emissary.
- #read_loggrs ⇒ Object
- #respond ⇒ Object
Constructor Details
#initialize ⇒ Emissary
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_token ⇒ Object
Returns the value of attribute bot_token.
8 9 10 |
# File 'lib/emissary.rb', line 8 def bot_token @bot_token end |
.header_format ⇒ Object
Returns the value of attribute header_format.
8 9 10 |
# File 'lib/emissary.rb', line 8 def header_format @header_format end |
.json_file_path ⇒ Object
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_name ⇒ Object
Returns the value of attribute server_name.
8 9 10 |
# File 'lib/emissary.rb', line 8 def server_name @server_name end |
.trello_member_token ⇒ Object
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_key ⇒ Object
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_url ⇒ Object
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
#loggrs ⇒ Object
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 |
.header ⇒ Object
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_message ⇒ Object
30 31 |
# File 'lib/emissary.rb', line 30 def end |
#init_bot ⇒ Object
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. loggr. 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.(args[1]) "#{Emissary.header}\n**Trello card added.**\n#{card_url}" end else loggr. loggr.(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_loggrs ⇒ Object
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 |
#respond ⇒ Object
33 34 |
# File 'lib/emissary.rb', line 33 def respond end |