Class: Lita::Handlers::Karma::Chat
- Inherits:
-
Lita::Handler
- Object
- Lita::Handler
- Lita::Handlers::Karma::Chat
- Defined in:
- lib/lita/handlers/karma/chat.rb
Overview
Tracks karma points for arbitrary terms.
Instance Method Summary collapse
- #check(response) ⇒ Object
- #decrement(response) ⇒ Object
- #define_routes(payload) ⇒ Object
- #delete(response) ⇒ Object
- #increment(response) ⇒ Object
- #link(response) ⇒ Object
- #list_best(response) ⇒ Object
- #list_worst(response) ⇒ Object
- #modified(response) ⇒ Object
- #unlink(response) ⇒ Object
Instance Method Details
#check(response) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lita/handlers/karma/chat.rb', line 21 def check(response) seen = Set.new output = response.matches.map do |match| term = get_term(match[0]) next if seen.include?(term) seen << term term.check end.compact response.reply output.join("; ") end |
#decrement(response) ⇒ Object
17 18 19 |
# File 'lib/lita/handlers/karma/chat.rb', line 17 def decrement(response) modify(response, :decrement) end |
#define_routes(payload) ⇒ Object
8 9 10 11 |
# File 'lib/lita/handlers/karma/chat.rb', line 8 def define_routes(payload) define_static_routes define_dynamic_routes(config.term_pattern.source) end |
#delete(response) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/lita/handlers/karma/chat.rb', line 85 def delete(response) term = Term.new(robot, response..body.sub(/^karma delete /, ""), normalize: false) if term.delete response.reply t("delete_success", term: term) end end |
#increment(response) ⇒ Object
13 14 15 |
# File 'lib/lita/handlers/karma/chat.rb', line 13 def increment(response) modify(response, :increment) end |
#link(response) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lita/handlers/karma/chat.rb', line 42 def link(response) response.matches.each do |match| term1 = get_term(match[0]) term2 = get_term(match[1]) result = term1.link(term2) case result when Integer response.reply t("threshold_not_satisfied", threshold: result) when true response.reply t("link_success", source: term2, target: term1) else response.reply t("already_linked", source: term2, target: term1) end end end |
#list_best(response) ⇒ Object
34 35 36 |
# File 'lib/lita/handlers/karma/chat.rb', line 34 def list_best(response) list(response, :list_best) end |
#list_worst(response) ⇒ Object
38 39 40 |
# File 'lib/lita/handlers/karma/chat.rb', line 38 def list_worst(response) list(response, :list_worst) end |
#modified(response) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lita/handlers/karma/chat.rb', line 73 def modified(response) term = get_term(response.args[1]) users = term.modified if users.empty? response.reply t("never_modified", term: term) else response.reply users.map(&:name).join(", ") end end |
#unlink(response) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lita/handlers/karma/chat.rb', line 60 def unlink(response) response.matches.each do |match| term1 = get_term(match[0]) term2 = get_term(match[1]) if term1.unlink(term2) response.reply t("unlink_success", source: term2, target: term1) else response.reply t("already_unlinked", source: term2, target: term1) end end end |