-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ex
64 lines (47 loc) · 1.35 KB
/
commands.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
defmodule App.Commands do
use App.Router
use App.Commander
alias App.Stats
@bot_name Application.get_env(:app, :bot_name)
command "help" do
message = """
<b>Showing Help</b>
<b>Commands</b>
<i>For normal commands, just send me a message.</i>
/help
<b>Inline Commands</b>
<i>For inline commands, type "@#{@bot_name}" then the command.</i>
<code>/hex [package_name]</code>
<b>Channels</b>
@elixir_forum - <i>Elixir forum</i>
@rElixir - <i>Elixir subreddit</i>
@elixirstatus - <i>Elixirstatus</i>
"""
{:ok, _} = send_message message, parse_mode: "html"
end
inline_query_command "hex" do
"/hex" <> query = update.inline_query.query
|> String.trim
{:ok, packages} = App.Hex.packages query
results = packages
|> Enum.take(20)
|> Enum.map(&App.Hex.package_to_inline_query_result/1)
case answer_inline_query(results) do
:ok -> nil
{:error, %Model.Error{reason: reason}} ->
Logger.log :error, "Errored with query '#{query}'"
Logger.log :error, "Reason: #{reason}"
end
end
inline_query do
answer_inline_query []
Stats.increment("inline_query.unmatched")
end
message do
send_message """
Sorry, I didn't undestand.
Try running the /help command.
"""
Stats.increment("message.unmatched")
end
end