-
Notifications
You must be signed in to change notification settings - Fork 0
/
commander.ex
155 lines (128 loc) · 4.02 KB
/
commander.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
defmodule App.Commander do
@bot_name Application.get_env(:app, :bot_name)
# Code injectors
defmacro __using__(_opts) do
quote do
require Logger
import App.Commander
alias Nadia.Model
alias Nadia.Model.InlineQueryResult
end
end
# Sender Macros
defmacro answer_callback_query(options \\ []) do
quote bind_quoted: [options: options] do
Nadia.answer_callback_query var!(update).callback_query.id, options
end
end
defmacro answer_inline_query(results, options \\ []) do
quote bind_quoted: [results: results, options: options] do
Nadia.answer_inline_query var!(update).inline_query.id, results, options
end
end
defmacro send_audio(audio, options \\ []) do
quote bind_quoted: [audio: audio, options: options] do
Nadia.send_audio get_chat_id(), audio, options
end
end
defmacro send_chat_action(action) do
quote bind_quoted: [action: action] do
Nadia.send_chat_action get_chat_id(), action
end
end
defmacro send_contact(phone_number, first_name, options \\ []) do
quote bind_quoted: [phone_number: phone_number, first_name: first_name,
options: options] do
Nadia.send_contact get_chat_id(), phone_number, first_name, options
end
end
defmacro send_document(document, options \\ []) do
quote bind_quoted: [document: document, options: options] do
Nadia.send_document get_chat_id(), document, options
end
end
defmacro send_location(latitude, longitude, options \\ []) do
quote bind_quoted: [latitude: latitude, longitude: longitude,
options: options] do
Nadia.send_location get_chat_id(), latitude, longitude, options
end
end
defmacro send_message(text, options \\ []) do
quote bind_quoted: [text: text, options: options] do
Nadia.send_message get_chat_id(), text, options
end
end
defmacro send_photo(photo, options \\ []) do
quote bind_quoted: [photo: photo, options: options] do
Nadia.send_photo get_chat_id(), photo, options
end
end
defmacro send_sticker(sticker, options \\ []) do
quote bind_quoted: [sticker: sticker, options: options] do
Nadia.send_sticker get_chat_id(), sticker, options
end
end
defmacro send_venue(latitude, longitude, title, address, options \\ []) do
quote bind_quoted: [latitude: latitude, longitude: longitude,
title: title, address: address, options: options] do
Nadia.send_venue get_chat_id(), latitude, longitude, title, address, options
end
end
defmacro send_video(video, options \\ []) do
quote bind_quoted: [video: video, options: options] do
Nadia.send_video get_chat_id(), video, options
end
end
defmacro send_voice(voice, options \\ []) do
quote bind_quoted: [voice: voice, options: options] do
Nadia.send_voice get_chat_id(), voice, options
end
end
# Action Macros
defmacro forward_message(chat_id) do
quote bind_quoted: [chat_id: chat_id] do
Nadia.forward_message chat_id, get_chat_id(), var!(update).message.message_id
end
end
defmacro get_chat do
quote do
Nadia.get_chat get_chat_id()
end
end
defmacro get_chat_administrators do
quote do
Nadia.get_chat_administrators get_chat_id()
end
end
defmacro get_chat_member(user_id) do
quote bind_quoted: [user_id: user_id] do
Nadia.get_chat_member get_chat_id(), user_id
end
end
defmacro get_chat_members_count do
quote do
Nadia.get_chat_members_count get_chat_id()
end
end
defmacro kick_chat_member(user_id) do
quote bind_quoted: [user_id: user_id] do
Nadia.kick_chat_member get_chat_id(), user_id
end
end
defmacro leave_chat do
quote do
Nadia.leave_chat get_chat_id()
end
end
defmacro unban_chat_member(user_id) do
quote bind_quoted: [user_id: user_id] do
Nadia.unban_chat_member get_chat_id(), user_id
end
end
# Helpers
defmacro get_chat_id do
quote do
App.Telegram.get_chat_id var!(update)
end
end
end