Class: Lita::Handlers::Doc
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Doc
- Defined in:
- lib/lita/handlers/doc.rb
Constant Summary collapse
- COMMANDS =
{ how: { regex: /^how do i +([^\?]+)\??$/, command: "how do i [do thing]", description: "Shows where to find doc." }, show: { regex: /^doc +(.+)$/, command: "doc [name]", description: "Shows where to find doc." }, remove: { regex: /^doc:remove +(.+)$/, command: "docs:remove [name]", description: "Remove doc." }, list: { regex: /^docs(:all)?$/, command: "docs:all", description: "Lists all known docs." }, help: { regex: /^docs[: ]help/, command: "docs help OR docs:help", description: "Shows all doc commands." }, add: { regex: /^doc:new (.+) (http:\/\/.+)$/, command: "doc:new [name] [url]", description: "Adds doc." }, wtf: { regex: /^docs ((?!help).)*$/ } }
Class Method Summary collapse
Instance Method Summary collapse
- #add_doc(response) ⇒ Object
- #doc_names ⇒ Object
- #help(response) ⇒ Object
- #list_docs(response) ⇒ Object
- #remove_doc(response) ⇒ Object
- #show_doc(response) ⇒ Object
- #wtf?(response) ⇒ Boolean
Class Method Details
.help_for(name) ⇒ Object
44 45 46 |
# File 'lib/lita/handlers/doc.rb', line 44 def self.help_for(name) { COMMANDS[name][:command] => COMMANDS[name][:description] } end |
.regex_for(name) ⇒ Object
40 41 42 |
# File 'lib/lita/handlers/doc.rb', line 40 def self.regex_for(name) COMMANDS[name][:regex] end |
Instance Method Details
#add_doc(response) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/lita/handlers/doc.rb', line 90 def add_doc(response) name = response.match_data[1].strip location = response.match_data[2].strip if name && location redis.rpush :docs, name redis.set name, location response.reply "Sweet, added #{name} to docs list." else response.reply "Looks like you did something wrong, please input in the form `.doc:add [doc explanation] [doc_url]`. Note: doc_url must begin with `http://`" end end |
#doc_names ⇒ Object
117 118 119 |
# File 'lib/lita/handlers/doc.rb', line 117 def doc_names redis.lrange :docs, 0, -1 end |
#help(response) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/lita/handlers/doc.rb', line 56 def help(response) msg = "```\n" COMMANDS.each do |key, value| msg += "#{value[:command]} - #{value[:description]}\n" if value[:command] end msg += "```" response.reply msg end |
#list_docs(response) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lita/handlers/doc.rb', line 76 def list_docs(response) docs = doc_names msg = "" if docs.empty? response.reply "No docs found." else docs.each do |doc| msg += "`#{doc}` - #{redis.get doc}\n" end response.reply msg end end |
#remove_doc(response) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lita/handlers/doc.rb', line 102 def remove_doc(response) name = response.match_data[1].strip if doc_names.include?(name) redis.lrem :docs, 0, name redis.del name response.reply "Boom! Removed #{name} from docs list." else response.reply "I don't have any information for #{name}, so... mission accomplished?" end end |
#show_doc(response) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lita/handlers/doc.rb', line 65 def show_doc(response) name = response.match_data[1].strip res = redis.get name if res response.reply "Go to #{res} to find out." else response.reply "I don't know where to find that information. Figure it out for me, then add it to my memory please: .doc:add #{name} [destination_url]" end end |
#wtf?(response) ⇒ Boolean
113 114 115 |
# File 'lib/lita/handlers/doc.rb', line 113 def wtf?(response) response.reply "I don't know what you mean. Have you been drinking? Try `.docs:help`" end |