├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── bot
├── seedbot.lua
└── utils.lua
├── data
├── .gitkeep
└── photos
│ └── .gitkeep
├── groups
├── all
│ └── [group_id]all.txt
├── lists
│ └── [group_id]memberlist.txt
└── logs
│ ├── [group_id]log.txt
│ └── [group_id]stats.txt
├── launch.sh
├── libs
├── JSON.lua
├── dkjson.lua
├── mimetype.lua
└── redis.lua
├── patches
└── disable-python-and-libjansson.patch
└── plugins
├── Fabanhammer.lua
├── Welcome.lua
├── addplug.lua
├── admin.lua
├── all.lua
├── anti_spam.lua
├── antisticker.lua
├── antitag.lua
├── arabic_lock.lua
├── banhammer.lua
├── broadcast.lua
├── chating.lua
├── download_media.lua
├── echoall.lua
├── echofile.lua
├── expire.lua
├── feedback.lua
├── get.lua
├── helpen.lua
├── info.lua
├── ingroup.lua
├── inpm.lua
├── inrealm.lua
├── invite.lua
├── invsudo.lua
├── joining.lua
├── leave_ban.lua
├── linkpv.lua
├── lock_ads.lua
├── lock_chat.lua
├── lock_join.lua
├── onservice.lua
├── owners.lua
├── p.lua
├── plugmanager.lua
├── quran.lua
├── set.lua
├── stats.lua
├── tagall.lua
├── terminal.lua
└── xy.lua
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Lua sources
2 | luac.out
3 |
4 | # luarocks build files
5 | *.src.rock
6 | *.zip
7 | *.tar.gz
8 |
9 | # Object files
10 | *.o
11 | *.os
12 | *.ko
13 | *.obj
14 | *.elf
15 |
16 | # Precompiled Headers
17 | *.gch
18 | *.pch
19 |
20 | # Libraries
21 | *.lib
22 | *.a
23 | *.la
24 | *.lo
25 | *.def
26 | *.exp
27 |
28 | # Shared objects (inc. Windows DLLs)
29 | *.dll
30 | *.so
31 | *.so.*
32 | *.dylib
33 |
34 | # Executables
35 | *.exe
36 | *.out
37 | *.app
38 | *.i*86
39 | *.x86_64
40 | *.hex
41 |
42 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "tg"]
2 | path = tg
3 | url = https://github.com/BossTG/tg-1
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [BossTG](https://telegram.me/BossTG)
2 |
3 |
4 | **An advance and powerful Administration bot based on [TeleSeed](https://github.com/seedteam/TeleSeed)
5 | # Features
6 |
7 | * **A powerful Anti spam with custom sensitivity For each group**
8 | * **Multiple Realms(admin groups)**
9 | * **recalcitrant to any kind of spamming(Xy bots,name|photo changers and ...)**
10 | * **Global ban**
11 | * **Broadcast to all groups**
12 | * **Group link**
13 | * **Kick,ban and unban by reply**
14 | * **Groups,ban and global bans list**
15 | * **Logging anything that happens in group !**
16 | * **Invite by username**
17 | * **Group administration in bots private**
18 | * **Only mods,owner and admin can add bots**
19 | * **Arabic lock**
20 | * **And ...**
21 |
22 | ### One command
23 | To install everything in one command on debian-based distros, use: (useful for VPS deployment)
24 | ```sh
25 | #https://github.com/yagop/telegram-bot/wiki/Installation
26 | sudo apt-get update; sudo apt-get upgrade -y --force-yes; sudo apt-get dist-upgrade -y --force-yes; sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson* libpython-dev make unzip git redis-server g++ -y --force-yes && git clone https://github.com/BossTG/BossTG.git && cd BossTG && chmod +x launch.sh && ./launch.sh install && ./launch.sh
27 | ```
28 |
29 | # sudoers
30 |
31 | * [HaMeD](telegram.me/tehran980) = Sudo
32 | * [amin](telegram.me/Boy_Crazy) = Sudo
33 |
34 | # Special thanks to
35 |
36 | * [Shervin](telegram.me/shervin_hacker)
37 | * [Mrhalix](telegram.me/Mrhalix)
38 |
39 |
40 | # [admin](telegram.me/tehran980)
41 | # Pull request
42 | * you can send pull request for edit and add plugin
43 |
44 | # Channel BossTG
45 | * [BossTG](telegram.me/BossTGch)
46 |
47 | # my channel
48 |
49 | * [android](telegram.me/newsandroid)
50 |
--------------------------------------------------------------------------------
/bot/seedbot.lua:
--------------------------------------------------------------------------------
1 | package.path = package.path .. ';.luarocks/share/lua/5.2/?.lua'
2 | ..';.luarocks/share/lua/5.2/?/init.lua'
3 | package.cpath = package.cpath .. ';.luarocks/lib/lua/5.2/?.so'
4 |
5 | require("./bot/utils")
6 |
7 | VERSION = '2'
8 |
9 | -- This function is called when tg receive a msg
10 | function on_msg_receive (msg)
11 | if not started then
12 | return
13 | end
14 |
15 | local receiver = get_receiver(msg)
16 | print (receiver)
17 |
18 | --vardump(msg)
19 | msg = pre_process_service_msg(msg)
20 | if msg_valid(msg) then
21 | msg = pre_process_msg(msg)
22 | if msg then
23 | match_plugins(msg)
24 | if redis:get("bot:markread") then
25 | if redis:get("bot:markread") == "on" then
26 | mark_read(receiver, ok_cb, false)
27 | end
28 | end
29 | end
30 | end
31 | end
32 |
33 | function ok_cb(extra, success, result)
34 | end
35 |
36 | function on_binlog_replay_end()
37 | started = true
38 | postpone (cron_plugins, false, 60*5.0)
39 |
40 | _config = load_config()
41 |
42 | -- load plugins
43 | plugins = {}
44 | load_plugins()
45 | end
46 |
47 | function msg_valid(msg)
48 | -- Don't process outgoing messages
49 | if msg.out then
50 | print('\27[36mNot valid: msg from us\27[39m')
51 | return false
52 | end
53 |
54 | -- Before bot was started
55 | if msg.date < now then
56 | print('\27[36mNot valid: old msg\27[39m')
57 | return false
58 | end
59 |
60 | if msg.unread == 0 then
61 | print('\27[36mNot valid: readed\27[39m')
62 | return false
63 | end
64 |
65 | if not msg.to.id then
66 | print('\27[36mNot valid: To id not provided\27[39m')
67 | return false
68 | end
69 |
70 | if not msg.from.id then
71 | print('\27[36mNot valid: From id not provided\27[39m')
72 | return false
73 | end
74 |
75 | if msg.from.id == our_id then
76 | print('\27[36mNot valid: Msg from our id\27[39m')
77 | return false
78 | end
79 |
80 | if msg.to.type == 'encr_chat' then
81 | print('\27[36mNot valid: Encrypted chat\27[39m')
82 | return false
83 | end
84 |
85 | if msg.from.id == 777000 then
86 | local login_group_id = 1
87 | --It will send login codes to this chat
88 | send_large_msg('chat#id'..login_group_id, msg.text)
89 | end
90 |
91 | return true
92 | end
93 |
94 | --
95 | function pre_process_service_msg(msg)
96 | if msg.service then
97 | local action = msg.action or {type=""}
98 | -- Double ! to discriminate of normal actions
99 | msg.text = "!!tgservice " .. action.type
100 |
101 | -- wipe the data to allow the bot to read service messages
102 | if msg.out then
103 | msg.out = false
104 | end
105 | if msg.from.id == our_id then
106 | msg.from.id = 0
107 | end
108 | end
109 | return msg
110 | end
111 |
112 | -- Apply plugin.pre_process function
113 | function pre_process_msg(msg)
114 | for name,plugin in pairs(plugins) do
115 | if plugin.pre_process and msg then
116 | print('Preprocess', name)
117 | msg = plugin.pre_process(msg)
118 | end
119 | end
120 |
121 | return msg
122 | end
123 |
124 | -- Go over enabled plugins patterns.
125 | function match_plugins(msg)
126 | for name, plugin in pairs(plugins) do
127 | match_plugin(plugin, name, msg)
128 | end
129 | end
130 |
131 | -- Check if plugin is on _config.disabled_plugin_on_chat table
132 | local function is_plugin_disabled_on_chat(plugin_name, receiver)
133 | local disabled_chats = _config.disabled_plugin_on_chat
134 | -- Table exists and chat has disabled plugins
135 | if disabled_chats and disabled_chats[receiver] then
136 | -- Checks if plugin is disabled on this chat
137 | for disabled_plugin,disabled in pairs(disabled_chats[receiver]) do
138 | if disabled_plugin == plugin_name and disabled then
139 | local warning = 'Plugin '..disabled_plugin..' is disabled on this chat'
140 | print(warning)
141 | send_msg(receiver, warning, ok_cb, false)
142 | return true
143 | end
144 | end
145 | end
146 | return false
147 | end
148 |
149 | function match_plugin(plugin, plugin_name, msg)
150 | local receiver = get_receiver(msg)
151 |
152 | -- Go over patterns. If one matches it's enough.
153 | for k, pattern in pairs(plugin.patterns) do
154 | local matches = match_pattern(pattern, msg.text)
155 | if matches then
156 | print("msg matches: ", pattern)
157 |
158 | if is_plugin_disabled_on_chat(plugin_name, receiver) then
159 | return nil
160 | end
161 | -- Function exists
162 | if plugin.run then
163 | -- If plugin is for privileged users only
164 | if not warns_user_not_allowed(plugin, msg) then
165 | local result = plugin.run(msg, matches)
166 | if result then
167 | send_large_msg(receiver, result)
168 | end
169 | end
170 | end
171 | -- One patterns matches
172 | return
173 | end
174 | end
175 | end
176 |
177 | -- DEPRECATED, use send_large_msg(destination, text)
178 | function _send_msg(destination, text)
179 | send_large_msg(destination, text)
180 | end
181 |
182 | -- Save the content of _config to config.lua
183 | function save_config( )
184 | serialize_to_file(_config, './data/config.lua')
185 | print ('saved config into ./data/config.lua')
186 | end
187 |
188 | -- Returns the config from config.lua file.
189 | -- If file doesn't exist, create it.
190 | function load_config( )
191 | local f = io.open('./data/config.lua', "r")
192 | -- If config.lua doesn't exist
193 | if not f then
194 | print ("Created new config file: data/config.lua")
195 | create_config()
196 | else
197 | f:close()
198 | end
199 | local config = loadfile ("./data/config.lua")()
200 | for v,user in pairs(config.sudo_users) do
201 | print("Allowed user: " .. user)
202 | end
203 | return config
204 | end
205 |
206 | -- Create a basic config.json file and saves it.
207 | function create_config( )
208 | -- A simple config with basic plugins and ourselves as privileged user
209 | config = {
210 | enabled_plugins = {
211 | "onservice",
212 | "inrealm",
213 | "ingroup",
214 | "inpm",
215 | "banhammer",
216 | "stats",
217 | "anti_spam",
218 | "owners",
219 | "arabic_lock",
220 | "set",
221 | "get",
222 | "broadcast",
223 | "download_media",
224 | "invite",
225 | "all",
226 | "leave_ban",
227 | "admin"
228 | },
229 | sudo_users = {140529465,103649648,143723991,111020322,0,tonumber(our_id)},--Sudo users
230 | disabled_channels = {},
231 | moderation = {data = 'data/moderation.json'},
232 | about_text = [[Teleseed v2 - Open Source
233 | An advance Administration bot based on yagop/telegram-bot
234 | https://github.com/SEEDTEAM/TeleSeed
235 | Admins
236 | @iwals [Founder]
237 | @imandaneshi [Developer]
238 | @Rondoozle [Developer]
239 | @seyedan25 [Manager]
240 | Special thanks to
241 | awkward_potato
242 | Siyanew
243 | topkecleon
244 | Vamptacus
245 | Our channels
246 | @teleseedch [English]
247 | @iranseed [persian]
248 | ]],
249 | help_text_realm = [[
250 | Realm Commands:
251 | !creategroup [Name]
252 | Create a group
253 | !createrealm [Name]
254 | Create a realm
255 | !setname [Name]
256 | Set realm name
257 | !setabout [GroupID] [Text]
258 | Set a group's about text
259 | !setrules [GroupID] [Text]
260 | Set a group's rules
261 | !lock [GroupID] [setting]
262 | Lock a group's setting
263 | !unlock [GroupID] [setting]
264 | Unock a group's setting
265 | !wholist
266 | Get a list of members in group/realm
267 | !who
268 | Get a file of members in group/realm
269 | !type
270 | Get group type
271 | !kill chat [GroupID]
272 | Kick all memebers and delete group
273 | !kill realm [RealmID]
274 | Kick all members and delete realm
275 | !addadmin [id|username]
276 | Promote an admin by id OR username *Sudo only
277 | !removeadmin [id|username]
278 | Demote an admin by id OR username *Sudo only
279 | !list groups
280 | Get a list of all groups
281 | !list realms
282 | Get a list of all realms
283 | !log
284 | Grt a logfile of current group or realm
285 | !broadcast [text]
286 | !broadcast Hello !
287 | Send text to all groups
288 | Only sudo users can run this command
289 | !bc [group_id] [text]
290 | !bc 123456789 Hello !
291 | This command will send text to [group_id]
292 | **U can use both "/" and "!"
293 | *Only admins and sudo can add bots in group
294 | *Only admins and sudo can use kick,ban,unban,newlink,setphoto,setname,lock,unlock,set rules,set about and settings commands
295 | *Only admins and sudo can use res, setowner, commands
296 | ]],
297 | help_text = [[
298 | Commands list :
299 | !kick [username|id]
300 | You can also do it by reply
301 | !ban [ username|id]
302 | You can also do it by reply
303 | !unban [id]
304 | You can also do it by reply
305 | !who
306 | Members list
307 | !modlist
308 | Moderators list
309 | !promote [username]
310 | Promote someone
311 | !demote [username]
312 | Demote someone
313 | !kickme
314 | Will kick user
315 | !about
316 | Group description
317 | !setphoto
318 | Set and locks group photo
319 | !setname [name]
320 | Set group name
321 | !rules
322 | Group rules
323 | !id
324 | return group id or user id
325 | !help
326 | !lock [member|name|bots|leave]
327 | Locks [member|name|bots|leaveing]
328 | !unlock [member|name|bots|leave]
329 | Unlocks [member|name|bots|leaving]
330 | !set rules
331 | Set as rules
332 | !set about
333 | Set as about
334 | !settings
335 | Returns group settings
336 | !newlink
337 | create/revoke your group link
338 | !link
339 | returns group link
340 | !owner
341 | returns group owner id
342 | !setowner [id]
343 | Will set id as owner
344 | !setflood [value]
345 | Set [value] as flood sensitivity
346 | !stats
347 | Simple message statistics
348 | !save [value]
349 | Save as [value]
350 | !get [value]
351 | Returns text of [value]
352 | !clean [modlist|rules|about]
353 | Will clear [modlist|rules|about] and set it to nil
354 | !res [username]
355 | returns user id
356 | "!res @username"
357 | !log
358 | will return group logs
359 | !banlist
360 | will return group ban list
361 | **U can use both "/" and "!"
362 | *Only owner and mods can add bots in group
363 | *Only moderators and owner can use kick,ban,unban,newlink,link,setphoto,setname,lock,unlock,set rules,set about and settings commands
364 | *Only owner can use res,setowner,promote,demote and log commands
365 | ]]
366 | }
367 | serialize_to_file(config, './data/config.lua')
368 | print('saved config into ./data/config.lua')
369 | end
370 |
371 | function on_our_id (id)
372 | our_id = id
373 | end
374 |
375 | function on_user_update (user, what)
376 | --vardump (user)
377 | end
378 |
379 | function on_chat_update (chat, what)
380 |
381 | end
382 |
383 | function on_secret_chat_update (schat, what)
384 | --vardump (schat)
385 | end
386 |
387 | function on_get_difference_end ()
388 | end
389 |
390 | -- Enable plugins in config.json
391 | function load_plugins()
392 | for k, v in pairs(_config.enabled_plugins) do
393 | print("Loading plugin", v)
394 |
395 | local ok, err = pcall(function()
396 | local t = loadfile("plugins/"..v..'.lua')()
397 | plugins[v] = t
398 | end)
399 |
400 | if not ok then
401 | print('\27[31mError loading plugin '..v..'\27[39m')
402 | print(tostring(io.popen("lua plugins/"..v..".lua"):read('*all')))
403 | print('\27[31m'..err..'\27[39m')
404 | end
405 |
406 | end
407 | end
408 |
409 |
410 | -- custom add
411 | function load_data(filename)
412 |
413 | local f = io.open(filename)
414 | if not f then
415 | return {}
416 | end
417 | local s = f:read('*all')
418 | f:close()
419 | local data = JSON.decode(s)
420 |
421 | return data
422 |
423 | end
424 |
425 | function save_data(filename, data)
426 |
427 | local s = JSON.encode(data)
428 | local f = io.open(filename, 'w')
429 | f:write(s)
430 | f:close()
431 |
432 | end
433 |
434 | -- Call and postpone execution for cron plugins
435 | function cron_plugins()
436 |
437 | for name, plugin in pairs(plugins) do
438 | -- Only plugins with cron function
439 | if plugin.cron ~= nil then
440 | plugin.cron()
441 | end
442 | end
443 |
444 | -- Called again in 2 mins
445 | postpone (cron_plugins, false, 120)
446 | end
447 |
448 | -- Start and load values
449 | our_id = 0
450 | now = os.time()
451 | math.randomseed(now)
452 | started = false
453 |
--------------------------------------------------------------------------------
/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thisishmed/BossTG/17c51a697499c01c806994eafde31e150a79e146/data/.gitkeep
--------------------------------------------------------------------------------
/data/photos/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thisishmed/BossTG/17c51a697499c01c806994eafde31e150a79e146/data/photos/.gitkeep
--------------------------------------------------------------------------------
/groups/all/[group_id]all.txt:
--------------------------------------------------------------------------------
1 | [group_id] logs !
2 |
--------------------------------------------------------------------------------
/groups/lists/[group_id]memberlist.txt:
--------------------------------------------------------------------------------
1 | [group_id] memeberlist !
2 |
--------------------------------------------------------------------------------
/groups/logs/[group_id]log.txt:
--------------------------------------------------------------------------------
1 | [group_id] logs !
2 |
--------------------------------------------------------------------------------
/groups/logs/[group_id]stats.txt:
--------------------------------------------------------------------------------
1 | [group_id] stats !
2 |
--------------------------------------------------------------------------------
/launch.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | THIS_DIR=$(cd $(dirname $0); pwd)
4 | cd $THIS_DIR
5 |
6 | update() {
7 | git pull
8 | git submodule update --init --recursive
9 | install_rocks
10 | }
11 |
12 | # Will install luarocks on THIS_DIR/.luarocks
13 | install_luarocks() {
14 | git clone https://github.com/keplerproject/luarocks.git
15 | cd luarocks
16 | git checkout tags/v2.2.1 # Current stable
17 |
18 | PREFIX="$THIS_DIR/.luarocks"
19 |
20 | ./configure --prefix=$PREFIX --sysconfdir=$PREFIX/luarocks --force-config
21 |
22 | RET=$?; if [ $RET -ne 0 ];
23 | then echo "Error. Exiting."; exit $RET;
24 | fi
25 |
26 | make build && make install
27 | RET=$?; if [ $RET -ne 0 ];
28 | then echo "Error. Exiting.";exit $RET;
29 | fi
30 |
31 | cd ..
32 | rm -rf luarocks
33 | }
34 |
35 | install_rocks() {
36 | ./.luarocks/bin/luarocks install luasocket
37 | RET=$?; if [ $RET -ne 0 ];
38 | then echo "Error. Exiting."; exit $RET;
39 | fi
40 |
41 | ./.luarocks/bin/luarocks install oauth
42 | RET=$?; if [ $RET -ne 0 ];
43 | then echo "Error. Exiting."; exit $RET;
44 | fi
45 |
46 | ./.luarocks/bin/luarocks install redis-lua
47 | RET=$?; if [ $RET -ne 0 ];
48 | then echo "Error. Exiting."; exit $RET;
49 | fi
50 |
51 | ./.luarocks/bin/luarocks install lua-cjson
52 | RET=$?; if [ $RET -ne 0 ];
53 | then echo "Error. Exiting."; exit $RET;
54 | fi
55 |
56 | ./.luarocks/bin/luarocks install fakeredis
57 | RET=$?; if [ $RET -ne 0 ];
58 | then echo "Error. Exiting."; exit $RET;
59 | fi
60 |
61 | ./.luarocks/bin/luarocks install xml
62 | RET=$?; if [ $RET -ne 0 ];
63 | then echo "Error. Exiting."; exit $RET;
64 | fi
65 |
66 | ./.luarocks/bin/luarocks install feedparser
67 | RET=$?; if [ $RET -ne 0 ];
68 | then echo "Error. Exiting."; exit $RET;
69 | fi
70 |
71 | ./.luarocks/bin/luarocks install serpent
72 | RET=$?; if [ $RET -ne 0 ];
73 | then echo "Error. Exiting."; exit $RET;
74 | fi
75 | }
76 |
77 | install() {
78 | git pull
79 | git submodule update --init --recursive
80 | patch -i "patches/disable-python-and-libjansson.patch" -p 0 --batch --forward
81 | RET=$?;
82 |
83 | cd tg
84 | if [ $RET -ne 0 ]; then
85 | autoconf -i
86 | fi
87 | ./configure && make
88 |
89 | RET=$?; if [ $RET -ne 0 ]; then
90 | echo "Error. Exiting."; exit $RET;
91 | fi
92 | cd ..
93 | install_luarocks
94 | install_rocks
95 | }
96 |
97 | if [ "$1" = "install" ]; then
98 | install
99 | elif [ "$1" = "update" ]; then
100 | update
101 | else
102 | if [ ! -f ./tg/telegram.h ]; then
103 | echo "tg not found"
104 | echo "Run $0 install"
105 | exit 1
106 | fi
107 |
108 | if [ ! -f ./tg/bin/telegram-cli ]; then
109 | echo "tg binary not found"
110 | echo "Run $0 install"
111 | exit 1
112 | fi
113 |
114 | ./tg/bin/telegram-cli -k ./tg/tg-server.pub -s ./bot/seedbot.lua -l 1 -E $@
115 | fi
--------------------------------------------------------------------------------
/libs/mimetype.lua:
--------------------------------------------------------------------------------
1 | -- Thanks to https://github.com/catwell/lua-toolbox/blob/master/mime.types
2 | do
3 |
4 | local mimetype = {}
5 |
6 | -- TODO: Add more?
7 | local types = {
8 | ["text/html"] = "html",
9 | ["text/css"] = "css",
10 | ["text/xml"] = "xml",
11 | ["image/gif"] = "gif",
12 | ["image/jpeg"] = "jpg",
13 | ["application/x-javascript"] = "js",
14 | ["application/atom+xml"] = "atom",
15 | ["application/rss+xml"] = "rss",
16 | ["text/mathml"] = "mml",
17 | ["text/plain"] = "txt",
18 | ["text/vnd.sun.j2me.app-descriptor"] = "jad",
19 | ["text/vnd.wap.wml"] = "wml",
20 | ["text/x-component"] = "htc",
21 | ["image/png"] = "png",
22 | ["image/tiff"] = "tiff",
23 | ["image/vnd.wap.wbmp"] = "wbmp",
24 | ["image/x-icon"] = "ico",
25 | ["image/x-jng"] = "jng",
26 | ["image/x-ms-bmp"] = "bmp",
27 | ["image/svg+xml"] = "svg",
28 | ["image/webp"] = "webp",
29 | ["application/java-archive"] = "jar",
30 | ["application/mac-binhex40"] = "hqx",
31 | ["application/msword"] = "doc",
32 | ["application/pdf"] = "pdf",
33 | ["application/postscript"] = "ps",
34 | ["application/rtf"] = "rtf",
35 | ["application/vnd.ms-excel"] = "xls",
36 | ["application/vnd.ms-powerpoint"] = "ppt",
37 | ["application/vnd.wap.wmlc"] = "wmlc",
38 | ["application/vnd.google-earth.kml+xml"] = "kml",
39 | ["application/vnd.google-earth.kmz"] = "kmz",
40 | ["application/x-7z-compressed"] = "7z",
41 | ["application/x-cocoa"] = "cco",
42 | ["application/x-java-archive-diff"] = "jardiff",
43 | ["application/x-java-jnlp-file"] = "jnlp",
44 | ["application/x-makeself"] = "run",
45 | ["application/x-perl"] = "pl",
46 | ["application/x-pilot"] = "prc",
47 | ["application/x-rar-compressed"] = "rar",
48 | ["application/x-redhat-package-manager"] = "rpm",
49 | ["application/x-sea"] = "sea",
50 | ["application/x-shockwave-flash"] = "swf",
51 | ["application/x-stuffit"] = "sit",
52 | ["application/x-tcl"] = "tcl",
53 | ["application/x-x509-ca-cert"] = "crt",
54 | ["application/x-xpinstall"] = "xpi",
55 | ["application/xhtml+xml"] = "xhtml",
56 | ["application/zip"] = "zip",
57 | ["application/octet-stream"] = "bin",
58 | ["audio/midi"] = "mid",
59 | ["audio/mpeg"] = "mp3",
60 | ["audio/ogg"] = "ogg",
61 | ["audio/x-m4a"] = "m4a",
62 | ["audio/x-realaudio"] = "ra",
63 | ["video/3gpp"] = "3gpp",
64 | ["video/mp4"] = "mp4",
65 | ["video/mpeg"] = "mpeg",
66 | ["video/quicktime"] = "mov",
67 | ["video/webm"] = "webm",
68 | ["video/x-flv"] = "flv",
69 | ["video/x-m4v"] = "m4v",
70 | ["video/x-mng"] = "mng",
71 | ["video/x-ms-asf"] = "asf",
72 | ["video/x-ms-wmv"] = "wmv",
73 | ["video/x-msvideo"] = "avi"
74 | }
75 |
76 | -- Returns the common file extension from a content-type
77 | function mimetype.get_mime_extension(content_type)
78 | return types[content_type]
79 | end
80 |
81 | -- Returns the mimetype and subtype
82 | function mimetype.get_content_type(extension)
83 | for k,v in pairs(types) do
84 | if v == extension then
85 | return k
86 | end
87 | end
88 | end
89 |
90 | -- Returns the mimetype without the subtype
91 | function mimetype.get_content_type_no_sub(extension)
92 | for k,v in pairs(types) do
93 | if v == extension then
94 | -- Before /
95 | return k:match('([%w-]+)/')
96 | end
97 | end
98 | end
99 |
100 | return mimetype
101 | end
--------------------------------------------------------------------------------
/libs/redis.lua:
--------------------------------------------------------------------------------
1 | local Redis = require 'redis'
2 | local FakeRedis = require 'fakeredis'
3 |
4 | local params = {
5 | host = '127.0.0.1',
6 | port = 6379,
7 | }
8 |
9 | -- Overwrite HGETALL
10 | Redis.commands.hgetall = Redis.command('hgetall', {
11 | response = function(reply, command, ...)
12 | local new_reply = { }
13 | for i = 1, #reply, 2 do new_reply[reply[i]] = reply[i + 1] end
14 | return new_reply
15 | end
16 | })
17 |
18 | local redis = nil
19 |
20 | -- Won't launch an error if fails
21 | local ok = pcall(function()
22 | redis = Redis.connect(params)
23 | end)
24 |
25 | if not ok then
26 |
27 | local fake_func = function()
28 | print('\27[31mCan\'t connect with Redis, install/configure it!\27[39m')
29 | end
30 | fake_func()
31 | fake = FakeRedis.new()
32 |
33 | print('\27[31mRedis addr: '..params.host..'\27[39m')
34 | print('\27[31mRedis port: '..params.port..'\27[39m')
35 |
36 | redis = setmetatable({fakeredis=true}, {
37 | __index = function(a, b)
38 | if b ~= 'data' and fake[b] then
39 | fake_func(b)
40 | end
41 | return fake[b] or fake_func
42 | end })
43 |
44 | end
45 |
46 |
47 | return redis
--------------------------------------------------------------------------------
/patches/disable-python-and-libjansson.patch:
--------------------------------------------------------------------------------
1 | --- tg/configure.ac 2015-10-24 14:23:51.964259062 +0200
2 | +++ tg/configure.ac 2015-10-24 14:05:10.111062758 +0200
3 | @@ -61,93 +61,43 @@
4 | ],[
5 | ])
6 |
7 | +# liblua is required
8 | AC_MSG_CHECKING([for liblua])
9 | -AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
10 | - [
11 | - if test "x$enableval" = "xno" ; then
12 | - AC_MSG_RESULT([disabled])
13 | - else
14 | - AC_MSG_RESULT([enabled])
15 | - AX_PROG_LUA([],[],
16 | - [
17 | - AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])])
18 | - AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])])
19 | - [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ]
20 | - [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ]
21 | - AC_DEFINE(USE_LUA,1,[use lua])
22 | - ],
23 | - [
24 | - AC_MSG_ERROR([No lua found. Try --disable-liblua])
25 | - ])
26 | - fi
27 | - ],[
28 | - AC_MSG_RESULT([enabled])
29 | - AX_PROG_LUA([],[],
30 | - [
31 | - AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Try --disable-liblua])])
32 | - AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Try --disable-liblua])])
33 | - [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ]
34 | - [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ]
35 | - AC_DEFINE(USE_LUA,1,[use lua])
36 | - ],
37 | - [
38 | - AC_MSG_ERROR([No lua found. Try --disable-liblua])
39 | - ])
40 | - ])
41 | -
42 | -AC_MSG_CHECKING([for python])
43 | -AC_ARG_ENABLE(python,[--enable-python/--disable-python],
44 | +AC_MSG_RESULT([enabled])
45 | +AX_PROG_LUA([],[],
46 | [
47 | - if test "x$enableval" = "xno" ; then
48 | - AC_MSG_RESULT([disabled])
49 | - else
50 | - AC_MSG_RESULT([enabled])
51 | -
52 | - AX_PYTHON()
53 | - AC_SUBST([PYTHON_FOUND])
54 | - if test $PYTHON_FOUND = no ; then
55 | - AC_MSG_ERROR([No supported python lib version found. Try --disable-python])
56 | - else
57 | - AC_SUBST([PYTHON_LIBS])
58 | - AC_SUBST([PYTHON_CFLAGS])
59 | - EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
60 | - CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
61 | - AC_DEFINE(USE_PYTHON,1,[use python])
62 | - fi
63 | - fi
64 | - ],[
65 | - AC_MSG_RESULT([enabled])
66 | -
67 | - AX_PYTHON()
68 | - AC_SUBST([PYTHON_FOUND])
69 | - if test $PYTHON_FOUND = no ; then
70 | - AC_MSG_ERROR([No supported python lib version found. Try --disable-python])
71 | - else
72 | - AC_SUBST([PYTHON_LIBS])
73 | - AC_SUBST([PYTHON_CFLAGS])
74 | - EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
75 | - CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
76 | - AC_DEFINE(USE_PYTHON,1,[use python])
77 | - fi
78 | + AX_LUA_HEADERS([],[AC_MSG_ERROR([No lua headers found. Install them])])
79 | + AX_LUA_LIBS([],[AC_MSG_ERROR([No lua libs found. Install them])])
80 | + [EXTRA_LIBS="${EXTRA_LIBS} ${LUA_LIB}" ; ]
81 | + [CPPFLAGS="${CPPFLAGS} ${LUA_INCLUDE}" ; ]
82 | + AC_DEFINE(USE_LUA,1,[use lua])
83 | + ],
84 | + [
85 | + AC_MSG_ERROR([No lua found. Install lua])
86 | ])
87 |
88 | +# Optional
89 | +AC_MSG_CHECKING([for python])
90 | +AX_PYTHON()
91 | +AC_SUBST([PYTHON_FOUND])
92 | +if test $PYTHON_FOUND = no ; then
93 | + AC_MSG_RESULT([disabled])
94 | +else
95 | + AC_SUBST([PYTHON_LIBS])
96 | + AC_SUBST([PYTHON_CFLAGS])
97 | + EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
98 | + CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
99 | + AC_DEFINE(USE_PYTHON,1,[use python])
100 | +fi
101 |
102 | -
103 | +# Optional
104 | AC_MSG_CHECKING([for libjansson])
105 | -AC_ARG_ENABLE(json,[--enable-json/--disable-json],
106 | - [
107 | - if test "x$enableval" = "xno" ; then
108 | - AC_MSG_RESULT([disabled])
109 | - else
110 | - AC_MSG_RESULT([enabled])
111 | - AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json]))
112 | - AC_DEFINE(USE_JSON,1,[use json])
113 | - fi
114 | - ],[
115 | +AC_CHECK_LIB([jansson],[json_array_set_new],
116 | + [
117 | AC_MSG_RESULT([enabled])
118 | - AC_CHECK_LIB([jansson],[json_array_set_new],[],AC_MSG_ERROR([No libjansson found. Try --disable-json]))
119 | AC_DEFINE(USE_JSON,1,[use json])
120 | - ])
121 | + ],
122 | + [AC_MSG_RESULT([disabled])])
123 |
124 | #check for custom prog name
125 | AC_MSG_CHECKING([progname])
126 | @@ -193,4 +143,3 @@
127 | AC_SUBST(EXTRA_LIBS)
128 | AC_CONFIG_FILES([Makefile])
129 | AC_OUTPUT
130 | -
131 |
--------------------------------------------------------------------------------
/plugins/Fabanhammer.lua:
--------------------------------------------------------------------------------
1 |
2 | local function pre_process(msg)
3 | -- SERVICE MESSAGE
4 | if msg.action and msg.action.type then
5 | local action = msg.action.type
6 | -- Check if banned user joins chat by link
7 | if action == 'chat_add_user_link' then
8 | local user_id = msg.from.id
9 | print('Checking invited user '..user_id)
10 | local banned = is_banned(user_id, msg.to.id)
11 | if banned or is_gbanned(user_id) then -- Check it with redis
12 | print('User is banned!')
13 | local name = user_print_name(msg.from)
14 | savelog(msg.to.id, name.." ["..msg.from.id.."] is banned and kicked ! ")-- Save to logs
15 | kick_user(user_id, msg.to.id)
16 | end
17 | end
18 | -- Check if banned user joins chat
19 | if action == 'chat_add_user' then
20 | local user_id = msg.action.user.id
21 | print('Checking invited user '..user_id)
22 | local banned = is_banned(user_id, msg.to.id)
23 | if banned or is_gbanned(user_id) then -- Check it with redis
24 | print('User is banned!')
25 | local name = user_print_name(msg.from)
26 | savelog(msg.to.id, name.." ["..msg.from.id.."] added a banned user >"..msg.action.user.id)-- Save to logs
27 | kick_user(user_id, msg.to.id)
28 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
29 | redis:incr(banhash)
30 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
31 | local banaddredis = redis:get(banhash)
32 | if banaddredis then
33 | if tonumber(banaddredis) == 4 and not is_owner(msg) then
34 | kick_user(msg.from.id, msg.to.id)-- Kick user who adds ban ppl more than 3 times
35 | end
36 | if tonumber(banaddredis) == 8 and not is_owner(msg) then
37 | ban_user(msg.from.id, msg.to.id)-- Kick user who adds ban ppl more than 7 times
38 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
39 | redis:set(banhash, 0)-- Reset the Counter
40 | end
41 | end
42 | end
43 | if data[tostring(msg.to.id)] then
44 | if data[tostring(msg.to.id)]['settings'] then
45 | if data[tostring(msg.to.id)]['settings']['lock_bots'] then
46 | bots_protection = data[tostring(msg.to.id)]['settings']['lock_bots']
47 | end
48 | end
49 | end
50 | if msg.action.user.username ~= nil then
51 | if string.sub(msg.action.user.username:lower(), -3) == 'bot' and not is_momod(msg) and bots_protection == "yes" then --- Will kick bots added by normal users
52 | local name = user_print_name(msg.from)
53 | savelog(msg.to.id, name.." ["..msg.from.id.."] added a bot > @".. msg.action.user.username)-- Save to logs
54 | kick_user(msg.action.user.id, msg.to.id)
55 | end
56 | end
57 | end
58 | -- No further checks
59 | return msg
60 | end
61 | -- banned user is talking !
62 | if msg.to.type == 'chat' then
63 | local data = load_data(_config.moderation.data)
64 | local group = msg.to.id
65 | local texttext = 'groups'
66 | --if not data[tostring(texttext)][tostring(msg.to.id)] and not is_realm(msg) then -- Check if this group is one of my groups or not
67 | --chat_del_user('chat#id'..msg.to.id,'user#id'..our_id,ok_cb,false)
68 | --return
69 | --end
70 | local user_id = msg.from.id
71 | local chat_id = msg.to.id
72 | local banned = is_banned(user_id, chat_id)
73 | if banned or is_gbanned(user_id) then -- Check it with redis
74 | print('Banned user talking!')
75 | local name = user_print_name(msg.from)
76 | savelog(msg.to.id, name.." ["..msg.from.id.."] banned user is talking !")-- Save to logs
77 | kick_user(user_id, chat_id)
78 | msg.text = ''
79 | end
80 | end
81 | return msg
82 | end
83 |
84 | local function kick_ban_res(extra, success, result)
85 | --vardump(result)
86 | --vardump(extra)
87 | local member_id = result.id
88 | local user_id = member_id
89 | local member = result.username
90 | local chat_id = extra.chat_id
91 | local from_id = extra.from_id
92 | local get_cmd = extra.get_cmd
93 | local receiver = "chat#id"..chat_id
94 | if get_cmd == "اخراج" then
95 | if member_id == from_id then
96 | return send_large_msg(receiver, "You can't kick yourself")
97 | end
98 | if is_momod2(member_id, chat_id) and not is_admin2(sender) then
99 | return send_large_msg(receiver, "You can't kick mods/owner/admins")
100 | end
101 | return kick_user(member_id, chat_id)
102 | elseif get_cmd == 'بن' then
103 | if is_momod2(member_id, chat_id) and not is_admin2(sender) then
104 | return send_large_msg(receiver, "You can't ban mods/owner/admins")
105 | end
106 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] banned')
107 | return ban_user(member_id, chat_id)
108 | elseif get_cmd == 'ان بن' then
109 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] unbanned')
110 | local hash = 'banned:'..chat_id
111 | redis:srem(hash, member_id)
112 | return 'کاربر '..user_id..' بن شد'
113 | elseif get_cmd == 'بن جهانی' then
114 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] globally banned')
115 | return banall_user(member_id, chat_id)
116 | elseif get_cmd == 'حذف بن جهانی' then
117 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] un-globally banned')
118 | return unbanall_user(member_id, chat_id)
119 | end
120 | end
121 |
122 | local function run(msg, matches)
123 | if matches[1]:lower() == 'ایدی' then
124 | if msg.to.type == "user" then
125 | return "Bot ID: "..msg.to.id.. "\n\nYour ID: "..msg.from.id
126 | end
127 | if type(msg.reply_id) ~= "nil" then
128 | local name = user_print_name(msg.from)
129 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /id ")
130 | id = get_message(msg.reply_id,get_message_callback_id, false)
131 | elseif matches[1]:lower() == 'ایدی' then
132 | local name = user_print_name(msg.from)
133 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /id ")
134 | return "Group ID for " ..string.gsub(msg.to.print_name, "_", " ").. ":\n\n"..msg.to.id
135 | end
136 | end
137 | if matches[1]:lower() == 'حذفم کن' then-- /kickme
138 | local receiver = get_receiver(msg)
139 | if msg.to.type == 'chat' then
140 | local name = user_print_name(msg.from)
141 | savelog(msg.to.id, name.." ["..msg.from.id.."] left using kickme ")-- Save to logs
142 | chat_del_user("chat#id"..msg.to.id, "user#id"..msg.from.id, ok_cb, false)
143 | end
144 | end
145 |
146 | if not is_momod(msg) then -- Ignore normal users
147 | return
148 | end
149 |
150 | if matches[1]:lower() == "لیست بن" then -- Ban list !
151 | local chat_id = msg.to.id
152 | if matches[2] and is_admin(msg) then
153 | chat_id = matches[2]
154 | end
155 | return ban_list(chat_id)
156 | end
157 | if matches[1]:lower() == 'بن' then-- /ban
158 | if type(msg.reply_id)~="nil" and is_momod(msg) then
159 | if is_admin(msg) then
160 | local msgr = get_message(msg.reply_id,ban_by_reply_admins, false)
161 | else
162 | msgr = get_message(msg.reply_id,ban_by_reply, false)
163 | end
164 | end
165 | local user_id = matches[2]
166 | local chat_id = msg.to.id
167 | if string.match(matches[2], '^%d+$') then
168 | if tonumber(matches[2]) == tonumber(our_id) then
169 | return
170 | end
171 | if not is_admin(msg) and is_momod2(matches[2], msg.to.id) then
172 | return "you can't ban mods/owner/admins"
173 | end
174 | if tonumber(matches[2]) == tonumber(msg.from.id) then
175 | return "You can't ban your self !"
176 | end
177 | local name = user_print_name(msg.from)
178 | savelog(msg.to.id, name.." ["..msg.from.id.."] baned user ".. matches[2])
179 | ban_user(user_id, chat_id)
180 | else
181 | local cbres_extra = {
182 | chat_id = msg.to.id,
183 | get_cmd = 'ban',
184 | from_id = msg.from.id
185 | }
186 | local username = matches[2]
187 | local username = string.gsub(matches[2], '@', '')
188 | res_user(username, kick_ban_res, cbres_extra)
189 | end
190 | end
191 |
192 |
193 | if matches[1]:lower() == 'ان بن' then -- /unban
194 | if type(msg.reply_id)~="nil" and is_momod(msg) then
195 | local msgr = get_message(msg.reply_id,unban_by_reply, false)
196 | end
197 | local user_id = matches[2]
198 | local chat_id = msg.to.id
199 | local targetuser = matches[2]
200 | if string.match(targetuser, '^%d+$') then
201 | local user_id = targetuser
202 | local hash = 'banned:'..chat_id
203 | redis:srem(hash, user_id)
204 | local name = user_print_name(msg.from)
205 | savelog(msg.to.id, name.." ["..msg.from.id.."] unbaned user ".. matches[2])
206 | return 'کاربر '..user_id..' از بن خارج شد'
207 | else
208 | local cbres_extra = {
209 | chat_id = msg.to.id,
210 | get_cmd = 'ان بن',
211 | from_id = msg.from.id
212 | }
213 | local username = matches[2]
214 | local username = string.gsub(matches[2], '@', '')
215 | res_user(username, kick_ban_res, cbres_extra)
216 | end
217 | end
218 |
219 | if matches[1]:lower() == 'اخراج' then
220 | if type(msg.reply_id)~="nil" and is_momod(msg) then
221 | if is_admin(msg) then
222 | local msgr = get_message(msg.reply_id,Kick_by_reply_admins, false)
223 | else
224 | msgr = get_message(msg.reply_id,Kick_by_reply, false)
225 | end
226 | end
227 |
228 | if string.match(matches[2], '^%d+$') then
229 | if tonumber(matches[2]) == tonumber(our_id) then
230 | return
231 | end
232 | if not is_admin(msg) and is_momod2(matches[2], msg.to.id) then
233 | return "شما نمیتوانید حذف کنید mods/owner/admins ها را"
234 | end
235 | if tonumber(matches[2]) == tonumber(msg.from.id) then
236 | return "You can't kick your self !"
237 | end
238 | local user_id = matches[2]
239 | local chat_id = msg.to.id
240 | name = user_print_name(msg.from)
241 | savelog(msg.to.id, name.." ["..msg.from.id.."] kicked user ".. matches[2])
242 | kick_user(user_id, chat_id)
243 | else
244 | local cbres_extra = {
245 | chat_id = msg.to.id,
246 | get_cmd = 'اخراج',
247 | from_id = msg.from.id
248 | }
249 | local username = matches[2]
250 | local username = string.gsub(matches[2], '@', '')
251 | res_user(username, kick_ban_res, cbres_extra)
252 | end
253 | end
254 |
255 |
256 | if not is_admin(msg) then
257 | return
258 | end
259 |
260 | if matches[1]:lower() == 'بن جهانی' then -- Global ban
261 | if type(msg.reply_id) ~="nil" and is_admin(msg) then
262 | return get_message(msg.reply_id,banall_by_reply, false)
263 | end
264 | local user_id = matches[2]
265 | local chat_id = msg.to.id
266 | local targetuser = matches[2]
267 | if string.match(targetuser, '^%d+$') then
268 | if tonumber(matches[2]) == tonumber(our_id) then
269 | return false
270 | end
271 | banall_user(targetuser)
272 | return 'کاربر ['..user_id..' ] بن جهانی شد'
273 | else
274 | local cbres_extra = {
275 | chat_id = msg.to.id,
276 | get_cmd = 'بن جهانی',
277 | from_id = msg.from.id
278 | }
279 | local username = matches[2]
280 | local username = string.gsub(matches[2], '@', '')
281 | res_user(username, kick_ban_res, cbres_extra)
282 | end
283 | end
284 | if matches[1]:lower() == 'حذف بن جهانی' then -- Global unban
285 | local user_id = matches[2]
286 | local chat_id = msg.to.id
287 | if string.match(matches[2], '^%d+$') then
288 | if tonumber(matches[2]) == tonumber(our_id) then
289 | return false
290 | end
291 | unbanall_user(user_id)
292 | return 'کاربر ['..user_id..' ] از بن جهانی خارج شد'
293 | else
294 | local cbres_extra = {
295 | chat_id = msg.to.id,
296 | get_cmd = 'حذف بن جهانی',
297 | from_id = msg.from.id
298 | }
299 | local username = matches[2]
300 | local username = string.gsub(matches[2], '@', '')
301 | res_user(username, kick_ban_res, cbres_extra)
302 | end
303 | end
304 | if matches[1]:lower() == "لیست بن جهانی" then -- Global ban list
305 | return banall_list()
306 | end
307 | end
308 |
309 | return {
310 | patterns = {
311 | "^(بن جهانی) (.*)$",
312 | "^[!/](بن جهانی)$",
313 | "^(لیست بن جهانی) (.*)$",
314 | "^(لیست بن)$",
315 | "^(لیست بن)$",
316 | "^(بن) (.*)$",
317 | "^(اخراج)$",
318 | "^(ان بن) (.*)$",
319 | "^(حذف بن جهانی) (.*)$",
320 | "^([حذف بن جهانی)$",
321 | "^(ان بن) (.*)$",
322 | "^(حذفم کن)$",
323 | "^([بن)$",
324 | "^([ان بن)$",
325 | "^(ایدی)$",
326 | "^!!tgservice (.+)$"
327 | },
328 | run = run,
329 | pre_process = pre_process --by shatel team
330 | }
331 |
--------------------------------------------------------------------------------
/plugins/Welcome.lua:
--------------------------------------------------------------------------------
1 | local add_user_cfg = load_from_file('data/add_user_cfg.lua')
2 |
3 | local function template_add_user(base, to_username, from_username, chat_name, chat_id)
4 | base = base or ''
5 | to_username = '@' .. (to_username or '')
6 | from_username = '@' .. (from_username or '')
7 | chat_name = string.gsub(chat_name, '_', ' ') or ''
8 | chat_id = "chat#id" .. (chat_id or '')
9 | if to_username == "@" then
10 | to_username = ''
11 | end
12 | if from_username == "@" then
13 | from_username = ''
14 | end
15 | base = string.gsub(base, "{to_username}", to_username)
16 | base = string.gsub(base, "{from_username}", from_username)
17 | base = string.gsub(base, "{chat_name}", chat_name)
18 | base = string.gsub(base, "{chat_id}", chat_id)
19 | return base
20 | end
21 |
22 | function chat_new_user_link(msg)
23 | local pattern = add_user_cfg.initial_chat_msg
24 | local to_username = msg.from.username
25 | local from_username = 'link (@' .. (msg.action.link_issuer.username or '') .. ')'
26 | local chat_name = msg.to.print_name
27 | local chat_id = msg.to.id
28 | pattern = template_add_user(pattern, to_username, from_username, chat_name, chat_id)
29 | if pattern ~= '' then
30 | local receiver = get_receiver(msg)
31 | send_msg(receiver, pattern, ok_cb, false)
32 | end
33 | end
34 |
35 | function chat_new_user(msg)
36 | local pattern = add_user_cfg.initial_chat_msg
37 | local to_username = msg.action.user.username
38 | local from_username = msg.from.username
39 | local chat_name = msg.to.print_name
40 | local chat_id = msg.to.id
41 | pattern = template_add_user(pattern, to_username, from_username, chat_name, chat_id)
42 | if pattern ~= '' then
43 | local receiver = get_receiver(msg)
44 | send_msg(receiver, pattern, ok_cb, false)
45 | end
46 | end
47 |
48 | local function description_rules(msg, nama)
49 | local data = load_data(_config.moderation.data)
50 | if data[tostring(msg.to.id)] then
51 | local about = ""
52 | local rules = ""
53 | if data[tostring(msg.to.id)]["description"] then
54 | about = data[tostring(msg.to.id)]["description"]
55 | about = "\nAbout :\n"..about.."\n"
56 | end
57 | if data[tostring(msg.to.id)]["rules"] then
58 | rules = data[tostring(msg.to.id)]["rules"]
59 | rules = "\nRules :\n"..rules.."\n"
60 | end
61 | local sambutan = "Hi "..nama.."\nWelcome to '"..string.gsub(msg.to.print_name, "_", " ").."'\nYou can use /help for see bot commands\n"
62 | local text = sambutan..about..rules.."\n"
63 | local receiver = get_receiver(msg)
64 | send_large_msg(receiver, text, ok_cb, false)
65 | end
66 | end
67 |
68 | local function run(msg, matches)
69 | if not msg.service then
70 | return "Are you trying to troll me?"
71 | end
72 | --vardump(msg)
73 | if matches[1] == "chat_add_user" then
74 | if not msg.action.user.username then
75 | nama = string.gsub(msg.action.user.print_name, "_", " ")
76 | else
77 | nama = "@"..msg.action.user.username
78 | end
79 | chat_new_user(msg)
80 | description_rules(msg, nama)
81 | elseif matches[1] == "chat_add_user_link" then
82 | if not msg.from.username then
83 | nama = string.gsub(msg.from.print_name, "_", " ")
84 | else
85 | nama = "@"..msg.from.username
86 | end
87 | chat_new_user_link(msg)
88 | description_rules(msg, nama)
89 | elseif matches[1] == "chat_del_user" then
90 | local bye_name = msg.action.user.first_name
91 | return 'Sikout '..bye_name
92 | end
93 | end
94 |
95 | return {
96 | description = "Welcoming Message",
97 | usage = "send message to new member",
98 | patterns = {
99 | "^!!tgservice (chat_add_user)$",
100 | "^!!tgservice (chat_add_user_link)$",
101 | "^!!tgservice (chat_del_user)$",
102 | },
103 | run = run
104 | }
105 |
--------------------------------------------------------------------------------
/plugins/addplug.lua:
--------------------------------------------------------------------------------
1 | do
2 | local function save_file(name, text)
3 | local file = io.open("./plugins/"..name, "w")
4 | file:write(text)
5 | file:flush()
6 | file:close()
7 | return "Plugin saved."
8 | end
9 | function run(msg, matches)
10 | if matches[1] == "addplug" and is_sudo(msg) then
11 |
12 | local name = matches[2]
13 | local text = matches[3]
14 | return save_file(name, text)
15 |
16 | end
17 | end
18 | return {
19 | patterns = {
20 | "^/(addplug) ([^%s]+) (.+)$"
21 | },
22 | run = run
23 | }
24 | end
25 | -- create by @shervin_hacker
26 |
--------------------------------------------------------------------------------
/plugins/admin.lua:
--------------------------------------------------------------------------------
1 | local function set_bot_photo(msg, success, result)
2 | local receiver = get_receiver(msg)
3 | if success then
4 | local file = 'data/photos/bot.jpg'
5 | print('File downloaded to:', result)
6 | os.rename(result, file)
7 | print('File moved to:', file)
8 | set_profile_photo(file, ok_cb, false)
9 | send_large_msg(receiver, 'Photo changed!', ok_cb, false)
10 | redis:del("bot:photo")
11 | else
12 | print('Error downloading: '..msg.id)
13 | send_large_msg(receiver, 'Failed, please try again!', ok_cb, false)
14 | end
15 | end
16 | local function parsed_url(link)
17 | local parsed_link = URL.parse(link)
18 | local parsed_path = URL.parse_path(parsed_link.path)
19 | return parsed_path[2]
20 | end
21 | local function get_contact_list_callback (cb_extra, success, result)
22 | local text = " "
23 | for k,v in pairs(result) do
24 | if v.print_name and v.id and v.phone then
25 | text = text..string.gsub(v.print_name , "_" , " ").." ["..v.id.."] = "..v.phone.."\n"
26 | end
27 | end
28 | local file = io.open("contact_list.txt", "w")
29 | file:write(text)
30 | file:flush()
31 | file:close()
32 | send_document("user#id"..cb_extra.target,"contact_list.txt", ok_cb, false)--.txt format
33 | local file = io.open("contact_list.json", "w")
34 | file:write(json:encode_pretty(result))
35 | file:flush()
36 | file:close()
37 | send_document("user#id"..cb_extra.target,"contact_list.json", ok_cb, false)--json format
38 | end
39 | local function user_info_callback(cb_extra, success, result)
40 | result.access_hash = nil
41 | result.flags = nil
42 | result.phone = nil
43 | if result.username then
44 | result.username = '@'..result.username
45 | end
46 | result.print_name = result.print_name:gsub("_","")
47 | local text = serpent.block(result, {comment=false})
48 | text = text:gsub("[{}]", "")
49 | text = text:gsub('"', "")
50 | text = text:gsub(",","")
51 | if cb_extra.msg.to.type == "chat" then
52 | send_large_msg("chat#id"..cb_extra.msg.to.id, text)
53 | else
54 | send_large_msg("user#id"..cb_extra.msg.to.id, text)
55 | end
56 | end
57 | local function get_dialog_list_callback(cb_extra, success, result)
58 | local text = ""
59 | for k,v in pairs(result) do
60 | if v.peer then
61 | if v.peer.type == "chat" then
62 | text = text.."group{"..v.peer.title.."}["..v.peer.id.."]("..v.peer.members_num..")"
63 | else
64 | if v.peer.print_name and v.peer.id then
65 | text = text.."user{"..v.peer.print_name.."}["..v.peer.id.."]"
66 | end
67 | if v.peer.username then
68 | text = text.."("..v.peer.username..")"
69 | end
70 | if v.peer.phone then
71 | text = text.."'"..v.peer.phone.."'"
72 | end
73 | end
74 | end
75 | if v.message then
76 | text = text..'\nlast msg >\nmsg id = '..v.message.id
77 | if v.message.text then
78 | text = text .. "\n text = "..v.message.text
79 | end
80 | if v.message.action then
81 | text = text.."\n"..serpent.block(v.message.action, {comment=false})
82 | end
83 | if v.message.from then
84 | if v.message.from.print_name then
85 | text = text.."\n From > \n"..string.gsub(v.message.from.print_name, "_"," ").."["..v.message.from.id.."]"
86 | end
87 | if v.message.from.username then
88 | text = text.."( "..v.message.from.username.." )"
89 | end
90 | if v.message.from.phone then
91 | text = text.."' "..v.message.from.phone.." '"
92 | end
93 | end
94 | end
95 | text = text.."\n\n"
96 | end
97 | local file = io.open("dialog_list.txt", "w")
98 | file:write(text)
99 | file:flush()
100 | file:close()
101 | send_document("user#id"..cb_extra.target,"dialog_list.txt", ok_cb, false)--.txt format
102 | local file = io.open("dialog_list.json", "w")
103 | file:write(json:encode_pretty(result))
104 | file:flush()
105 | file:close()
106 | send_document("user#id"..cb_extra.target,"dialog_list.json", ok_cb, false)--json format
107 | end
108 | local function run(msg,matches)
109 | local data = load_data(_config.moderation.data)
110 | local receiver = get_receiver(msg)
111 | local group = msg.to.id
112 | if not is_admin(msg) then
113 | return
114 | end
115 | if msg.media then
116 | if msg.media.type == 'photo' and redis:get("bot:photo") then
117 | if redis:get("bot:photo") == 'waiting' then
118 | load_photo(msg.id, set_bot_photo, msg)
119 | end
120 | end
121 | end
122 | if matches[1] == "setbotphoto" then
123 | redis:set("bot:photo", "waiting")
124 | return 'Please send me bot photo now'
125 | end
126 | if matches[1] == "markread" then
127 | if matches[2] == "on" then
128 | redis:set("bot:markread", "on")
129 | return "Mark read > on"
130 | end
131 | if matches[2] == "off" then
132 | redis:del("bot:markread")
133 | return "Mark read > off"
134 | end
135 | return
136 | end
137 | if matches[1] == "pm" then
138 | send_large_msg("user#id"..matches[2],matches[3])
139 | return "Msg sent"
140 | end
141 | if matches[1] == "block" then
142 | if is_admin2(matches[2]) then
143 | return "You can't block admins"
144 | end
145 | block_user("user#id"..matches[2],ok_cb,false)
146 | return "User blocked"
147 | end
148 | if matches[1] == "unblock" then
149 | unblock_user("user#id"..matches[2],ok_cb,false)
150 | return "User unblocked"
151 | end
152 | if matches[1] == "import" then--join by group link
153 | local hash = parsed_url(matches[2])
154 | import_chat_link(hash,ok_cb,false)
155 | end
156 | if matches[1] == "contactlist" then
157 | get_contact_list(get_contact_list_callback, {target = msg.from.id})
158 | return "I've sent contact list with both json and text format to your private"
159 | end
160 | if matches[1] == "delcontact" then
161 | del_contact("user#id"..matches[2],ok_cb,false)
162 | return "User "..matches[2].." removed from contact list"
163 | end
164 | if matches[1] == "dialoglist" then
165 | get_dialog_list(get_dialog_list_callback, {target = msg.from.id})
166 | return "I've sent dialog list with both json and text format to your private"
167 | end
168 | if matches[1] == "whois" then
169 | user_info("user#id"..matches[2],user_info_callback,{msg=msg})
170 | end
171 | return
172 | end
173 | return {
174 | patterns = {
175 | "^[!/](pm) (%d+) (.*)$",
176 | "^[!/](import) (.*)$",
177 | "^[!/](unblock) (%d+)$",
178 | "^[!/](block) (%d+)$",
179 | "^[!/](markread) (on)$",
180 | "^[!/](markread) (off)$",
181 | "^[!/](setbotphoto)$",
182 | "%[(photo)%]",
183 | "^[!/](contactlist)$",
184 | "^[!/](dialoglist)$",
185 | "^[!/](delcontact) (%d+)$",
186 | "^[!/](whois) (%d+)$"
187 | },
188 | run = run,
189 | }
190 | --By @imandaneshi :)
191 | --https://github.com/SEEDTEAM/TeleSeed/blob/master/plugins/admin.lua
192 |
--------------------------------------------------------------------------------
/plugins/all.lua:
--------------------------------------------------------------------------------
1 | do
2 | data = load_data(_config.moderation.data)
3 | local function get_msgs_user_chat(user_id, chat_id)
4 | local user_info = {}
5 | local uhash = 'user:'..user_id
6 | local user = redis:hgetall(uhash)
7 | local um_hash = 'msgs:'..user_id..':'..chat_id
8 | user_info.msgs = tonumber(redis:get(um_hash) or 0)
9 | user_info.name = user_print_name(user)..' ['..user_id..']'
10 | return user_info
11 | end
12 | local function chat_stats(chat_id)
13 | local hash = 'chat:'..chat_id..':users'
14 | local users = redis:smembers(hash)
15 | local users_info = {}
16 | for i = 1, #users do
17 | local user_id = users[i]
18 | local user_info = get_msgs_user_chat(user_id, chat_id)
19 | table.insert(users_info, user_info)
20 | end
21 | table.sort(users_info, function(a, b)
22 | if a.msgs and b.msgs then
23 | return a.msgs > b.msgs
24 | end
25 | end)
26 | local text = 'Chat stats:\n'
27 | for k,user in pairs(users_info) do
28 | text = text..user.name..' = '..user.msgs..'\n'
29 | end
30 | return text
31 | end
32 |
33 | local function get_group_type(target)
34 | local data = load_data(_config.moderation.data)
35 | local group_type = data[tostring(target)]['group_type']
36 | if not group_type or group_type == nil then
37 | return 'No group type available.'
38 | end
39 | return group_type
40 | end
41 | local function show_group_settings(target)
42 | local data = load_data(_config.moderation.data)
43 | if data[tostring(target)] then
44 | if data[tostring(target)]['settings']['flood_msg_max'] then
45 | NUM_MSG_MAX = tonumber(data[tostring(target)]['settings']['flood_msg_max'])
46 | print('custom'..NUM_MSG_MAX)
47 | else
48 | NUM_MSG_MAX = 5
49 | end
50 | end
51 | local settings = data[tostring(target)]['settings']
52 | local text = "Lock group name : "..settings.lock_name.."\nLock group photo : "..settings.lock_photo.."\nLock group member : "..settings.lock_member.."\nflood sensitivity : "..NUM_MSG_MAX
53 | return text
54 | end
55 |
56 | local function get_description(target)
57 | local data = load_data(_config.moderation.data)
58 | local data_cat = 'description'
59 | if not data[tostring(target)][data_cat] then
60 | return 'No description available.'
61 | end
62 | local about = data[tostring(target)][data_cat]
63 | return about
64 | end
65 |
66 | local function get_rules(target)
67 | local data = load_data(_config.moderation.data)
68 | local data_cat = 'rules'
69 | if not data[tostring(target)][data_cat] then
70 | return 'No rules available.'
71 | end
72 | local rules = data[tostring(target)][data_cat]
73 | return rules
74 | end
75 |
76 |
77 | local function modlist(target)
78 | local data = load_data(_config.moderation.data)
79 | local groups = 'groups'
80 | if not data[tostring(groups)] or not data[tostring(groups)][tostring(target)] then
81 | return 'Group is not added or is Realm.'
82 | end
83 | if next(data[tostring(target)]['moderators']) == nil then
84 | return 'No moderator in this group.'
85 | end
86 | local i = 1
87 | local message = '\nList of moderators :\n'
88 | for k,v in pairs(data[tostring(target)]['moderators']) do
89 | message = message ..i..' - @'..v..' [' ..k.. '] \n'
90 | i = i + 1
91 | end
92 | return message
93 | end
94 |
95 | local function get_link(target)
96 | local data = load_data(_config.moderation.data)
97 | local group_link = data[tostring(target)]['settings']['set_link']
98 | if not group_link or group_link == nil then
99 | return "No link"
100 | end
101 | return "Group link:\n"..group_link
102 | end
103 |
104 | local function all(target, receiver)
105 | local text = "All the things I know about this group\n\n"
106 | local group_type = get_group_type(target)
107 | text = text.."Group Type: \n"..group_type
108 | local settings = show_group_settings(target)
109 | text = text.."\n\nGroup settings: \n"..settings
110 | local rules = get_rules(target)
111 | text = text.."\n\nRules: \n"..rules
112 | local description = get_description(target)
113 | text = text.."\n\nAbout: \n"..description
114 | local modlist = modlist(target)
115 | text = text.."\n\nMods: \n"..modlist
116 | local link = get_link(target)
117 | text = text.."\n\nLink: \n"..link
118 | local stats = chat_stats(target)
119 | text = text.."\n\n"..stats
120 | local ban_list = ban_list(target)
121 | text = text.."\n\n"..ban_list
122 | local file = io.open("./groups/all/"..target.."all.txt", "w")
123 | file:write(text)
124 | file:flush()
125 | file:close()
126 | send_document(receiver,"./groups/all/"..target.."all.txt", ok_cb, false)
127 | return
128 | end
129 |
130 | function run(msg, matches)
131 | if matches[1] == "all" and matches[2] and is_owner2(msg.from.id, matches[2]) then
132 | local receiver = get_receiver(msg)
133 | local target = matches[2]
134 | return all(target, receiver)
135 | end
136 | if not is_owner(msg) then
137 | return
138 | end
139 | if matches[1] == "all" and not matches[2] then
140 | local receiver = get_receiver(msg)
141 | if not is_owner(msg) then
142 | return
143 | end
144 | return all(msg.to.id, receiver)
145 | end
146 | end
147 |
148 |
149 | return {
150 | patterns = {
151 | "^[!/](all)$",
152 | "^[!/](all) (%d+)$"
153 | },
154 | run = run
155 | }
156 | end
157 |
--------------------------------------------------------------------------------
/plugins/anti_spam.lua:
--------------------------------------------------------------------------------
1 |
2 | --An empty table for solving multiple kicking problem(thanks to @topkecleon )
3 | kicktable = {}
4 |
5 | do
6 |
7 | local TIME_CHECK = 2 -- seconds
8 | local data = load_data(_config.moderation.data)
9 | -- Save stats, ban user
10 | local function pre_process(msg)
11 | -- Ignore service msg
12 | if msg.service then
13 | return msg
14 | end
15 | if msg.from.id == our_id then
16 | return msg
17 | end
18 |
19 | -- Save user on Redis
20 | if msg.from.type == 'user' then
21 | local hash = 'user:'..msg.from.id
22 | print('Saving user', hash)
23 | if msg.from.print_name then
24 | redis:hset(hash, 'print_name', msg.from.print_name)
25 | end
26 | if msg.from.first_name then
27 | redis:hset(hash, 'first_name', msg.from.first_name)
28 | end
29 | if msg.from.last_name then
30 | redis:hset(hash, 'last_name', msg.from.last_name)
31 | end
32 | end
33 |
34 | -- Save stats on Redis
35 | if msg.to.type == 'chat' then
36 | -- User is on chat
37 | local hash = 'chat:'..msg.to.id..':users'
38 | redis:sadd(hash, msg.from.id)
39 | end
40 |
41 |
42 |
43 | -- Total user msgs
44 | local hash = 'msgs:'..msg.from.id..':'..msg.to.id
45 | redis:incr(hash)
46 |
47 | --Load moderation data
48 | local data = load_data(_config.moderation.data)
49 | if data[tostring(msg.to.id)] then
50 | --Check if flood is one or off
51 | if data[tostring(msg.to.id)]['settings']['flood'] == 'no' then
52 | return msg
53 | end
54 | end
55 |
56 | -- Check flood
57 | if msg.from.type == 'user' then
58 | local hash = 'user:'..msg.from.id..':msgs'
59 | local msgs = tonumber(redis:get(hash) or 0)
60 | local data = load_data(_config.moderation.data)
61 | local NUM_MSG_MAX = 5
62 | if data[tostring(msg.to.id)] then
63 | if data[tostring(msg.to.id)]['settings']['flood_msg_max'] then
64 | NUM_MSG_MAX = tonumber(data[tostring(msg.to.id)]['settings']['flood_msg_max'])--Obtain group flood sensitivity
65 | end
66 | end
67 | local max_msg = NUM_MSG_MAX * 1
68 | if msgs > max_msg then
69 | local user = msg.from.id
70 | -- Ignore mods,owner and admins
71 | if is_momod(msg) then
72 | return msg
73 | end
74 | local chat = msg.to.id
75 | local user = msg.from.id
76 | -- Return end if user was kicked before
77 | if kicktable[user] == true then
78 | return
79 | end
80 | kick_user(user, chat)
81 | if msg.to.type == "user" then
82 | block_user("user#id"..msg.from.id,ok_cb,false)--Block user if spammed in private
83 | end
84 | local name = user_print_name(msg.from)
85 | --save it to log file
86 | savelog(msg.to.id, name.." ["..msg.from.id.."] spammed and kicked ! ")
87 | -- incr it on redis
88 | local gbanspam = 'gban:spam'..msg.from.id
89 | redis:incr(gbanspam)
90 | local gbanspam = 'gban:spam'..msg.from.id
91 | local gbanspamonredis = redis:get(gbanspam)
92 | --Check if user has spammed is group more than 4 times
93 | if gbanspamonredis then
94 | if tonumber(gbanspamonredis) == 4 and not is_owner(msg) then
95 | --Global ban that user
96 | banall_user(msg.from.id)
97 | local gbanspam = 'gban:spam'..msg.from.id
98 | --reset the counter
99 | redis:set(gbanspam, 0)
100 | local username = " "
101 | if msg.from.username ~= nil then
102 | username = msg.from.username
103 | end
104 | local name = user_print_name(msg.from)
105 | --Send this to that chat
106 | send_large_msg("chat#id"..msg.to.id, "User [ "..name.." ]"..msg.from.id.." Globally banned (spamming)")
107 | local log_group = 1 --set log group caht id
108 | --send it to log group
109 | send_large_msg("chat#id"..log_group, "User [ "..name.." ] ( @"..username.." )"..msg.from.id.." Globally banned from ( "..msg.to.print_name.." ) [ "..msg.to.id.." ] (spamming)")
110 | end
111 | end
112 | kicktable[user] = true
113 | msg = nil
114 | end
115 | redis:setex(hash, TIME_CHECK, msgs+1)
116 | end
117 | return msg
118 | end
119 |
120 | local function cron()
121 | --clear that table on the top of the plugins
122 | kicktable = {}
123 | end
124 |
125 | return {
126 | patterns = {},
127 | cron = cron,
128 | pre_process = pre_process
129 | }
130 |
131 | end
132 |
--------------------------------------------------------------------------------
/plugins/antisticker.lua:
--------------------------------------------------------------------------------
1 | -- data saved to data/moderation.json
2 | do
3 |
4 | local administrators_only = 'For administrator only!'
5 | local moderators_only = 'For moderators only!'
6 |
7 | local function create_group(msg)
8 | if not is_admin(msg) then return administrators_only end
9 | local group_creator = msg.from.print_name
10 | create_group_chat (group_creator, group_name, ok_cb, false)
11 | return 'Group '..string.gsub(group_name, '_', ' ')..' has been created.'
12 | end
13 |
14 | local function addgroup(msg)
15 | if not is_admin(msg) then return administrators_only end
16 | local data = load_data(_config.moderation.data)
17 | if data[tostring(msg.to.id)] then
18 | return 'Group is already added.'
19 | end
20 | -- create data array in moderation.json
21 | data[tostring(msg.to.id)] = {
22 | moderators ={},
23 | settings = {
24 | set_name = string.gsub(msg.to.print_name, '_', ' '),
25 | lock_bots = 'no',
26 | lock_name = 'no',
27 | lock_photo = 'no',
28 | lock_member = 'no',
29 | anti_flood = 'no',
30 | welcome = 'no',
31 | sticker = 'ok'
32 | }
33 | }
34 | save_data(_config.moderation.data, data)
35 |
36 | return 'Group has been added.'
37 | end
38 |
39 | local function remgroup(msg)
40 | if not is_admin(msg) then return administrators_only end
41 | local data = load_data(_config.moderation.data)
42 | local receiver = get_receiver(msg)
43 | if not data[tostring(msg.to.id)] then
44 | return 'Group is not added.'
45 | end
46 |
47 | data[tostring(msg.to.id)] = nil
48 | save_data(_config.moderation.data, data)
49 |
50 | return 'Group has been removed'
51 | end
52 |
53 | local function export_chat_link_callback(extra, success, result)
54 | local msg = extra.msg
55 | local group_name = msg.to.title
56 | local data = extra.data
57 | local receiver = get_receiver(msg)
58 | if success == 0 then
59 | return send_large_msg(receiver, 'Cannot generate invite link for this group.\nMake sure you are an admin or a sudoer.')
60 | end
61 | data[tostring(msg.to.id)]['link'] = result
62 | save_data(_config.moderation.data, data)
63 | return send_large_msg(receiver,'Newest generated invite link for '..group_name..' is:\n'..result)
64 | end
65 |
66 | local function set_description(msg, data)
67 | if not is_mod(msg) then return moderators_only end
68 | local data_cat = 'description'
69 | data[tostring(msg.to.id)][data_cat] = deskripsi
70 | save_data(_config.moderation.data, data)
71 |
72 | return 'Set group description to:\n'..deskripsi
73 | end
74 |
75 | local function get_description(msg, data)
76 | local data_cat = 'description'
77 | if not data[tostring(msg.to.id)][data_cat] then
78 | return 'No description available.'
79 | end
80 | local about = data[tostring(msg.to.id)][data_cat]
81 | return string.gsub(msg.to.print_name, "_", " ")..':\n\n'..about
82 | end
83 |
84 | local function set_rules(msg, data)
85 | if not is_mod(msg) then return moderators_only end
86 | local data_cat = 'rules'
87 | data[tostring(msg.to.id)][data_cat] = rules
88 | save_data(_config.moderation.data, data)
89 |
90 | return 'Set group rules to:\n'..rules
91 | end
92 |
93 | local function get_rules(msg, data)
94 | local data_cat = 'rules'
95 | if not data[tostring(msg.to.id)][data_cat] then
96 | return 'No rules available.'
97 | end
98 | local rules = data[tostring(msg.to.id)][data_cat]
99 | local rules = string.gsub(msg.to.print_name, '_', ' ')..' rules:\n\n'..rules
100 | return rules
101 | end
102 |
103 | -- dis/allow APIs bots to enter group. Spam prevention.
104 | local function allow_api_bots(msg, data)
105 | if not is_mod(msg) then return moderators_only end
106 | local group_bot_lock = data[tostring(msg.to.id)]['settings']['lock_bots']
107 | if group_bot_lock == 'no' then
108 | return 'Bots are allowed to enter group.'
109 | else
110 | data[tostring(msg.to.id)]['settings']['lock_bots'] = 'no'
111 | save_data(_config.moderation.data, data)
112 | return 'Group is open for bots.'
113 | end
114 | end
115 |
116 | local function disallow_api_bots(msg, data)
117 | if not is_mod(msg) then return moderators_only end
118 | local group_bot_lock = data[tostring(msg.to.id)]['settings']['lock_bots']
119 | if group_bot_lock == 'yes' then
120 | return 'Group is already locked from bots.'
121 | else
122 | data[tostring(msg.to.id)]['settings']['lock_bots'] = 'yes'
123 | save_data(_config.moderation.data, data)
124 | return 'Group is locked from bots.'
125 | end
126 | end
127 |
128 | -- lock/unlock group name. bot automatically change group name when locked
129 | local function lock_group_name(msg, data)
130 | if not is_mod(msg) then return moderators_only end
131 | local group_name_set = data[tostring(msg.to.id)]['settings']['set_name']
132 | local group_name_lock = data[tostring(msg.to.id)]['settings']['lock_name']
133 | if group_name_lock == 'yes' then
134 | return 'Group name is already locked'
135 | else
136 | data[tostring(msg.to.id)]['settings']['lock_name'] = 'yes'
137 | save_data(_config.moderation.data, data)
138 | data[tostring(msg.to.id)]['settings']['set_name'] = string.gsub(msg.to.print_name, '_', ' ')
139 | save_data(_config.moderation.data, data)
140 | return 'Group name has been locked'
141 | end
142 | end
143 |
144 | local function unlock_group_name(msg, data)
145 | if not is_mod(msg) then return moderators_only end
146 | local group_name_set = data[tostring(msg.to.id)]['settings']['set_name']
147 | local group_name_lock = data[tostring(msg.to.id)]['settings']['lock_name']
148 | if group_name_lock == 'no' then
149 | return 'Group name is already unlocked'
150 | else
151 | data[tostring(msg.to.id)]['settings']['lock_name'] = 'no'
152 | save_data(_config.moderation.data, data)
153 | return 'Group name has been unlocked'
154 | end
155 | end
156 |
157 | --lock/unlock group member. bot automatically kick new added user when locked
158 | local function lock_group_member(msg, data)
159 | if not is_mod(msg) then return moderators_only end
160 | local group_member_lock = data[tostring(msg.to.id)]['settings']['lock_member']
161 | if group_member_lock == 'yes' then
162 | return 'Group members are already locked'
163 | else
164 | data[tostring(msg.to.id)]['settings']['lock_member'] = 'yes'
165 | save_data(_config.moderation.data, data)
166 | end
167 | return 'Group members has been locked'
168 | end
169 |
170 | local function unlock_group_member(msg, data)
171 | if not is_mod(msg) then return moderators_only end
172 | local group_member_lock = data[tostring(msg.to.id)]['settings']['lock_member']
173 | if group_member_lock == 'no' then
174 | return 'Group members are not locked'
175 | else
176 | data[tostring(msg.to.id)]['settings']['lock_member'] = 'no'
177 | save_data(_config.moderation.data, data)
178 | return 'Group members has been unlocked'
179 | end
180 | end
181 |
182 | --lock/unlock group photo. bot automatically keep group photo when locked
183 | local function lock_group_photo(msg, data)
184 | if not is_mod(msg) then return moderators_only end
185 | local group_photo_lock = data[tostring(msg.to.id)]['settings']['lock_photo']
186 | if group_photo_lock == 'yes' then
187 | return 'Group photo is already locked'
188 | else
189 | data[tostring(msg.to.id)]['settings']['set_photo'] = 'waiting'
190 | save_data(_config.moderation.data, data)
191 | end
192 | return 'Please send me the group photo now'
193 | end
194 |
195 | local function unlock_group_photo(msg, data)
196 | if not is_mod(msg) then return moderators_only end
197 | local group_photo_lock = data[tostring(msg.to.id)]['settings']['lock_photo']
198 | if group_photo_lock == 'no' then
199 | return 'Group photo is not locked'
200 | else
201 | data[tostring(msg.to.id)]['settings']['lock_photo'] = 'no'
202 | save_data(_config.moderation.data, data)
203 | return 'Group photo has been unlocked'
204 | end
205 | end
206 |
207 | local function set_group_photo(msg, success, result)
208 | local data = load_data(_config.moderation.data)
209 | local receiver = get_receiver(msg)
210 | if success then
211 | local file = 'data/photos/chat_photo_'..msg.to.id..'.jpg'
212 | print('File downloaded to:', result)
213 | os.rename(result, file)
214 | print('File moved to:', file)
215 | chat_set_photo (receiver, file, ok_cb, false)
216 | data[tostring(msg.to.id)]['settings']['set_photo'] = file
217 | save_data(_config.moderation.data, data)
218 | data[tostring(msg.to.id)]['settings']['lock_photo'] = 'yes'
219 | save_data(_config.moderation.data, data)
220 | send_large_msg(receiver, 'Photo saved!', ok_cb, false)
221 | else
222 | print('Error downloading: '..msg.id)
223 | send_large_msg(receiver, 'Failed, please try again!', ok_cb, false)
224 | end
225 | end
226 |
227 | -- show group settings
228 | local function show_group_settings(msg, data)
229 | if not is_mod(msg) then return moderators_only end
230 | local settings = data[tostring(msg.to.id)]['settings']
231 | if settings.lock_bots == 'yes' then
232 | lock_bots_state = 'ًں”’'
233 | elseif settings.lock_bots == 'no' then
234 | lock_bots_state = 'ًں”“'
235 | end
236 | if settings.lock_name == 'yes' then
237 | lock_name_state = 'ًں”’'
238 | elseif settings.lock_name == 'no' then
239 | lock_name_state = 'ًں”“'
240 | end
241 | if settings.lock_photo == 'yes' then
242 | lock_photo_state = 'ًں”’'
243 | elseif settings.lock_photo == 'no' then
244 | lock_photo_state = 'ًں”“'
245 | end
246 | if settings.lock_member == 'yes' then
247 | lock_member_state = 'ًں”’'
248 | elseif settings.lock_member == 'no' then
249 | lock_member_state = 'ًں”“'
250 | end
251 | if settings.anti_flood ~= 'no' then
252 | antiflood_state = 'ًں”’'
253 | elseif settings.anti_flood == 'no' then
254 | antiflood_state = 'ًں”“'
255 | end
256 | if settings.welcome ~= 'no' then
257 | greeting_state = 'ًں”’'
258 | elseif settings.welcome == 'no' then
259 | greeting_state = 'ًں”“'
260 | end
261 | if settings.sticker ~= 'ok' then
262 | sticker_state = 'ًں”’'
263 | elseif settings.sticker == 'ok' then
264 | sticker_state = 'ًں”“'
265 | end
266 | local text = 'Group settings:\n'
267 | ..'\n'..lock_bots_state..' Lock group from bot : '..settings.lock_bots
268 | ..'\n'..lock_name_state..' Lock group name : '..settings.lock_name
269 | ..'\n'..lock_photo_state..' Lock group photo : '..settings.lock_photo
270 | ..'\n'..lock_member_state..' Lock group member : '..settings.lock_member
271 | ..'\n'..antiflood_state..' Flood protection : '..settings.anti_flood
272 | ..'\n'..greeting_state..' Welcome message : '..settings.welcome
273 | ..'\n'..sticker_state..' Sticker policy : '..settings.sticker
274 | return text
275 | end
276 |
277 | -- media handler. needed by group_photo_lock
278 | local function pre_process(msg)
279 | if not msg.text and msg.media then
280 | msg.text = '['..msg.media.type..']'
281 | end
282 | return msg
283 | end
284 |
285 | function run(msg, matches)
286 |
287 | if not is_chat_msg(msg) then
288 | return "This is not a group chat."
289 | end
290 |
291 | local data = load_data(_config.moderation.data)
292 | local receiver = get_receiver(msg)
293 |
294 | -- create a group
295 | if matches[1] == 'mkgroup' and matches[2] then
296 | group_name = matches[2]
297 | return create_group(msg)
298 | end
299 |
300 | -- add a group to be moderated
301 | if matches[1] == 'addgroup' then
302 | return addgroup(msg)
303 | end
304 |
305 | -- remove group from moderation
306 | if matches[1] == 'remgroup' then
307 | return remgroup(msg)
308 | end
309 |
310 | if msg.media and is_chat_msg(msg) and is_momod(msg) then
311 | if msg.media.type == 'photo' and data[tostring(msg.to.id)] then
312 | if data[tostring(msg.to.id)]['settings']['set_photo'] == 'waiting' then
313 | load_photo(msg.id, set_group_photo, msg)
314 | end
315 | end
316 | end
317 |
318 | if data[tostring(msg.to.id)] then
319 |
320 | local settings = data[tostring(msg.to.id)]['settings']
321 |
322 | if matches[1] == 'setabout' and matches[2] then
323 | deskripsi = matches[2]
324 | return set_description(msg, data)
325 | end
326 |
327 | if matches[1] == 'about' then
328 | return get_description(msg, data)
329 | end
330 |
331 | if matches[1] == 'setrules' then
332 | rules = matches[2]
333 | return set_rules(msg, data)
334 | end
335 |
336 | if matches[1] == 'rules' then
337 | return get_rules(msg, data)
338 | end
339 |
340 | -- group link {get|set}
341 | if matches[1] == 'link' then
342 | if matches[2] == 'get' then
343 | if data[tostring(msg.to.id)]['link'] then
344 | local about = get_description(msg, data)
345 | local link = data[tostring(msg.to.id)]['link']
346 | return about.."\n\n"..link
347 | else
348 | return 'Invite link does not exist.\nTry !link set to generate it.'
349 | end
350 | end
351 | if matches[2] == 'set' and is_mod(msg) then
352 | msgr = export_chat_link(receiver, export_chat_link_callback, {data=data, msg=msg})
353 | end
354 | end
355 |
356 | if matches[1] == 'group' then
357 | -- lock {bot|name|member|photo|sticker}
358 | if matches[2] == 'lock' then
359 | if matches[3] == 'bot' then
360 | return disallow_api_bots(msg, data)
361 | end
362 | if matches[3] == 'name' then
363 | return lock_group_name(msg, data)
364 | end
365 | if matches[3] == 'member' then
366 | return lock_group_member(msg, data)
367 | end
368 | if matches[3] == 'photo' then
369 | return lock_group_photo(msg, data)
370 | end
371 | -- unlock {bot|name|member|photo|sticker}
372 | elseif matches[2] == 'unlock' then
373 | if matches[3] == 'bot' then
374 | return allow_api_bots(msg, data)
375 | end
376 | if matches[3] == 'name' then
377 | return unlock_group_name(msg, data)
378 | end
379 | if matches[3] == 'member' then
380 | return unlock_group_member(msg, data)
381 | end
382 | if matches[3] == 'photo' then
383 | return unlock_group_photo(msg, data)
384 | end
385 | -- view group settings
386 | elseif matches[2] == 'settings' then
387 | return show_group_settings(msg, data)
388 | end
389 | end
390 | if matches[1] == 'sticker' then
391 | if matches[2] == 'warn' then
392 | if welcome_stat ~= 'warn' then
393 | data[tostring(msg.to.id)]['settings']['sticker'] = 'warn'
394 | save_data(_config.moderation.data, data)
395 | end
396 | return '[Alredy Enabled]\nSticker Sender will be warned first, then kicked for second Sticker.'
397 | end
398 | if matches[2] == 'kick' then
399 | if welcome_stat ~= 'kick' then
400 | data[tostring(msg.to.id)]['settings']['sticker'] = 'kick'
401 | save_data(_config.moderation.data, data)
402 | end
403 | return '[Already Enabled]Sticker Sender will be kicked!'
404 | end
405 | if matches[2] == 'ok' then
406 | if welcome_stat == 'ok' then
407 | return '[Already Disabled]Nothing Will Happend If Sticker Sent!'
408 | else
409 | data[tostring(msg.to.id)]['settings']['sticker'] = 'ok'
410 | save_data(_config.moderation.data, data)
411 | return 'Nothing Will Happend If Sticker Sent! '
412 | end
413 | end
414 | end
415 |
416 | -- if group name is renamed
417 | if matches[1] == 'chat_rename' then
418 | if not msg.service then
419 | return 'Are you trying to troll me?'
420 | end
421 | local group_name_set = settings.set_name
422 | local group_name_lock = settings.lock_name
423 | local to_rename = 'chat#id'..msg.to.id
424 | if group_name_lock == 'yes' then
425 | if group_name_set ~= tostring(msg.to.print_name) then
426 | rename_chat(to_rename, group_name_set, ok_cb, false)
427 | end
428 | elseif group_name_lock == 'no' then
429 | return nil
430 | end
431 | end
432 |
433 | -- set group name
434 | if matches[1] == 'setname' and is_mod(msg) then
435 | local new_name = string.gsub(matches[2], '_', ' ')
436 | data[tostring(msg.to.id)]['settings']['set_name'] = new_name
437 | save_data(_config.moderation.data, data)
438 | local group_name_set = data[tostring(msg.to.id)]['settings']['set_name']
439 | local to_rename = 'chat#id'..msg.to.id
440 | rename_chat(to_rename, group_name_set, ok_cb, false)
441 | end
442 |
443 | -- set group photo
444 | if matches[1] == 'setphoto' and is_mod(msg) then
445 | data[tostring(msg.to.id)]['settings']['set_photo'] = 'waiting'
446 | save_data(_config.moderation.data, data)
447 | return 'Please send me new group photo now'
448 | end
449 |
450 | -- if a user is added to group
451 | if matches[1] == 'chat_add_user' then
452 | if not msg.service then
453 | return 'Are you trying to troll me?'
454 | end
455 | local group_member_lock = settings.lock_member
456 | local group_bot_lock = settings.lock_bots
457 | local user = 'user#id'..msg.action.user.id
458 | if group_member_lock == 'yes' then
459 | chat_del_user(receiver, user, ok_cb, true)
460 | -- no APIs bot are allowed to enter chat group.
461 | elseif group_bot_lock == 'yes' and msg.action.user.flags == 4352 then
462 | chat_del_user(receiver, user, ok_cb, true)
463 | elseif group_bot_lock == 'no' or group_member_lock == 'no' then
464 | return nil
465 | end
466 | end
467 |
468 | -- if sticker is sent
469 | if msg.media and msg.media.caption == 'sticker.webp' and not is_momod(msg) then
470 | local user_id = msg.from.id
471 | local chat_id = msg.to.id
472 | local sticker_hash = 'mer_sticker:'..chat_id..':'..user_id
473 | local is_sticker_offender = redis:get(sticker_hash)
474 | if settings.sticker == 'warn' then
475 | if is_sticker_offender then
476 | chat_del_user(receiver, 'user#id'..user_id, ok_cb, true)
477 | redis:del(sticker_hash)
478 | return '[Warned Before]Kicked Because You Have Sent Stickers'
479 | elseif not is_sticker_offender then
480 | redis:set(sticker_hash, true)
481 | return ' Stop Sending Sticker.This Is A Warn Next Time You Will Kicked!'
482 | end
483 | elseif settings.sticker == 'kick' then
484 | chat_del_user(receiver, 'user#id'..user_id, ok_cb, true)
485 | return 'You Kicked Because You Have Sent Stickers??'
486 | elseif settings.sticker == 'ok' then
487 | return nil
488 | end
489 | end
490 |
491 | -- if group photo is deleted
492 | if matches[1] == 'chat_delete_photo' then
493 | if not msg.service then
494 | return 'Are you trying to troll me?'
495 | end
496 | local group_photo_lock = settings.lock_photo
497 | if group_photo_lock == 'yes' then
498 | chat_set_photo (receiver, settings.set_photo, ok_cb, false)
499 | elseif group_photo_lock == 'no' then
500 | return nil
501 | end
502 | end
503 |
504 | -- if group photo is changed
505 | if matches[1] == 'chat_change_photo' and msg.from.id ~= 0 then
506 | if not msg.service then
507 | return 'Are you trying to troll me?'
508 | end
509 | local group_photo_lock = settings.lock_photo
510 | if group_photo_lock == 'yes' then
511 | chat_set_photo (receiver, settings.set_photo, ok_cb, false)
512 | elseif group_photo_lock == 'no' then
513 | return nil
514 | end
515 | end
516 |
517 | end
518 | end
519 |
520 | return {
521 | description = 'Plugin to manage group chat.',
522 | usage = {
523 | admin = {
524 | '!mkgroup : Make/create a new group.',
525 | '!addgroup : Add group to moderation list.',
526 | '!remgroup : Remove group from moderation list.'
527 | },
528 | moderator = {
529 | '!group bot : {Dis}allow APIs bots.',
530 | '!group member : Lock/unlock group member.',
531 | '!group name : Lock/unlock group name.',
532 | '!group photo : Lock/unlock group photo.',
533 | '!group settings : Show group settings.',
534 | '!link : Generate/revoke invite link.',
535 | '!setabout : Set group description.',
536 | '!setname : Set group name.',
537 | '!setphoto : Set group photo.',
538 | '!setrules : Set group rules.',
539 | '!sticker warn : Sticker restriction, sender will be warned for the first violation.',
540 | '!sticker kick : Sticker restriction, sender will be kick.',
541 | '!sticker ok : Disable sticker restriction.'
542 | },
543 | user = {
544 | '!about : Read group description',
545 | '!rules : Read group rules',
546 | '!link : Print invite link'
547 | },
548 | },
549 | patterns = {
550 | --"^!(about)$",
551 | --"^!(addgroup)$",
552 | "%[(audio)%]",
553 | "%[(document)%]",
554 | --"^!(group) (lock) (.*)$",
555 | --"^!(group) (settings)$",
556 | --"^!(group) (unlock) (.*)$",
557 | --"^!(link) (.*)$",
558 | --"^!(mkgroup) (.*)$",
559 | --"%[(photo)%]",
560 | --"^!(remgroup)$",
561 | --"^!(rules)$",
562 | -- "^!(setabout) (.*)$",
563 | -- "^!(setname) (.*)$",
564 | --"^!(setphoto)$",
565 | --"^!(setrules) (.*)$",
566 | "^[!/](sticker) (.*)$",
567 | "^!!tgservice (.+)$",
568 | "%[(video)%]"
569 | },
570 | run = run,
571 | pre_process = pre_process
572 | }
573 |
574 | end
575 |
576 | --To Have This Update Lua-tg-c avaiable on tg folder
577 |
--------------------------------------------------------------------------------
/plugins/antitag.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | if is_owner(msg) then
3 | return
4 | end
5 | local data = load_data(_config.moderation.data)
6 | if data[tostring(msg.to.id)] then
7 | if data[tostring(msg.to.id)]['settings'] then
8 | if data[tostring(msg.to.id)]['settings']['antitag'] then
9 | lock_tag = data[tostring(msg.to.id)]['settings']['antitag']
10 | end
11 | end
12 | end
13 | local chat = get_receiver(msg)
14 | local user = "user#id"..msg.from.id
15 | if lock_tag == "yes" then
16 | send_large_msg(chat, 'tag is not allowed')
17 | chat_del_user(chat, user, ok_cb, true)
18 | end
19 | end
20 |
21 | return {
22 | patterns = {
23 | "#(.*)",
24 | "@(.*)"
25 | },
26 | run = run
27 | }
28 |
29 | -- @BossTGch
30 |
--------------------------------------------------------------------------------
/plugins/arabic_lock.lua:
--------------------------------------------------------------------------------
1 |
2 | antiarabic = {}-- An empty table for solving multiple kicking problem
3 |
4 | do
5 | local function run(msg, matches)
6 | if is_momod(msg) then -- Ignore mods,owner,admins
7 | return
8 | end
9 | local data = load_data(_config.moderation.data)
10 | if data[tostring(msg.to.id)]['settings']['lock_arabic'] then
11 | if data[tostring(msg.to.id)]['settings']['lock_arabic'] == 'yes' then
12 | if antiarabic[msg.from.id] == true then
13 | return
14 | end
15 | send_large_msg("chat#id".. msg.to.id , "Arabic is not allowed here")
16 | local name = user_print_name(msg.from)
17 | savelog(msg.to.id, name.." ["..msg.from.id.."] kicked (arabic was locked) ")
18 | chat_del_user('chat#id'..msg.to.id,'user#id'..msg.from.id,ok_cb,false)
19 | antiarabic[msg.from.id] = true
20 | return
21 | end
22 | end
23 | return
24 | end
25 | local function cron()
26 | antiarabic = {} -- Clear antiarabic table
27 | end
28 | return {
29 | patterns = {
30 | "([\216-\219][\128-\191])"
31 | },
32 | run = run,
33 | cron = cron
34 | }
35 |
36 | end
37 |
--------------------------------------------------------------------------------
/plugins/banhammer.lua:
--------------------------------------------------------------------------------
1 |
2 | local function pre_process(msg)
3 | -- SERVICE MESSAGE
4 | if msg.action and msg.action.type then
5 | local action = msg.action.type
6 | -- Check if banned user joins chat by link
7 | if action == 'chat_add_user_link' then
8 | local user_id = msg.from.id
9 | print('Checking invited user '..user_id)
10 | local banned = is_banned(user_id, msg.to.id)
11 | if banned or is_gbanned(user_id) then -- Check it with redis
12 | print('User is banned!')
13 | local name = user_print_name(msg.from)
14 | savelog(msg.to.id, name.." ["..msg.from.id.."] is banned and kicked ! ")-- Save to logs
15 | kick_user(user_id, msg.to.id)
16 | end
17 | end
18 | -- Check if banned user joins chat
19 | if action == 'chat_add_user' then
20 | local user_id = msg.action.user.id
21 | print('Checking invited user '..user_id)
22 | local banned = is_banned(user_id, msg.to.id)
23 | if banned or is_gbanned(user_id) then -- Check it with redis
24 | print('User is banned!')
25 | local name = user_print_name(msg.from)
26 | savelog(msg.to.id, name.." ["..msg.from.id.."] added a banned user >"..msg.action.user.id)-- Save to logs
27 | kick_user(user_id, msg.to.id)
28 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
29 | redis:incr(banhash)
30 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
31 | local banaddredis = redis:get(banhash)
32 | if banaddredis then
33 | if tonumber(banaddredis) == 4 and not is_owner(msg) then
34 | kick_user(msg.from.id, msg.to.id)-- Kick user who adds ban ppl more than 3 times
35 | end
36 | if tonumber(banaddredis) == 8 and not is_owner(msg) then
37 | ban_user(msg.from.id, msg.to.id)-- Kick user who adds ban ppl more than 7 times
38 | local banhash = 'addedbanuser:'..msg.to.id..':'..msg.from.id
39 | redis:set(banhash, 0)-- Reset the Counter
40 | end
41 | end
42 | end
43 | if data[tostring(msg.to.id)] then
44 | if data[tostring(msg.to.id)]['settings'] then
45 | if data[tostring(msg.to.id)]['settings']['lock_bots'] then
46 | bots_protection = data[tostring(msg.to.id)]['settings']['lock_bots']
47 | end
48 | end
49 | end
50 | if msg.action.user.username ~= nil then
51 | if string.sub(msg.action.user.username:lower(), -3) == 'bot' and not is_momod(msg) and bots_protection == "yes" then --- Will kick bots added by normal users
52 | local name = user_print_name(msg.from)
53 | savelog(msg.to.id, name.." ["..msg.from.id.."] added a bot > @".. msg.action.user.username)-- Save to logs
54 | kick_user(msg.action.user.id, msg.to.id)
55 | end
56 | end
57 | end
58 | -- No further checks
59 | return msg
60 | end
61 | -- banned user is talking !
62 | if msg.to.type == 'chat' then
63 | local data = load_data(_config.moderation.data)
64 | local group = msg.to.id
65 | local texttext = 'groups'
66 | --if not data[tostring(texttext)][tostring(msg.to.id)] and not is_realm(msg) then -- Check if this group is one of my groups or not
67 | --chat_del_user('chat#id'..msg.to.id,'user#id'..our_id,ok_cb,false)
68 | --return
69 | --end
70 | local user_id = msg.from.id
71 | local chat_id = msg.to.id
72 | local banned = is_banned(user_id, chat_id)
73 | if banned or is_gbanned(user_id) then -- Check it with redis
74 | print('Banned user talking!')
75 | local name = user_print_name(msg.from)
76 | savelog(msg.to.id, name.." ["..msg.from.id.."] banned user is talking !")-- Save to logs
77 | kick_user(user_id, chat_id)
78 | msg.text = ''
79 | end
80 | end
81 | return msg
82 | end
83 |
84 | local function kick_ban_res(extra, success, result)
85 | --vardump(result)
86 | --vardump(extra)
87 | local member_id = result.id
88 | local user_id = member_id
89 | local member = result.username
90 | local chat_id = extra.chat_id
91 | local from_id = extra.from_id
92 | local get_cmd = extra.get_cmd
93 | local receiver = "chat#id"..chat_id
94 | if get_cmd == "kick" then
95 | if member_id == from_id then
96 | return send_large_msg(receiver, "You can't kick yourself")
97 | end
98 | if is_momod2(member_id, chat_id) and not is_admin2(sender) then
99 | return send_large_msg(receiver, "You can't kick mods/owner/admins")
100 | end
101 | return kick_user(member_id, chat_id)
102 | elseif get_cmd == 'ban' then
103 | if is_momod2(member_id, chat_id) and not is_admin2(sender) then
104 | return send_large_msg(receiver, "You can't ban mods/owner/admins")
105 | end
106 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] banned')
107 | return ban_user(member_id, chat_id)
108 | elseif get_cmd == 'unban' then
109 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] unbanned')
110 | local hash = 'banned:'..chat_id
111 | redis:srem(hash, member_id)
112 | return 'User '..user_id..' unbanned'
113 | elseif get_cmd == 'banall' then
114 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] globally banned')
115 | return banall_user(member_id, chat_id)
116 | elseif get_cmd == 'unbanall' then
117 | send_large_msg(receiver, 'User @'..member..' ['..member_id..'] un-globally banned')
118 | return unbanall_user(member_id, chat_id)
119 | end
120 | end
121 |
122 | local function run(msg, matches)
123 | if matches[1]:lower() == 'id' then
124 | if msg.to.type == "user" then
125 | return "Bot ID: "..msg.to.id.. "\n\nYour ID: "..msg.from.id
126 | end
127 | if type(msg.reply_id) ~= "nil" then
128 | local name = user_print_name(msg.from)
129 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /id ")
130 | id = get_message(msg.reply_id,get_message_callback_id, false)
131 | elseif matches[1]:lower() == 'id' then
132 | local name = user_print_name(msg.from)
133 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /id ")
134 | return "Group ID for " ..string.gsub(msg.to.print_name, "_", " ").. ":\n\n"..msg.to.id
135 | end
136 | end
137 | if matches[1]:lower() == 'kickme' then-- /kickme
138 | local receiver = get_receiver(msg)
139 | if msg.to.type == 'chat' then
140 | local name = user_print_name(msg.from)
141 | savelog(msg.to.id, name.." ["..msg.from.id.."] left using kickme ")-- Save to logs
142 | chat_del_user("chat#id"..msg.to.id, "user#id"..msg.from.id, ok_cb, false)
143 | end
144 | end
145 |
146 | if not is_momod(msg) then -- Ignore normal users
147 | return
148 | end
149 |
150 | if matches[1]:lower() == "banlist" then -- Ban list !
151 | local chat_id = msg.to.id
152 | if matches[2] and is_admin(msg) then
153 | chat_id = matches[2]
154 | end
155 | return ban_list(chat_id)
156 | end
157 | if matches[1]:lower() == 'ban' then-- /ban
158 | if type(msg.reply_id)~="nil" and is_momod(msg) then
159 | if is_admin(msg) then
160 | local msgr = get_message(msg.reply_id,ban_by_reply_admins, false)
161 | else
162 | msgr = get_message(msg.reply_id,ban_by_reply, false)
163 | end
164 | end
165 | local user_id = matches[2]
166 | local chat_id = msg.to.id
167 | if string.match(matches[2], '^%d+$') then
168 | if tonumber(matches[2]) == tonumber(our_id) then
169 | return
170 | end
171 | if not is_admin(msg) and is_momod2(matches[2], msg.to.id) then
172 | return "you can't ban mods/owner/admins"
173 | end
174 | if tonumber(matches[2]) == tonumber(msg.from.id) then
175 | return "You can't ban your self !"
176 | end
177 | local name = user_print_name(msg.from)
178 | savelog(msg.to.id, name.." ["..msg.from.id.."] baned user ".. matches[2])
179 | ban_user(user_id, chat_id)
180 | else
181 | local cbres_extra = {
182 | chat_id = msg.to.id,
183 | get_cmd = 'ban',
184 | from_id = msg.from.id
185 | }
186 | local username = matches[2]
187 | local username = string.gsub(matches[2], '@', '')
188 | res_user(username, kick_ban_res, cbres_extra)
189 | end
190 | end
191 |
192 |
193 | if matches[1]:lower() == 'unban' then -- /unban
194 | if type(msg.reply_id)~="nil" and is_momod(msg) then
195 | local msgr = get_message(msg.reply_id,unban_by_reply, false)
196 | end
197 | local user_id = matches[2]
198 | local chat_id = msg.to.id
199 | local targetuser = matches[2]
200 | if string.match(targetuser, '^%d+$') then
201 | local user_id = targetuser
202 | local hash = 'banned:'..chat_id
203 | redis:srem(hash, user_id)
204 | local name = user_print_name(msg.from)
205 | savelog(msg.to.id, name.." ["..msg.from.id.."] unbaned user ".. matches[2])
206 | return 'User '..user_id..' unbanned'
207 | else
208 | local cbres_extra = {
209 | chat_id = msg.to.id,
210 | get_cmd = 'unban',
211 | from_id = msg.from.id
212 | }
213 | local username = matches[2]
214 | local username = string.gsub(matches[2], '@', '')
215 | res_user(username, kick_ban_res, cbres_extra)
216 | end
217 | end
218 |
219 | if matches[1]:lower() == 'kick' then
220 | if type(msg.reply_id)~="nil" and is_momod(msg) then
221 | if is_admin(msg) then
222 | local msgr = get_message(msg.reply_id,Kick_by_reply_admins, false)
223 | else
224 | msgr = get_message(msg.reply_id,Kick_by_reply, false)
225 | end
226 | end
227 |
228 | if string.match(matches[2], '^%d+$') then
229 | if tonumber(matches[2]) == tonumber(our_id) then
230 | return
231 | end
232 | if not is_admin(msg) and is_momod2(matches[2], msg.to.id) then
233 | return "you can't kick mods/owner/admins"
234 | end
235 | if tonumber(matches[2]) == tonumber(msg.from.id) then
236 | return "You can't kick your self !"
237 | end
238 | local user_id = matches[2]
239 | local chat_id = msg.to.id
240 | name = user_print_name(msg.from)
241 | savelog(msg.to.id, name.." ["..msg.from.id.."] kicked user ".. matches[2])
242 | kick_user(user_id, chat_id)
243 | else
244 | local cbres_extra = {
245 | chat_id = msg.to.id,
246 | get_cmd = 'kick',
247 | from_id = msg.from.id
248 | }
249 | local username = matches[2]
250 | local username = string.gsub(matches[2], '@', '')
251 | res_user(username, kick_ban_res, cbres_extra)
252 | end
253 | end
254 |
255 |
256 | if not is_admin(msg) then
257 | return
258 | end
259 |
260 | if matches[1]:lower() == 'banall' then -- Global ban
261 | if type(msg.reply_id) ~="nil" and is_admin(msg) then
262 | return get_message(msg.reply_id,banall_by_reply, false)
263 | end
264 | local user_id = matches[2]
265 | local chat_id = msg.to.id
266 | local targetuser = matches[2]
267 | if string.match(targetuser, '^%d+$') then
268 | if tonumber(matches[2]) == tonumber(our_id) then
269 | return false
270 | end
271 | banall_user(targetuser)
272 | return 'User ['..user_id..' ] globally banned'
273 | else
274 | local cbres_extra = {
275 | chat_id = msg.to.id,
276 | get_cmd = 'banall',
277 | from_id = msg.from.id
278 | }
279 | local username = matches[2]
280 | local username = string.gsub(matches[2], '@', '')
281 | res_user(username, kick_ban_res, cbres_extra)
282 | end
283 | end
284 | if matches[1]:lower() == 'unbanall' then -- Global unban
285 | local user_id = matches[2]
286 | local chat_id = msg.to.id
287 | if string.match(matches[2], '^%d+$') then
288 | if tonumber(matches[2]) == tonumber(our_id) then
289 | return false
290 | end
291 | unbanall_user(user_id)
292 | return 'User ['..user_id..' ] removed from global ban list'
293 | else
294 | local cbres_extra = {
295 | chat_id = msg.to.id,
296 | get_cmd = 'unbanall',
297 | from_id = msg.from.id
298 | }
299 | local username = matches[2]
300 | local username = string.gsub(matches[2], '@', '')
301 | res_user(username, kick_ban_res, cbres_extra)
302 | end
303 | end
304 | if matches[1]:lower() == "gbanlist" then -- Global ban list
305 | return banall_list()
306 | end
307 | end
308 |
309 | return {
310 | patterns = {
311 | "^[!/]([Bb]anall) (.*)$",
312 | "^[!/]([Bb]anall)$",
313 | "^[!/]([Bb]anlist) (.*)$",
314 | "^[!/]([Bb]anlist)$",
315 | "^[!/]([Gg]banlist)$",
316 | "^[!/]([Bb]an) (.*)$",
317 | "^[!/]([Kk]ick)$",
318 | "^[!/]([Uu]nban) (.*)$",
319 | "^[!/]([Uu]nbanall) (.*)$",
320 | "^[!/]([Uu]nbanall)$",
321 | "^[!/]([Kk]ick) (.*)$",
322 | "^[!/]([Kk]ickme)$",
323 | "^[!/]([Bb]an)$",
324 | "^[!/]([Uu]nban)$",
325 | "^[!/]([Ii]d)$",
326 | "^!!tgservice (.+)$"
327 | },
328 | run = run,
329 | pre_process = pre_process
330 | }
331 |
332 |
--------------------------------------------------------------------------------
/plugins/broadcast.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | if matches[1] == 'bc' and is_admin(msg) then
3 | local response = matches[3]
4 | send_large_msg("chat#id"..matches[2], response)
5 | end
6 | if matches[1] == 'broadcast' then
7 | if is_sudo(msg) then -- Only sudo !
8 | local data = load_data(_config.moderation.data)
9 | local groups = 'groups'
10 | local response = matches[2]
11 | for k,v in pairs(data[tostring(groups)]) do
12 | chat_id = v
13 | local receiver = 'chat#id'..chat_id
14 | send_large_msg(receiver, response)
15 | end
16 | end
17 | end
18 | end
19 | return {
20 | patterns = {
21 | "^[!/](broadcast) +(.+)$",
22 | "^[!/](bc) (%d+) (.*)$"
23 | },
24 | run = run
25 | }
26 |
--------------------------------------------------------------------------------
/plugins/chating.lua:
--------------------------------------------------------------------------------
1 | local function run(msg)
2 | if msg.text == "hi" then
3 | return "Hello bb"
4 | end
5 | if msg.text == "Hi" then
6 | return "Hello honey"
7 | end
8 | if msg.text == "Hello" then
9 | return "Hi bb"
10 | end
11 | if msg.text == "hello" then
12 | return "Hi honey"
13 | end
14 | if msg.text == "Salam" then
15 | return "Salam aleykom"
16 | end
17 | if msg.text == "salam" then
18 | return "va aleykol asalam"
19 | end
20 | if msg.text == "BossTG" then
21 | return "Sardare shoma"
22 | end
23 | if msg.text == "Boss" then
24 | return "sardar"
25 | end
26 | if msg.text == "kir" then
27 | return "to konet"
28 | end
29 | if msg.text == "boss" then
30 | return "Yes?"
31 | end
32 | if msg.text == "boss" then
33 | return "What?"
34 | end
35 | if msg.text == "bot" then
36 | return "hum?"
37 | end
38 | if msg.text == "Bot" then
39 | return "Huuuum?"
40 | end
41 | if msg.text == "?" then
42 | return "Hum??"
43 | end
44 | if msg.text == "Bye" then
45 | return "Babay"
46 | end
47 | if msg.text == "bye" then
48 | return "Bye Bye"
49 | end
50 | end
51 |
52 | return {
53 | description = "Chat With Robot Server",
54 | usage = "chat with robot",
55 | patterns = {
56 | "^[Hh]i$",
57 | "^[Hh]ello$",
58 | "^BossTG$",
59 | "^Boss$",
60 | "^[Bb]ot$",
61 | "^boss$",
62 | "^[Bb]ye$",
63 | "^?$",
64 | "^[Ss]alam$",
65 | },
66 | run = run,
67 | --privileged = true,
68 | pre_process = pre_process
69 | }
70 |
--------------------------------------------------------------------------------
/plugins/download_media.lua:
--------------------------------------------------------------------------------
1 | local function callback(extra, success, result) -- Calback for load_photo in line 17
2 | if success then
3 | print('File downloaded to:', result)
4 | else
5 | print('Error downloading: '..extra)
6 | end
7 | end
8 |
9 | local function run(msg, matches)
10 | if not is_momod(msg) then -- Will download images only from mods,owner and admins
11 | return
12 | end
13 | if msg.media then
14 | if msg.media.type == 'photo' then
15 | load_photo(msg.id, callback, msg.id)
16 | end
17 | end
18 | end
19 |
20 | local function pre_process(msg)
21 | if not msg.text and msg.media then
22 | msg.text = '['..msg.media.type..']'
23 | end
24 | return msg
25 | end
26 |
27 | return {
28 | run = run,
29 | patterns = {
30 | '%[(photo)%]'
31 | },
32 | pre_process = pre_process
33 | }
34 |
--------------------------------------------------------------------------------
/plugins/echoall.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | local text = matches[1]
3 | local b = 1
4 |
5 | while b ~= 0 do
6 | text = text:trim()
7 | text,b = text:gsub('^!+','')
8 | end
9 | return text
10 | end
11 |
12 | return {
13 | description = "Simplest plugin ever!",
14 | usage = "!echo [whatever]: echoes the msg",
15 | patterns = {
16 | "^(.+)$"
17 | },
18 | run = run
19 | }
20 |
21 | -- Shared by @BossTGch
22 | -- musicgold.loxblog.com
23 |
--------------------------------------------------------------------------------
/plugins/echofile.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | local text = matches[1]
3 | local b = 1
4 |
5 | while b ~= 0 do
6 | text = text:trim()
7 | text,b = text:gsub('^!+','')
8 | end
9 | local file = io.open("./data/echo"..msg.from.id..matches[2], "w")
10 | file:write(text)
11 | file:flush()
12 | file:close()
13 | send_document("chat#id"..msg.to.id,"./data/echo"..msg.from.id..matches[2], ok_cb, false)
14 | end
15 |
16 | return {
17 | description = "Simplest plugin ever!",
18 | usage = "!echo [whatever]: echoes the msg",
19 | patterns = {
20 | "^!echo +(.+) (.*)$"
21 | },
22 | run = run
23 | }
24 |
--------------------------------------------------------------------------------
/plugins/expire.lua:
--------------------------------------------------------------------------------
1 | local filename='data/expire.lua'
2 | local cronned = load_from_file(filename)
3 |
4 | local function save_cron(msg, text,date)
5 | local origin = get_receiver(msg)
6 | if not cronned[date] then
7 | cronned[date] = {}
8 | end
9 | local arr = { origin, text } ;
10 | table.insert(cronned[date], arr)
11 | serialize_to_file(cronned, filename)
12 | return 'Saved!'
13 | end
14 |
15 | local function delete_cron(date)
16 | for k,v in pairs(cronned) do
17 | if k == date then
18 | cronned[k]=nil
19 | end
20 | end
21 | serialize_to_file(cronned, filename)
22 | end
23 |
24 | local function cron()
25 | for date, values in pairs(cronned) do
26 | if date < os.time() then --time's up
27 | send_msg(values[1][1], "Time's up:"..values[1][2], ok_cb, false)
28 | delete_cron(date)
29 | end
30 |
31 | end
32 | end
33 |
34 | local function actually_run(msg, delay,text)
35 | if (not delay or not text) then
36 | return "Usage: !remind [delay: 2h3m1s] text"
37 | end
38 | save_cron(msg, text,delay)
39 | return "I'll remind you on " .. os.date("%x at %H:%M:%S",delay) .. " about '" .. text .. "'"
40 | end
41 |
42 | local function run(msg, matches)
43 | local sum = 0
44 | for i = 1, #matches-1 do
45 | local b,_ = string.gsub(matches[i],"[a-zA-Z]","")
46 | if string.find(matches[i], "s") then
47 | sum=sum+b
48 | end
49 | if string.find(matches[i], "m") then
50 | sum=sum+b*60
51 | end
52 | if string.find(matches[i], "h") then
53 | sum=sum+b*3600
54 | end
55 | end
56 |
57 | local date=sum+os.time()
58 | local text = matches[#matches]
59 |
60 | local text = actually_run(msg, date, text)
61 | return text
62 | end
63 |
64 | return {
65 |
66 | patterns = {
67 | "^[!/](expire) ([0-9]+[hmsdHMSD]) (.+)$", --- e.g : for a month enter : 720hms - then , in text enter gp id and admin id
68 | "^[!/](expire) ([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD]) (.+)$",
69 | "^[!/](expire) ([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD])([0-9]+[hmsdHMSD]) (.+)$"
70 | },
71 | run = run,
72 | cron = cron
73 | }
74 |
--------------------------------------------------------------------------------
/plugins/feedback.lua:
--------------------------------------------------------------------------------
1 | do
2 | function run(msg, matches)
3 |
4 | local fuse = 'New FeedBack\n\nId : ' .. msg.from.id .. '\n\nName: ' .. msg.from.print_name ..'\n\nUsername: @' .. msg.from.username .. '\n\nThe Pm:\n' .. matches[1]
5 | local fuses = '!printf user#id' .. msg.from.id
6 |
7 |
8 | local text = matches[1]
9 | local chat = "chat#id"..YourChatId
10 | --like : local chat = "chat#id"..12345678
11 |
12 | local sends = send_msg(chat, fuse, ok_cb, false)
13 | return 'Sent!'
14 |
15 | end
16 | end
17 | return {
18 |
19 | description = "Feedback",
20 |
21 | usage = "!feedback message",
22 | patterns = {
23 | "^[!/][Ff]eedback (.*)$"
24 |
25 | },
26 | run = run
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/plugins/get.lua:
--------------------------------------------------------------------------------
1 | local function get_variables_hash(msg)
2 | if msg.to.type == 'chat' then
3 | return 'chat:'..msg.to.id..':variables'
4 | end
5 | end
6 |
7 | local function get_value(msg, var_name)
8 | local hash = get_variables_hash(msg)
9 | if hash then
10 | local value = redis:hget(hash, var_name)
11 | if not value then
12 | return
13 | else
14 | return var_name..' :\n'..value
15 | end
16 | end
17 | end
18 |
19 | local function run(msg, matches)
20 | if not is_momod(msg) then -- only for mods,owner and admins
21 | return
22 | end
23 | if matches[2] then
24 | local name = user_print_name(msg.from)
25 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /get ".. matches[2])-- save to logs
26 | return get_value(msg, matches[2])
27 | else
28 | return
29 | end
30 | end
31 |
32 | return {
33 | patterns = {
34 | "^([!/]get) (.+)$"
35 | },
36 | run = run
37 | }
38 |
--------------------------------------------------------------------------------
/plugins/helpen.lua:
--------------------------------------------------------------------------------
1 | do
2 | function run(msg, matches)
3 | return [[
4 | Commands list :
5 |
6 | !kick [username|id]
7 | You can also by reply
8 | 〰〰〰〰〰〰
9 | !ban [ username|id]
10 | You can also by reply
11 | 〰〰〰〰〰〰
12 | !unban [id]
13 | You can also by reply
14 | 〰〰〰〰〰〰
15 | !inviter
16 | you can invite inviter bot to the group
17 | 〰〰〰〰〰〰
18 | !insudo
19 | you can invite sudo to the group
20 | 〰〰〰〰〰〰
21 | !who
22 | Members list
23 | 〰〰〰〰〰〰
24 | !modlist
25 | Moderators list
26 | 〰〰〰〰〰〰
27 | !promote [username]
28 | Promote someone
29 | 〰〰〰〰〰〰
30 | !demote [username]
31 | Demote someone
32 | 〰〰〰〰〰〰
33 | !kickme
34 | Will kick user
35 | 〰〰〰〰〰〰
36 | !about
37 | Group description
38 | 〰〰〰〰〰〰
39 | !setphoto
40 | locks group photo
41 | 〰〰〰〰〰〰
42 | !setname [name]
43 | Set group name
44 | 〰〰〰〰〰〰
45 | !rules
46 | Group rules
47 | 〰〰〰〰〰〰
48 | !id
49 | group id & user id
50 | 〰〰〰〰〰〰
51 | !help
52 | This help persian text
53 | 〰〰〰〰〰〰
54 | !lock [member|name|bots|leave|arabic|tag|ads]
55 | Locks [member|name|bots|leaveing|arabic|tag|ads]
56 | 〰〰〰〰〰〰
57 | !unlock [member|name|bots|leave|arabic|tag|ads]
58 | Unlocks [member|name|bots|leaving|arabic|tag|ads]
59 | 〰〰〰〰〰〰
60 | !set rules
61 | Set as rules
62 | 〰〰〰〰〰〰
63 | !set about
64 | Set as about
65 | 〰〰〰〰〰〰
66 | !settings
67 | Returns group settings
68 | 〰〰〰〰〰〰
69 | !newlink
70 | create/revoke your group link
71 | 〰〰〰〰〰〰
72 | !link
73 | returns group link
74 | 〰〰〰〰〰〰
75 | !owner
76 | returns group owner id
77 | 〰〰〰〰〰〰
78 | !setowner [id]
79 | Will set id as owner
80 | 〰〰〰〰〰〰
81 | !setflood [value]
82 | Set [value] as flood sensitivity
83 | 〰〰〰〰〰〰
84 | !stats
85 | Simple message statistics
86 | 〰〰〰〰〰〰
87 | !save [value]
88 | Save as [value]
89 | 〰〰〰〰〰〰
90 | !get [value]
91 | Returns text of [value]
92 | 〰〰〰〰〰〰
93 | !clean [modlist|rules|about]
94 | Will clear [modlist|rules|about]
95 | 〰〰〰〰〰〰
96 | !info
97 | send you a user stats
98 | worked by reply
99 | 〰〰〰〰〰〰
100 | !sticker [warn|kick|ok]
101 | warn : warning send sticker
102 | kick : send sticker=kick
103 | ok : send sticker open
104 | 〰〰〰〰〰〰
105 | !tagall [text]
106 | tag users && send your message
107 | 〰〰〰〰〰〰
108 | BossTG
109 | send about BossTG
110 | 〰〰〰〰〰〰
111 | !all
112 | see all about group
113 | 〰〰〰〰〰〰
114 | !block (user-id)
115 | !unblock (user-id)
116 | block - unblock users (sudo only)
117 | 〰〰〰〰〰〰
118 | !kickinactive
119 | kick inactive users from Group
120 | 〰〰〰〰〰〰
121 | !pv [user-id] [text]
122 | send text to user-id (sudo only)
123 | 〰〰〰〰〰〰
124 | !linkpv
125 | send link to your pv ( bot reported)
126 | 〰〰〰〰〰〰
127 | !banlist
128 | group ban list
129 | 〰〰〰〰〰〰
130 | !welcome [group|pm|disable]
131 | set welcome to group
132 | set welcome to pm (pv)
133 | set welcome disable
134 | 〰〰〰〰〰〰
135 | **U can use "/" & "!"
136 | 〰〰〰〰〰〰
137 | *Only owner & mods can add bots to group
138 | 〰〰〰〰〰〰
139 | *Only moderators & owner can use kick,ban,unban,newlink,link,setphoto,setname,lock,unlock,set rules,set about,settings commands
140 | 〰〰〰〰〰〰
141 | *Only owner can use res,setowner,promote,demote,log commands
142 |
143 | sudo: @tehran980 , @boy_crazy , @joker_admin1
144 |
145 | @BossTGch 👈👈pls join
146 | ]]
147 | end
148 |
149 | return {
150 | description = "Boss",
151 | patterns = {"^[!/%$+=.-*&][Hh]elpen$"},
152 | run = run
153 | }
154 | end
155 |
--------------------------------------------------------------------------------
/plugins/info.lua:
--------------------------------------------------------------------------------
1 | do
2 | local Arian = 122662162 --put your id here(BOT OWNER ID)
3 |
4 | local function setrank(msg, name, value) -- setrank function
5 | local hash = nil
6 | if msg.to.type == 'chat' then
7 | hash = 'rank:'..msg.to.id..':variables'
8 | end
9 | if hash then
10 | redis:hset(hash, name, value)
11 | return send_msg('chat#id'..msg.to.id, 'مقام کاربر ('..name..') به '..value..' تغییر داده شد ', ok_cb, true)
12 | end
13 | end
14 | local function res_user_callback(extra, success, result) -- /info function
15 | if success == 1 then
16 | if result.username then
17 | Username = '@'..result.username
18 | else
19 | Username = 'ندارد'
20 | end
21 | local text = 'نام کامل : '..(result.first_name or '')..' '..(result.last_name or '')..'\n'
22 | ..'یوزر: '..Username..'\n'
23 | ..'ایدی کاربری : '..result.id..'\n\n'
24 | local hash = 'rank:'..extra.chat2..':variables'
25 | local value = redis:hget(hash, result.id)
26 | if not value then
27 | if result.id == tonumber(Arian) then
28 | text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n'
29 | elseif is_admin2(result.id) then
30 | text = text..'مقام : ادمین ربات (Admin) \n\n'
31 | elseif is_owner2(result.id, extra.chat2) then
32 | text = text..'مقام : مدیر کل گروه (Owner) \n\n'
33 | elseif is_momod2(result.id, extra.chat2) then
34 | text = text..'مقام : مدیر گروه (Moderator) \n\n'
35 | else
36 | text = text..'مقام : کاربر (Member) \n\n'
37 | end
38 | else
39 | text = text..'مقام : '..value..'\n\n'
40 | end
41 | local uhash = 'user:'..result.id
42 | local user = redis:hgetall(uhash)
43 | local um_hash = 'msgs:'..result.id..':'..extra.chat2
44 | user_info_msgs = tonumber(redis:get(um_hash) or 0)
45 | text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n'
46 | text = text..'@BossTGch Team'
47 | send_msg(extra.receiver, text, ok_cb, true)
48 | else
49 | send_msg(extra.receiver, extra.user..' نام کاربری مورد نظر یافت نشد.', ok_cb, false)
50 | end
51 | end
52 |
53 | local function action_by_id(extra, success, result) -- /info function
54 | if success == 1 then
55 | if result.username then
56 | Username = '@'..result.username
57 | else
58 | Username = 'ندارد'
59 | end
60 | local text = 'نام کامل : '..(result.first_name or '')..' '..(result.last_name or '')..'\n'
61 | ..'یوزر: '..Username..'\n'
62 | ..'ایدی کاربری : '..result.id..'\n\n'
63 | local hash = 'rank:'..extra.chat2..':variables'
64 | local value = redis:hget(hash, result.id)
65 | if not value then
66 | if result.id == tonumber(Arian) then
67 | text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n'
68 | elseif is_admin2(result.id) then
69 | text = text..'مقام : ادمین ربات (Admin) \n\n'
70 | elseif is_owner2(result.id, extra.chat2) then
71 | text = text..'مقام : مدیر کل گروه (Owner) \n\n'
72 | elseif is_momod2(result.id, extra.chat2) then
73 | text = text..'مقام : مدیر گروه (Moderator) \n\n'
74 | else
75 | text = text..'مقام : کاربر (Member) \n\n'
76 | end
77 | else
78 | text = text..'مقام : '..value..'\n\n'
79 | end
80 | local uhash = 'user:'..result.id
81 | local user = redis:hgetall(uhash)
82 | local um_hash = 'msgs:'..result.id..':'..extra.chat2
83 | user_info_msgs = tonumber(redis:get(um_hash) or 0)
84 | text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n'
85 | text = text..'@BossTGch Team'
86 | send_msg(extra.receiver, text, ok_cb, true)
87 | else
88 | send_msg(extra.receiver, 'ایدی شخص مورد نظر در سیستم ثبت نشده است.\nاز دستور زیر استفاده کنید\n/info @username', ok_cb, false)
89 | end
90 | end
91 |
92 | local function action_by_reply(extra, success, result)-- (reply) /info function
93 | if result.from.username then
94 | Username = '@'..result.from.username
95 | else
96 | Username = 'ندارد'
97 | end
98 | local text = 'نام کامل : '..(result.from.first_name or '')..' '..(result.from.last_name or '')..'\n'
99 | ..'یوزر: '..Username..'\n'
100 | ..'ایدی کاربری : '..result.from.id..'\n\n'
101 | local hash = 'rank:'..result.to.id..':variables'
102 | local value = redis:hget(hash, result.from.id)
103 | if not value then
104 | if result.from.id == tonumber(Arian) then
105 | text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n'
106 | elseif is_admin2(result.from.id) then
107 | text = text..'مقام : ادمین ربات (Admin) \n\n'
108 | elseif is_owner2(result.from.id, result.to.id) then
109 | text = text..'مقام : مدیر کل گروه (Owner) \n\n'
110 | elseif is_momod2(result.from.id, result.to.id) then
111 | text = text..'مقام : مدیر گروه (Moderator) \n\n'
112 | else
113 | text = text..'مقام : کاربر (Member) \n\n'
114 | end
115 | else
116 | text = text..'مقام : '..value..'\n\n'
117 | end
118 | local user_info = {}
119 | local uhash = 'user:'..result.from.id
120 | local user = redis:hgetall(uhash)
121 | local um_hash = 'msgs:'..result.from.id..':'..result.to.id
122 | user_info_msgs = tonumber(redis:get(um_hash) or 0)
123 | text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n'
124 | text = text..'@BossTGch'
125 | send_msg(extra.receiver, text, ok_cb, true)
126 | end
127 |
128 | local function action_by_reply2(extra, success, result)
129 | local value = extra.value
130 | setrank(result, result.from.id, value)
131 | end
132 |
133 | local function run(msg, matches)
134 | if matches[1]:lower() == 'setrank' then
135 | local hash = 'usecommands:'..msg.from.id..':'..msg.to.id
136 | redis:incr(hash)
137 | if not is_sudo(msg) then
138 | return "Only for Sudo"
139 | end
140 | local receiver = get_receiver(msg)
141 | local Reply = msg.reply_id
142 | if msg.reply_id then
143 | local value = string.sub(matches[2], 1, 1000)
144 | msgr = get_message(msg.reply_id, action_by_reply2, {receiver=receiver, Reply=Reply, value=value})
145 | else
146 | local name = string.sub(matches[2], 1, 50)
147 | local value = string.sub(matches[3], 1, 1000)
148 | local text = setrank(msg, name, value)
149 |
150 | return text
151 | end
152 | end
153 | if matches[1]:lower() == 'info' and not matches[2] then
154 | local receiver = get_receiver(msg)
155 | local Reply = msg.reply_id
156 | if msg.reply_id then
157 | msgr = get_message(msg.reply_id, action_by_reply, {receiver=receiver, Reply=Reply})
158 | else
159 | if msg.from.username then
160 | Username = '@'..msg.from.username
161 | else
162 | Username = 'ندارد'
163 | end
164 | local text = 'نام : '..(msg.from.first_name or 'ندارد')..'\n'
165 | local text = text..'فامیل : '..(msg.from.last_name or 'ندارد')..'\n'
166 | local text = text..'یوزر : '..Username..'\n'
167 | local text = text..'ایدی کاربری : '..msg.from.id..'\n\n'
168 | local hash = 'rank:'..msg.to.id..':variables'
169 | if hash then
170 | local value = redis:hget(hash, msg.from.id)
171 | if not value then
172 | if msg.from.id == tonumber(Arian) then
173 | text = text..'مقام : مدیر کل ربات (Executive Admin) \n\n'
174 | elseif is_sudo(msg) then
175 | text = text..'مقام : ادمین ربات (Admin) \n\n'
176 | elseif is_owner(msg) then
177 | text = text..'مقام : مدیر کل گروه (Owner) \n\n'
178 | elseif is_momod(msg) then
179 | text = text..'مقام : مدیر گروه (Moderator) \n\n'
180 | else
181 | text = text..'مقام : کاربر (Member) \n\n'
182 | end
183 | else
184 | text = text..'مقام : '..value..'\n'
185 | end
186 | end
187 |
188 | local uhash = 'user:'..msg.from.id
189 | local user = redis:hgetall(uhash)
190 | local um_hash = 'msgs:'..msg.from.id..':'..msg.to.id
191 | user_info_msgs = tonumber(redis:get(um_hash) or 0)
192 | text = text..'تعداد پیام های فرستاده شده : '..user_info_msgs..'\n\n'
193 | if msg.to.type == 'chat' then
194 | text = text..'نام گروه : '..msg.to.title..'\n'
195 | text = text..'ایدی گروه : '..msg.to.id
196 | end
197 | text = text..'\n\n@BossTGch Team'
198 | return send_msg(receiver, text, ok_cb, true)
199 | end
200 | end
201 | if matches[1]:lower() == 'info' and matches[2] then
202 | local user = matches[2]
203 | local chat2 = msg.to.id
204 | local receiver = get_receiver(msg)
205 | if string.match(user, '^%d+$') then
206 | user_info('user#id'..user, action_by_id, {receiver=receiver, user=user, text=text, chat2=chat2})
207 | elseif string.match(user, '^@.+$') then
208 | username = string.gsub(user, '@', '')
209 | msgr = res_user(username, res_user_callback, {receiver=receiver, user=user, text=text, chat2=chat2})
210 | end
211 | end
212 | end
213 |
214 | return {
215 | description = 'Know your information or the info of a chat members.',
216 | usage = {
217 | '!info: Return your info and the chat info if you are in one.',
218 | '(Reply)!info: Return info of replied user if used by reply.',
219 | '!info : Return the info\'s of the .',
220 | '!info @: Return the member @ information from the current chat.',
221 | '!setrank : change members rank.',
222 | '(Reply)!setrank : change members rank.',
223 | },
224 | patterns = {
225 | "^[/!]([Ii][Nn][Ff][Oo])$",
226 | "^[/!]([Ii][Nn][Ff][Oo]) (.*)$",
227 | "^[/!]([Ss][Ee][Tt][Rr][Aa][Nn][Kk]) (%d+) (.*)$",
228 | "^[/!]([Ss][Ee][Tt][Rr][Aa][Nn][Kk]) (.*)$",
229 | },
230 | run = run
231 | }
232 |
233 | end
234 |
235 | -- @BossTGch
236 |
--------------------------------------------------------------------------------
/plugins/inpm.lua:
--------------------------------------------------------------------------------
1 | do
2 | local function pairsByKeys (t, f)
3 | local a = {}
4 | for n in pairs(t) do table.insert(a, n) end
5 | table.sort(a, f)
6 | local i = 0 -- iterator variable
7 | local iter = function () -- iterator function
8 | i = i + 1
9 | if a[i] == nil then return nil
10 | else return a[i], t[a[i]]
11 | end
12 | end
13 | return iter
14 | end
15 |
16 | local function chat_list(msg)
17 | local data = load_data(_config.moderation.data)
18 | local groups = 'groups'
19 | if not data[tostring(groups)] then
20 | return 'No groups at the moment'
21 | end
22 | local message = 'List of Groups:\n*Use /join (ID) to join*\n\n '
23 | for k,v in pairs(data[tostring(groups)]) do
24 | local settings = data[tostring(v)]['settings']
25 | for m,n in pairsByKeys(settings) do
26 | if m == 'set_name' then
27 | name = n
28 | end
29 | end
30 |
31 | message = message .. '👥 '.. name .. ' (ID: ' .. v .. ')\n\n '
32 | end
33 | local file = io.open("./groups/lists/listed_groups.txt", "w")
34 | file:write(message)
35 | file:flush()
36 | file:close()
37 | return message
38 | end
39 |
40 | local function run(msg, matches)
41 | if msg.to.type ~= 'chat' or is_sudo(msg) or is_admin(msg) and is_realm(msg) then
42 | local data = load_data(_config.moderation.data)
43 | if matches[1] == 'join' and data[tostring(matches[2])] then
44 | if is_banned(msg.from.id, matches[2]) then
45 | return 'You are banned.'
46 | end
47 | if is_gbanned(msg.from.id) then
48 | return 'You are globally banned.'
49 | end
50 | if data[tostring(matches[2])]['settings']['lock_member'] == 'yes' and not is_owner2(msg.from.id, matches[2]) then
51 | return 'Group is private.'
52 | end
53 | local chat_id = "chat#id"..matches[2]
54 | local user_id = "user#id"..msg.from.id
55 | chat_add_user(chat_id, user_id, ok_cb, false)
56 | local group_name = data[tostring(matches[2])]['settings']['set_name']
57 | return "Added you to chat:\n\n👥"..group_name.." (ID:"..matches[2]..")"
58 | elseif matches[1] == 'join' and not data[tostring(matches[2])] then
59 |
60 | return "Chat not found."
61 | end
62 | if matches[1] == 'chats'then
63 | if is_admin(msg) and msg.to.type == 'chat' then
64 | return chat_list(msg)
65 | elseif msg.to.type ~= 'chat' then
66 | return chat_list(msg)
67 | end
68 | end
69 | if matches[1] == 'chatlist'then
70 | if is_admin(msg) and msg.to.type == 'chat' then
71 | send_document("chat#id"..msg.from.id, "./groups/lists/listed_groups.txt", ok_cb, false)
72 | elseif msg.to.type ~= 'chat' then
73 | send_document("user#id"..msg.from.id, "./groups/lists/listed_groups.txt", ok_cb, false)
74 | end
75 | end
76 | end
77 | end
78 |
79 | return {
80 | patterns = {
81 | "^[/!](chats)$",
82 | "^[/!](chatlist)$",
83 | "^[/!](join) (.*)$",
84 | "^[/!](kickme) (.*)$",
85 | "^!!tgservice (chat_add_user)$"
86 | },
87 | run = run,
88 | }
89 | end
90 |
91 |
--------------------------------------------------------------------------------
/plugins/inrealm.lua:
--------------------------------------------------------------------------------
1 | -- data saved to moderation.json
2 | -- check moderation plugin
3 | do
4 |
5 | local function create_group(msg)
6 | -- superuser and admins only (because sudo are always has privilege)
7 | if is_sudo(msg) or is_realm(msg) and is_admin(msg) then
8 | local group_creator = msg.from.print_name
9 | create_group_chat (group_creator, group_name, ok_cb, false)
10 | return 'Group [ '..string.gsub(group_name, '_', ' ')..' ] has been created.'
11 | end
12 | end
13 |
14 | local function create_realm(msg)
15 | -- superuser and admins only (because sudo are always has privilege)
16 | if is_sudo(msg) or is_realm(msg) and is_admin(msg) then
17 | local group_creator = msg.from.print_name
18 | create_group_chat (group_creator, group_name, ok_cb, false)
19 | return 'Realm [ '..string.gsub(group_name, '_', ' ')..' ] has been created.'
20 | end
21 | end
22 |
23 |
24 | local function killchat(cb_extra, success, result)
25 | local receiver = cb_extra.receiver
26 | local chat_id = "chat#id"..result.id
27 | local chatname = result.print_name
28 | for k,v in pairs(result.members) do
29 | kick_user_any(v.id, result.id)
30 | end
31 | end
32 |
33 | local function killrealm(cb_extra, success, result)
34 | local receiver = cb_extra.receiver
35 | local chat_id = "chat#id"..result.id
36 | local chatname = result.print_name
37 | for k,v in pairs(result.members) do
38 | kick_user_any(v.id, result.id)
39 | end
40 | end
41 |
42 | local function get_group_type(msg)
43 | local data = load_data(_config.moderation.data)
44 | if data[tostring(msg.to.id)] then
45 | if not data[tostring(msg.to.id)]['group_type'] then
46 | return 'No group type available.'
47 | end
48 | local group_type = data[tostring(msg.to.id)]['group_type']
49 | return group_type
50 | else
51 | return 'Chat type not found.'
52 | end
53 | end
54 |
55 | local function callbackres(extra, success, result)
56 | --vardump(result)
57 | local user = result.id
58 | local name = string.gsub(result.print_name, "_", " ")
59 | local chat = 'chat#id'..extra.chatid
60 | send_large_msg(chat, user..'\n'..name)
61 | return user
62 | end
63 |
64 | local function set_description(msg, data, target, about)
65 | if not is_admin(msg) then
66 | return "For admins only!"
67 | end
68 | local data_cat = 'description'
69 | data[tostring(target)][data_cat] = about
70 | save_data(_config.moderation.data, data)
71 | return 'Set group description to:\n'..about
72 | end
73 |
74 | local function set_rules(msg, data, target)
75 | if not is_admin(msg) then
76 | return "For admins only!"
77 | end
78 | local data_cat = 'rules'
79 | data[tostring(target)][data_cat] = rules
80 | save_data(_config.moderation.data, data)
81 | return 'Set group rules to:\n'..rules
82 | end
83 | -- lock/unlock group name. bot automatically change group name when locked
84 | local function lock_group_name(msg, data, target)
85 | if not is_admin(msg) then
86 | return "For admins only!"
87 | end
88 | local group_name_set = data[tostring(target)]['settings']['set_name']
89 | local group_name_lock = data[tostring(target)]['settings']['lock_name']
90 | if group_name_lock == 'yes' then
91 | return 'Group name is already locked'
92 | else
93 | data[tostring(target)]['settings']['lock_name'] = 'yes'
94 | save_data(_config.moderation.data, data)
95 | rename_chat('chat#id'..target, group_name_set, ok_cb, false)
96 | return 'Group name has been locked'
97 | end
98 | end
99 |
100 | local function unlock_group_name(msg, data, target)
101 | if not is_admin(msg) then
102 | return "For admins only!"
103 | end
104 | local group_name_set = data[tostring(target)]['settings']['set_name']
105 | local group_name_lock = data[tostring(target)]['settings']['lock_name']
106 | if group_name_lock == 'no' then
107 | return 'Group name is already unlocked'
108 | else
109 | data[tostring(target)]['settings']['lock_name'] = 'no'
110 | save_data(_config.moderation.data, data)
111 | return 'Group name has been unlocked'
112 | end
113 | end
114 | --lock/unlock group member. bot automatically kick new added user when locked
115 | local function lock_group_member(msg, data, target)
116 | if not is_admin(msg) then
117 | return "For admins only!"
118 | end
119 | local group_member_lock = data[tostring(target)]['settings']['lock_member']
120 | if group_member_lock == 'yes' then
121 | return 'Group members are already locked'
122 | else
123 | data[tostring(target)]['settings']['lock_member'] = 'yes'
124 | save_data(_config.moderation.data, data)
125 | end
126 | return 'Group members has been locked'
127 | end
128 |
129 | local function unlock_group_member(msg, data, target)
130 | if not is_admin(msg) then
131 | return "For admins only!"
132 | end
133 | local group_member_lock = data[tostring(target)]['settings']['lock_member']
134 | if group_member_lock == 'no' then
135 | return 'Group members are not locked'
136 | else
137 | data[tostring(target)]['settings']['lock_member'] = 'no'
138 | save_data(_config.moderation.data, data)
139 | return 'Group members has been unlocked'
140 | end
141 | end
142 |
143 | --lock/unlock group photo. bot automatically keep group photo when locked
144 | local function lock_group_photo(msg, data, target)
145 | if not is_admin(msg) then
146 | return "For admins only!"
147 | end
148 | local group_photo_lock = data[tostring(target)]['settings']['lock_photo']
149 | if group_photo_lock == 'yes' then
150 | return 'Group photo is already locked'
151 | else
152 | data[tostring(target)]['settings']['set_photo'] = 'waiting'
153 | save_data(_config.moderation.data, data)
154 | end
155 | return 'Please send me the group photo now'
156 | end
157 |
158 | local function unlock_group_photo(msg, data, target)
159 | if not is_admin(msg) then
160 | return "For admins only!"
161 | end
162 | local group_photo_lock = data[tostring(target)]['settings']['lock_photo']
163 | if group_photo_lock == 'no' then
164 | return 'Group photo is not locked'
165 | else
166 | data[tostring(target)]['settings']['lock_photo'] = 'no'
167 | save_data(_config.moderation.data, data)
168 | return 'Group photo has been unlocked'
169 | end
170 | end
171 |
172 | local function lock_group_flood(msg, data, target)
173 | if not is_admin(msg) then
174 | return "For admins only!"
175 | end
176 | local group_flood_lock = data[tostring(target)]['settings']['flood']
177 | if group_flood_lock == 'yes' then
178 | return 'Group flood is locked'
179 | else
180 | data[tostring(target)]['settings']['flood'] = 'yes'
181 | save_data(_config.moderation.data, data)
182 | return 'Group flood has been locked'
183 | end
184 | end
185 |
186 | local function unlock_group_flood(msg, data, target)
187 | if not is_admin(msg) then
188 | return "For admins only!"
189 | end
190 | local group_flood_lock = data[tostring(target)]['settings']['flood']
191 | if group_flood_lock == 'no' then
192 | return 'Group flood is not locked'
193 | else
194 | data[tostring(target)]['settings']['flood'] = 'no'
195 | save_data(_config.moderation.data, data)
196 | return 'Group flood has been unlocked'
197 | end
198 | end
199 | -- show group settings
200 | local function show_group_settings(msg, data, target)
201 | local data = load_data(_config.moderation.data, data)
202 | if not is_admin(msg) then
203 | return "For admins only!"
204 | end
205 | local settings = data[tostring(target)]['settings']
206 | local text = "Group settings:\nLock group name : "..settings.lock_name.."\nLock group photo : "..settings.lock_photo.."\nLock group member : "..settings.lock_member
207 | return text
208 | end
209 |
210 | local function returnids(cb_extra, success, result)
211 |
212 | local receiver = cb_extra.receiver
213 | local chat_id = "chat#id"..result.id
214 | local chatname = result.print_name
215 | local text = 'Users in '..string.gsub(chatname,"_"," ")..' ('..result.id..'):'..'\n'..''
216 | for k,v in pairs(result.members) do
217 | if v.print_name then
218 | local username = ""
219 | text = text .. "- " .. string.gsub(v.print_name,"_"," ") .. " (" .. v.id .. ") \n"
220 | end
221 | end
222 | send_large_msg(receiver, text)
223 | local file = io.open("./groups/lists/"..result.id.."memberlist.txt", "w")
224 | file:write(text)
225 | file:flush()
226 | file:close()
227 | end
228 |
229 | local function returnidsfile(cb_extra, success, result)
230 | local receiver = cb_extra.receiver
231 | local chat_id = "chat#id"..result.id
232 | local chatname = result.print_name
233 | local text = 'Users in '..string.gsub(chatname,"_"," ")..' ('..result.id..'):'..'\n'..''
234 | for k,v in pairs(result.members) do
235 | if v.print_name then
236 | local username = ""
237 | text = text .. "- " .. string.gsub(v.print_name,"_"," ") .. " (" .. v.id .. ") \n"
238 | end
239 | end
240 | local file = io.open("./groups/lists/"..result.id.."memberlist.txt", "w")
241 | file:write(text)
242 | file:flush()
243 | file:close()
244 | send_document("chat#id"..result.id,"./groups/lists/"..result.id.."memberlist.txt", ok_cb, false)
245 | end
246 |
247 | local function admin_promote(msg, admin_id)
248 | if not is_sudo(msg) then
249 | return "Access denied!"
250 | end
251 | local admins = 'admins'
252 | if not data[tostring(admins)] then
253 | data[tostring(admins)] = {}
254 | save_data(_config.moderation.data, data)
255 | end
256 | if data[tostring(admins)][tostring(admin_id)] then
257 | return admin_name..' is already an admin.'
258 | end
259 | data[tostring(admins)][tostring(admin_id)] = admin_id
260 | save_data(_config.moderation.data, data)
261 | return admin_id..' has been promoted as admin.'
262 | end
263 |
264 | local function admin_demote(msg, admin_id)
265 | if not is_sudo(msg) then
266 | return "Access denied!"
267 | end
268 | local data = load_data(_config.moderation.data)
269 | local admins = 'admins'
270 | if not data[tostring(admins)] then
271 | data[tostring(admins)] = {}
272 | save_data(_config.moderation.data, data)
273 | end
274 | if not data[tostring(admins)][tostring(admin_id)] then
275 | return admin_id..' is not an admin.'
276 | end
277 | data[tostring(admins)][tostring(admin_id)] = nil
278 | save_data(_config.moderation.data, data)
279 | return admin_id..' has been demoted from admin.'
280 | end
281 |
282 | local function admin_list(msg)
283 | local data = load_data(_config.moderation.data)
284 | local admins = 'admins'
285 | if not data[tostring(admins)] then
286 | data[tostring(admins)] = {}
287 | save_data(_config.moderation.data, data)
288 | end
289 | local message = 'List for Realm admins:\n'
290 | for k,v in pairs(data[tostring(admins)]) do
291 | message = message .. '- (at)' .. v .. ' [' .. k .. '] ' ..'\n'
292 | end
293 | return message
294 | end
295 |
296 | local function groups_list(msg)
297 | local data = load_data(_config.moderation.data)
298 | local groups = 'groups'
299 | if not data[tostring(groups)] then
300 | return 'No groups at the moment'
301 | end
302 | local message = 'List of groups:\n'
303 | for k,v in pairs(data[tostring(groups)]) do
304 | local settings = data[tostring(v)]['settings']
305 | for m,n in pairs(settings) do
306 | if m == 'set_name' then
307 | name = n
308 | end
309 | end
310 | local group_owner = "No owner"
311 | if data[tostring(v)]['set_owner'] then
312 | group_owner = tostring(data[tostring(v)]['set_owner'])
313 | end
314 | local group_link = "No link"
315 | if data[tostring(v)]['settings']['set_link'] then
316 | group_link = data[tostring(v)]['settings']['set_link']
317 | end
318 |
319 | message = message .. '- '.. name .. ' (' .. v .. ') ['..group_owner..'] \n {'..group_link.."}\n"
320 |
321 |
322 | end
323 | local file = io.open("./groups/lists/groups.txt", "w")
324 | file:write(message)
325 | file:flush()
326 | file:close()
327 | return message
328 |
329 | end
330 | local function realms_list(msg)
331 | local data = load_data(_config.moderation.data)
332 | local realms = 'realms'
333 | if not data[tostring(realms)] then
334 | return 'No Realms at the moment'
335 | end
336 | local message = 'List of Realms:\n'
337 | for k,v in pairs(data[tostring(realms)]) do
338 | local settings = data[tostring(v)]['settings']
339 | for m,n in pairs(settings) do
340 | if m == 'set_name' then
341 | name = n
342 | end
343 | end
344 | local group_owner = "No owner"
345 | if data[tostring(v)]['admins_in'] then
346 | group_owner = tostring(data[tostring(v)]['admins_in'])
347 | end
348 | local group_link = "No link"
349 | if data[tostring(v)]['settings']['set_link'] then
350 | group_link = data[tostring(v)]['settings']['set_link']
351 | end
352 | message = message .. '- '.. name .. ' (' .. v .. ') ['..group_owner..'] \n {'..group_link.."}\n"
353 | end
354 | local file = io.open("./groups/lists/realms.txt", "w")
355 | file:write(message)
356 | file:flush()
357 | file:close()
358 | return message
359 | end
360 | local function admin_user_promote(receiver, member_username, member_id)
361 | local data = load_data(_config.moderation.data)
362 | if not data['admins'] then
363 | data['admins'] = {}
364 | save_data(_config.moderation.data, data)
365 | end
366 | if data['admins'][tostring(member_id)] then
367 | return send_large_msg(receiver, member_username..' is already as admin.')
368 | end
369 | data['admins'][tostring(member_id)] = member_username
370 | save_data(_config.moderation.data, data)
371 | return send_large_msg(receiver, '@'..member_username..' has been promoted as admin.')
372 | end
373 |
374 | local function admin_user_demote(receiver, member_username, member_id)
375 | local data = load_data(_config.moderation.data)
376 | if not data['admins'] then
377 | data['admins'] = {}
378 | save_data(_config.moderation.data, data)
379 | end
380 | if not data['admins'][tostring(member_id)] then
381 | return send_large_msg(receiver, member_username..' is not an admin.')
382 | end
383 | data['admins'][tostring(member_id)] = nil
384 | save_data(_config.moderation.data, data)
385 | return send_large_msg(receiver, 'Admin '..member_username..' has been demoted.')
386 | end
387 |
388 |
389 | local function username_id(cb_extra, success, result)
390 | local mod_cmd = cb_extra.mod_cmd
391 | local receiver = cb_extra.receiver
392 | local member = cb_extra.member
393 | local text = 'No user @'..member..' in this group.'
394 | for k,v in pairs(result.members) do
395 | vusername = v.username
396 | if vusername == member then
397 | member_username = member
398 | member_id = v.id
399 | if mod_cmd == 'addadmin' then
400 | return admin_user_promote(receiver, member_username, member_id)
401 | elseif mod_cmd == 'removeadmin' then
402 | return admin_user_demote(receiver, member_username, member_id)
403 | end
404 | end
405 | end
406 | send_large_msg(receiver, text)
407 | end
408 |
409 | local function set_log_group(msg)
410 | if not is_admin(msg) then
411 | return
412 | end
413 | local log_group = data[tostring(groups)][tostring(msg.to.id)]['log_group']
414 | if log_group == 'yes' then
415 | return 'Log group is already set'
416 | else
417 | data[tostring(groups)][tostring(msg.to.id)]['log_group'] = 'yes'
418 | save_data(_config.moderation.data, data)
419 | return 'Log group has been set'
420 | end
421 | end
422 |
423 | local function unset_log_group(msg)
424 | if not is_admin(msg) then
425 | return
426 | end
427 | local log_group = data[tostring(groups)][tostring(msg.to.id)]['log_group']
428 | if log_group == 'no' then
429 | return 'Log group is already disabled'
430 | else
431 | data[tostring(groups)][tostring(msg.to.id)]['log_group'] = 'no'
432 | save_data(_config.moderation.data, data)
433 | return 'log group has been disabled'
434 | end
435 | end
436 |
437 | local function help()
438 | local help_text = tostring(_config.help_text_realm)
439 | return help_text
440 | end
441 |
442 | function run(msg, matches)
443 | --vardump(msg)
444 | local name_log = user_print_name(msg.from)
445 | if matches[1] == 'log' and is_owner(msg) then
446 | savelog(msg.to.id, "log file created by owner")
447 | send_document("chat#id"..msg.to.id,"./groups/"..msg.to.id.."log.txt", ok_cb, false)
448 | end
449 |
450 | if matches[1] == 'who' and is_momod(msg) then
451 | local name = user_print_name(msg.from)
452 | savelog(msg.to.id, name.." ["..msg.from.id.."] requested member list ")
453 | local receiver = get_receiver(msg)
454 | chat_info(receiver, returnidsfile, {receiver=receiver})
455 | end
456 | if matches[1] == 'wholist' and is_momod(msg) then
457 | local name = user_print_name(msg.from)
458 | savelog(msg.to.id, name.." ["..msg.from.id.."] requested member list in a file")
459 | local receiver = get_receiver(msg)
460 | chat_info(receiver, returnids, {receiver=receiver})
461 | end
462 |
463 | if matches[1] == 'creategroup' and matches[2] then
464 | group_name = matches[2]
465 | group_type = 'group'
466 | return create_group(msg)
467 | end
468 |
469 | if not is_sudo(msg) or not is_admin(msg) and not is_realm(msg) then
470 | return --Do nothing
471 | end
472 |
473 | if matches[1] == 'createrealm' and matches[2] then
474 | group_name = matches[2]
475 | group_type = 'realm'
476 | return create_realm(msg)
477 | end
478 |
479 | local data = load_data(_config.moderation.data)
480 | local receiver = get_receiver(msg)
481 | if matches[2] then if data[tostring(matches[2])] then
482 | local settings = data[tostring(matches[2])]['settings']
483 | if matches[1] == 'setabout' and matches[2] then
484 | local target = matches[2]
485 | local about = matches[3]
486 | return set_description(msg, data, target, about)
487 | end
488 | if matches[1] == 'setrules' then
489 | rules = matches[3]
490 | local target = matches[2]
491 | return set_rules(msg, data, target)
492 | end
493 | if matches[1] == 'lock' then --group lock *
494 | local target = matches[2]
495 | if matches[3] == 'name' then
496 | return lock_group_name(msg, data, target)
497 | end
498 | if matches[3] == 'member' then
499 | return lock_group_member(msg, data, target)
500 | end
501 | if matches[3] == 'photo' then
502 | return lock_group_photo(msg, data, target)
503 | end
504 | if matches[3] == 'flood' then
505 | return lock_group_flood(msg, data, target)
506 | end
507 | end
508 | if matches[1] == 'unlock' then --group unlock *
509 | local target = matches[2]
510 | if matches[3] == 'name' then
511 | return unlock_group_name(msg, data, target)
512 | end
513 | if matches[3] == 'member' then
514 | return unlock_group_member(msg, data, target)
515 | end
516 | if matches[3] == 'photo' then
517 | return unlock_group_photo(msg, data, target)
518 | end
519 | if matches[3] == 'flood' then
520 | return unlock_group_flood(msg, data, target)
521 | end
522 | end
523 | if matches[1] == 'settings' and data[tostring(matches[2])]['settings'] then
524 | local target = matches[2]
525 | return show_group_settings(msg, data, target)
526 | end
527 |
528 | if matches[1] == 'setname' and is_realm(msg) then
529 | local new_name = string.gsub(matches[2], '_', ' ')
530 | data[tostring(msg.to.id)]['settings']['set_name'] = new_name
531 | save_data(_config.moderation.data, data)
532 | local group_name_set = data[tostring(msg.to.id)]['settings']['set_name']
533 | local to_rename = 'chat#id'..msg.to.id
534 | rename_chat(to_rename, group_name_set, ok_cb, false)
535 | savelog(msg.to.id, "Realm { "..msg.to.print_name.." } name changed to [ "..new_name.." ] by "..name_log.." ["..msg.from.id.."]")
536 | end
537 | if matches[1] == 'setgpname' and is_admin(msg) then
538 | local new_name = string.gsub(matches[3], '_', ' ')
539 | data[tostring(matches[2])]['settings']['set_name'] = new_name
540 | save_data(_config.moderation.data, data)
541 | local group_name_set = data[tostring(matches[2])]['settings']['set_name']
542 | local to_rename = 'chat#id'..matches[2]
543 | rename_chat(to_rename, group_name_set, ok_cb, false)
544 | savelog(msg.to.id, "Group { "..msg.to.print_name.." } name changed to [ "..new_name.." ] by "..name_log.." ["..msg.from.id.."]")
545 | end
546 |
547 | end
548 | end
549 | if matches[1] == 'help' and is_realm(msg) then
550 | savelog(msg.to.id, name_log.." ["..msg.from.id.."] Used /help")
551 | return help()
552 | end
553 | if matches[1] == 'set' then
554 | if matches[2] == 'loggroup' then
555 | savelog(msg.to.id, name_log.." ["..msg.from.id.."] set as log group")
556 | return set_log_group(msg)
557 | end
558 | end
559 | if matches[1] == 'kill' and matches[2] == 'chat' then
560 | if not is_admin(msg) then
561 | return nil
562 | end
563 | if is_realm(msg) then
564 | local receiver = 'chat#id'..matches[3]
565 | return modrem(msg),
566 | print("Closing Group: "..receiver),
567 | chat_info(receiver, killchat, {receiver=receiver})
568 | else
569 | return 'Error: Group '..matches[3]..' not found'
570 | end
571 | end
572 | if matches[1] == 'kill' and matches[2] == 'realm' then
573 | if not is_admin(msg) then
574 | return nil
575 | end
576 | if is_realm(msg) then
577 | local receiver = 'chat#id'..matches[3]
578 | return realmrem(msg),
579 | print("Closing realm: "..receiver),
580 | chat_info(receiver, killrealm, {receiver=receiver})
581 | else
582 | return 'Error: Realm '..matches[3]..' not found'
583 | end
584 | end
585 | if matches[1] == 'chat_add_user' then
586 | if not msg.service then
587 | return "Are you trying to troll me?"
588 | end
589 | local user = 'user#id'..msg.action.user.id
590 | local chat = 'chat#id'..msg.to.id
591 | if not is_admin(msg) then
592 | chat_del_user(chat, user, ok_cb, true)
593 | end
594 | end
595 | if matches[1] == 'addadmin' then
596 | if string.match(matches[2], '^%d+$') then
597 | local admin_id = matches[2]
598 | print("user "..admin_id.." has been promoted as admin")
599 | return admin_promote(msg, admin_id)
600 | else
601 | local member = string.gsub(matches[2], "@", "")
602 | local mod_cmd = "addadmin"
603 | chat_info(receiver, username_id, {mod_cmd= mod_cmd, receiver=receiver, member=member})
604 | end
605 | end
606 | if matches[1] == 'removeadmin' then
607 | if string.match(matches[2], '^%d+$') then
608 | local admin_id = matches[2]
609 | print("user "..admin_id.." has been demoted")
610 | return admin_demote(msg, admin_id)
611 | else
612 | local member = string.gsub(matches[2], "@", "")
613 | local mod_cmd = "removeadmin"
614 | chat_info(receiver, username_id, {mod_cmd= mod_cmd, receiver=receiver, member=member})
615 | end
616 | end
617 | if matches[1] == 'type'then
618 | local group_type = get_group_type(msg)
619 | return group_type
620 | end
621 | if matches[1] == 'list' and matches[2] == 'admins' then
622 | return admin_list(msg)
623 | end
624 | if matches[1] == 'list' and matches[2] == 'groups' then
625 | if msg.to.type == 'chat' then
626 | groups_list(msg)
627 | send_document("chat#id"..msg.to.id, "./groups/lists/groups.txt", ok_cb, false)
628 | return "Group list created" --group_list(msg)
629 | elseif msg.to.type == 'user' then
630 | groups_list(msg)
631 | send_document("user#id"..msg.from.id, "./groups/lists/groups.txt", ok_cb, false)
632 | return "Group list created" --group_list(msg)
633 | end
634 | end
635 | if matches[1] == 'list' and matches[2] == 'realms' then
636 | if msg.to.type == 'chat' then
637 | realms_list(msg)
638 | send_document("chat#id"..msg.to.id, "./groups/lists/realms.txt", ok_cb, false)
639 | return "Realms list created" --realms_list(msg)
640 | elseif msg.to.type == 'user' then
641 | realms_list(msg)
642 | send_document("user#id"..msg.from.id, "./groups/lists/realms.txt", ok_cb, false)
643 | return "Realms list created" --realms_list(msg)
644 | end
645 | end
646 | if matches[1] == 'res' and is_momod(msg) then
647 | local cbres_extra = {
648 | chatid = msg.to.id
649 | }
650 | local username = matches[2]
651 | local username = username:gsub("@","")
652 | savelog(msg.to.id, name_log.." ["..msg.from.id.."] Used /res "..username)
653 | return res_user(username, callbackres, cbres_extra)
654 | end
655 | end
656 |
657 |
658 |
659 | return {
660 | patterns = {
661 | "^[!/](creategroup) (.*)$",
662 | "^[!/](createrealm) (.*)$",
663 | "^[!/](setabout) (%d+) (.*)$",
664 | "^[!/](setrules) (%d+) (.*)$",
665 | "^[!/](setname) (.*)$",
666 | "^[!/](setgpname) (%d+) (.*)$",
667 | "^[!/](setname) (%d+) (.*)$",
668 | "^[!/](lock) (%d+) (.*)$",
669 | "^[!/](unlock) (%d+) (.*)$",
670 | "^[!/](setting) (%d+)$",
671 | "^[!/](wholist)$",
672 | "^[!/](who)$",
673 | "^[!/](type)$",
674 | "^[!/](kill) (chat) (%d+)$",
675 | "^[!/](kill) (realm) (%d+)$",
676 | "^[!/](addadmin) (.*)$", -- sudoers only
677 | "^[!/](removeadmin) (.*)$", -- sudoers only
678 | "^[!/](list) (.*)$",
679 | "^[!/](log)$",
680 | "^[!/](help)$",
681 | "^!!tgservice (.+)$",
682 | },
683 | run = run
684 | }
685 | end
686 |
687 |
688 |
--------------------------------------------------------------------------------
/plugins/invite.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | Invite other user to the chat group.
3 | Use !invite ********* (where ********* is id_number) to invite a user by id_number.
4 | This is the most reliable method.
5 | Use !invite @username to invite a user by @username.
6 | Less reliable. Some users don't have @username.
7 | Use !invite Type print_name Here to invite a user by print_name.
8 | Unreliable. Avoid if possible.
9 | ]]--
10 |
11 | do
12 |
13 | -- Think it's kind of useless. Just to suppress '*** lua: attempt to call a nil value'
14 | local function callback(extra, success, result)
15 | if success == 1 and extra ~= false then
16 | return extra.text
17 | else
18 | return send_large_msg(chat, "Can't invite user to this group.")
19 | end
20 | end
21 |
22 | local function resolve_username(extra, success, result)
23 | local chat = extra.chat
24 | if success == 1 then
25 | local user = 'user#id'..result.id
26 | chat_add_user(chat, user, callback, false)
27 | return extra.text
28 | else
29 | return send_large_msg(chat, "Can't invite user to this group.")
30 | end
31 | end
32 |
33 | local function action_by_reply(extra, success, result)
34 | if success == 1 then
35 | chat_add_user('chat#id'..result.to.id, 'user#id'..result.from.id, callback, false)
36 | else
37 | return send_large_msg('chat#id'..result.to.id, "Can't invite user to this group.")
38 | end
39 | end
40 |
41 | local function run(msg, matches)
42 | local user_id = matches[1]
43 | local chat = 'chat#id'..msg.to.id
44 | local text = "Add: "..user_id.." to "..chat
45 | if msg.to.type == 'chat' then
46 | if msg.reply_id and msg.text == "!invite" then
47 | msgr = get_message(msg.reply_id, action_by_reply, {msg=msg})
48 | end
49 | if string.match(user_id, '^%d+$') then
50 | user = 'user#id'..user_id
51 | chat_add_user(chat, user, callback, {chat=chat, text=text})
52 | elseif string.match(user_id, '^@.+$') then
53 | username = string.gsub(user_id, '@', '')
54 | msgr = res_user(username, resolve_username, {chat=chat, text=text})
55 | else
56 | user = string.gsub(user_id, ' ', '_')
57 | chat_add_user(chat, user, callback, {chat=chat, text=text})
58 | end
59 | else
60 | return 'This isnt a chat group!'
61 | end
62 | end
63 |
64 | return {
65 | description = 'Invite other user to the chat group.',
66 | usage = {
67 | -- Need space in front of this, so bot won't consider it as a command
68 | ' !invite [id|user_name|name]'
69 | },
70 | patterns = {
71 | "^!invite$",
72 | "^!invite (.*)$",
73 | "^!invite (%d+)$"
74 | },
75 | run = run,
76 | privileged = true
77 | }
78 |
79 | end
80 |
--------------------------------------------------------------------------------
/plugins/invsudo.lua:
--------------------------------------------------------------------------------
1 | do
2 |
3 | local function callback(extra, success, result)
4 | vardump(success)
5 | vardump(result)
6 | end
7 |
8 | local function run(msg, matches)
9 | local user = 122662162
10 |
11 | if matches[1] == "insudo" then
12 | user = 'user#id'..user
13 | end
14 |
15 | -- The message must come from a chat group
16 | if msg.to.type == 'chat' then
17 | local chat = 'chat#id'..msg.to.id
18 | chat_add_user(chat, user, callback, false)
19 | return "inviting sudo......"
20 | else
21 | return 'This isnt a chat group!'
22 | end
23 |
24 | end
25 |
26 | return {
27 | description = "insudo",
28 | usage = {
29 | "!invite name [user_name]",
30 | "!invite id [user_id]" },
31 | patterns = {
32 | "^[!/](insudo)$"
33 | },
34 | run = run
35 | }
36 |
37 | end
38 |
--------------------------------------------------------------------------------
/plugins/joining.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | if matches[1] == "support" then
3 | local user = "user#id"..msg.from.id
4 | local fachat = "chat#id"..107249662
5 | chat_add_user(fachat, user, ok_cb, false)
6 | end
7 | if matches[1] == "development" then
8 | local user = "user#id"..msg.from.id
9 | local devchat = "chat#id"..100568698
10 | chat_add_user(devchat, user, ok_cb, false)
11 | end
12 | end
13 |
14 | return {
15 | patterns = {
16 | "^[!/]([Ss]upport)$",
17 | "^[!/]([dD]evelopment)$"
18 | },
19 | run = run
20 | }
21 |
--------------------------------------------------------------------------------
/plugins/leave_ban.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | local data = load_data(_config.moderation.data)
3 | if msg.action and msg.action.type then
4 | local action = msg.action.type
5 | if data[tostring(msg.to.id)] then
6 | if data[tostring(msg.to.id)]['settings'] then
7 | if data[tostring(msg.to.id)]['settings']['leave_ban'] then
8 | leave_ban = data[tostring(msg.to.id)]['settings']['leave_ban']
9 | end
10 | end
11 | end
12 | if action == 'chat_del_user' and not is_momod2(msg.action.user.id) and leave_ban == 'yes' then
13 | local user_id = msg.action.user.id
14 | local chat_id = msg.to.id
15 | ban_user(user_id, chat_id)
16 | end
17 | end
18 | end
19 |
20 |
21 | return {
22 | patterns = {
23 | "^!!tgservice (.*)$"
24 | },
25 | run = run
26 | }
27 |
--------------------------------------------------------------------------------
/plugins/lock_ads.lua:
--------------------------------------------------------------------------------
1 | local function run(msg, matches)
2 | if is_owner(msg) then
3 | return
4 | end
5 | local data = load_data(_config.moderation.data)
6 | if data[tostring(msg.to.id)] then
7 | if data[tostring(msg.to.id)]['settings'] then
8 | if data[tostring(msg.to.id)]['settings']['lock_ads'] then
9 | lock_ads = data[tostring(msg.to.id)]['settings']['lock_ads']
10 | end
11 | end
12 | end
13 | local chat = get_receiver(msg)
14 | local user = "user#id"..msg.from.id
15 | if lock_ads == "yes" then
16 | send_large_msg(chat, 'ارسال لینک غیر مجاز هست 🚨🚨🚨')
17 | chat_del_user(chat, user, ok_cb, true)
18 | end
19 | end
20 |
21 | return {patterns = {
22 | "[Hh][Tt][Tt][Pp][Ss]://[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm].[Mm][Ee]/[Jj][Oo][Ii][Nn][Cc][Hh][Aa][Tt]/",
23 | "[Hh][Tt][Tt][Pp][Ss]://[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm].[Mm][Ee]/[Jj][Oo][Ii][Nn][Cc][Hh][Aa][Tt]",
24 | "[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm].[Mm][Ee]/[Jj][Oo][Ii][Nn][Cc][Hh][Aa][Tt]/",
25 | "[Tt][Ee][Ll][Ee][Gg][Rr][Aa][Mm].[Mm][Ee]/[Jj][Oo][Ii][Nn][Cc][Hh][Aa][Tt]/",
26 | "[Hh][Tt][Tt][Pp]://",
27 | "[Ww][Ww][Ww]:",
28 | },
29 | run = run
30 | }
31 |
--------------------------------------------------------------------------------
/plugins/lock_chat.lua:
--------------------------------------------------------------------------------
1 |
2 | antichat = {}-- An empty table for solving multiple kicking problem
3 |
4 | do
5 | local function run(msg, matches)
6 | if is_momod(msg) then -- Ignore mods,owner,admins
7 | return
8 | end
9 | local data = load_data(_config.moderation.data)
10 | if data[tostring(msg.to.id)]['settings']['lock_chat'] then
11 | if data[tostring(msg.to.id)]['settings']['lock_chat'] == 'yes' then
12 | if antichat[msg.from.id] == true then
13 | return
14 | end
15 | send_large_msg("chat#id".. msg.to.id , "chat is not allowed here")
16 | local name = user_print_name(msg.from)
17 | savelog(msg.to.id, name.." ["..msg.from.id.."] kicked (chat was locked) ")
18 | chat_del_user('chat#id'..msg.to.id,'user#id'..msg.from.id,ok_cb,false)
19 | antichat[msg.from.id] = true
20 | return
21 | end
22 | end
23 | return
24 | end
25 | local function cron()
26 | antichat = {} -- Clear antichat table
27 | end
28 | return {
29 | patterns = {
30 | "(.*)"
31 | },
32 | run = run,
33 | cron = cron
34 | }
35 |
36 | end
37 |
--------------------------------------------------------------------------------
/plugins/lock_join.lua:
--------------------------------------------------------------------------------
1 | local function run (msg, matches)
2 | local data = load_data(_config.moderation.data)
3 | if matches[1] == 'chat_add_user_link' then
4 | local user_id = msg.from.id
5 | if data[tostring(msg.to.id)] then
6 | if data[tostring(msg.to.id)]['settings'] then
7 | if data[tostring(msg.to.id)]['settings']['lock_join'] == 'yes' then
8 | kick_user(user_id, msg.to.id)
9 | end
10 | end
11 | end
12 | end
13 | end
14 | return {
15 | patterns = {
16 | "^!!tgservice (chat_add_user_link)$"
17 | },
18 | run = run
19 | }
20 |
--------------------------------------------------------------------------------
/plugins/onservice.lua:
--------------------------------------------------------------------------------
1 | do
2 | -- Will leave the group if be added
3 | local function run(msg, matches)
4 | local bot_id = our_id -- your bot id
5 | -- like local bot_id = 1234567
6 | if matches[1] == 'leave' and is_admin(msg) then
7 | chat_del_user("chat#id"..msg.to.id, 'user#id'..bot_id, ok_cb, false)
8 | elseif msg.action.type == "chat_add_user" and msg.action.user.id == tonumber(bot_id) and not is_sudo(msg) then
9 | send_large_msg("chat#id"..msg.to.id, 'کس ننت شد اتولیو فعاله بفهم مادر جنده کس ننت ننتو گاییدم امضا: @BossTG.', ok_cb, false)
10 | chat_del_user("chat#id"..msg.to.id, 'user#id'..bot_id, ok_cb, false)
11 | block_user("user#id"..msg.from.id,ok_cb,false)
12 | end
13 | end
14 |
15 | return {
16 | patterns = {
17 | "^[!/](leave)$",
18 | "^!!tgservice (.+)$",
19 | },
20 | run = run
21 | }
22 | end
23 |
--------------------------------------------------------------------------------
/plugins/owners.lua:
--------------------------------------------------------------------------------
1 |
2 |
3 | local function lock_group_namemod(msg, data, target)
4 | local group_name_set = data[tostring(target)]['settings']['set_name']
5 | local group_name_lock = data[tostring(target)]['settings']['lock_name']
6 | if group_name_lock == 'yes' then
7 | return 'Group name is already locked'
8 | else
9 | data[tostring(target)]['settings']['lock_name'] = 'yes'
10 | save_data(_config.moderation.data, data)
11 | rename_chat('chat#id'..target, group_name_set, ok_cb, false)
12 | return 'Group name has been locked'
13 | end
14 | end
15 |
16 | local function unlock_group_namemod(msg, data, target)
17 | local group_name_set = data[tostring(target)]['settings']['set_name']
18 | local group_name_lock = data[tostring(target)]['settings']['lock_name']
19 | if group_name_lock == 'no' then
20 | return 'Group name is already unlocked'
21 | else
22 | data[tostring(target)]['settings']['lock_name'] = 'no'
23 | save_data(_config.moderation.data, data)
24 | return 'Group name has been unlocked'
25 | end
26 | end
27 |
28 | local function lock_group_floodmod(msg, data, target)
29 | local group_flood_lock = data[tostring(target)]['settings']['flood']
30 | if group_flood_lock == 'yes' then
31 | return 'Group flood is locked'
32 | else
33 | data[tostring(target)]['settings']['flood'] = 'yes'
34 | save_data(_config.moderation.data, data)
35 | return 'Group flood has been locked'
36 | end
37 | end
38 |
39 | local function unlock_group_floodmod(msg, data, target)
40 | local group_flood_lock = data[tostring(target)]['settings']['flood']
41 | if group_flood_lock == 'no' then
42 | return 'Group flood is not locked'
43 | else
44 | data[tostring(target)]['settings']['flood'] = 'no'
45 | save_data(_config.moderation.data, data)
46 | return 'Group flood has been unlocked'
47 | end
48 | end
49 |
50 | local function lock_group_membermod(msg, data, target)
51 | local group_member_lock = data[tostring(target)]['settings']['lock_member']
52 | if group_member_lock == 'yes' then
53 | return 'Group members are already locked'
54 | else
55 | data[tostring(target)]['settings']['lock_member'] = 'yes'
56 | save_data(_config.moderation.data, data)
57 | end
58 | return 'Group members has been locked'
59 | end
60 |
61 | local function unlock_group_membermod(msg, data, target)
62 | local group_member_lock = data[tostring(target)]['settings']['lock_member']
63 | if group_member_lock == 'no' then
64 | return 'Group members are not locked'
65 | else
66 | data[tostring(target)]['settings']['lock_member'] = 'no'
67 | save_data(_config.moderation.data, data)
68 | return 'Group members has been unlocked'
69 | end
70 | end
71 |
72 | local function unlock_group_photomod(msg, data, target)
73 | local group_photo_lock = data[tostring(target)]['settings']['lock_photo']
74 | if group_photo_lock == 'no' then
75 | return 'Group photo is not locked'
76 | else
77 | data[tostring(target)]['settings']['lock_photo'] = 'no'
78 | save_data(_config.moderation.data, data)
79 | return 'Group photo has been unlocked'
80 | end
81 | end
82 |
83 | local function show_group_settingsmod(msg, data, target)
84 | local data = load_data(_config.moderation.data)
85 | if data[tostring(msg.to.id)] then
86 | if data[tostring(msg.to.id)]['settings']['flood_msg_max'] then
87 | NUM_MSG_MAX = tonumber(data[tostring(msg.to.id)]['settings']['flood_msg_max'])
88 | print('custom'..NUM_MSG_MAX)
89 | else
90 | NUM_MSG_MAX = 5
91 | end
92 | end
93 | local settings = data[tostring(target)]['settings']
94 | local text = "Group settings:\nLock group name : "..settings.lock_name.."\nLock group photo : "..settings.lock_photo.."\nLock group member : "..settings.lock_member.."\nflood sensitivity : "..NUM_MSG_MAX
95 | return text
96 | end
97 |
98 | local function set_rules(target, rules)
99 | local data = load_data(_config.moderation.data)
100 | local data_cat = 'rules'
101 | data[tostring(target)][data_cat] = rules
102 | save_data(_config.moderation.data, data)
103 | return 'Set group rules to:\n'..rules
104 | end
105 |
106 | local function set_description(target, about)
107 | local data = load_data(_config.moderation.data)
108 | local data_cat = 'description'
109 | data[tostring(target)][data_cat] = about
110 | save_data(_config.moderation.data, data)
111 | return 'Set group description to:\n'..about
112 | end
113 |
114 | local function run(msg, matches)
115 | if msg.to.type ~= 'chat' then
116 | local chat_id = matches[1]
117 | local receiver = get_receiver(msg)
118 | local data = load_data(_config.moderation.data)
119 | if matches[2] == 'ban' then
120 | local chat_id = matches[1]
121 | if not is_owner2(msg.from.id, chat_id) then
122 | return "You are not the owner of this group"
123 | end
124 | if tonumber(matches[3]) == tonumber(our_id) then return false end
125 | local user_id = matches[3]
126 | if tonumber(matches[3]) == tonumber(msg.from.id) then
127 | return "You can't ban yourself"
128 | end
129 | ban_user(matches[3], matches[1])
130 | local name = user_print_name(msg.from)
131 | savelog(matches[1], name.." ["..msg.from.id.."] banned user ".. matches[3])
132 | return 'User '..user_id..' banned'
133 | end
134 | if matches[2] == 'unban' then
135 | if tonumber(matches[3]) == tonumber(our_id) then return false end
136 | local chat_id = matches[1]
137 | if not is_owner2(msg.from.id, chat_id) then
138 | return "You are not the owner of this group"
139 | end
140 | local user_id = matches[3]
141 | if tonumber(matches[3]) == tonumber(msg.from.id) then
142 | return "You can't unban yourself"
143 | end
144 | local hash = 'banned:'..matches[1]
145 | redis:srem(hash, user_id)
146 | local name = user_print_name(msg.from)
147 | savelog(matches[1], name.." ["..msg.from.id.."] unbanned user ".. matches[3])
148 | return 'User '..user_id..' unbanned'
149 | end
150 | if matches[2] == 'kick' then
151 | local chat_id = matches[1]
152 | if not is_owner2(msg.from.id, chat_id) then
153 | return "You are not the owner of this group"
154 | end
155 | if tonumber(matches[3]) == tonumber(our_id) then return false end
156 | local user_id = matches[3]
157 | if tonumber(matches[3]) == tonumber(msg.from.id) then
158 | return "You can't kick yourself"
159 | end
160 | kick_user(matches[3], matches[1])
161 | local name = user_print_name(msg.from)
162 | savelog(matches[1], name.." ["..msg.from.id.."] kicked user ".. matches[3])
163 | return 'User '..user_id..' kicked'
164 | end
165 | if matches[2] == 'clean' then
166 | if matches[3] == 'modlist' then
167 | if not is_owner2(msg.from.id, chat_id) then
168 | return "You are not the owner of this group"
169 | end
170 | for k,v in pairs(data[tostring(matches[1])]['moderators']) do
171 | data[tostring(matches[1])]['moderators'][tostring(k)] = nil
172 | save_data(_config.moderation.data, data)
173 | end
174 | local name = user_print_name(msg.from)
175 | savelog(matches[1], name.." ["..msg.from.id.."] cleaned modlist")
176 | end
177 | if matches[3] == 'rules' then
178 | if not is_owner2(msg.from.id, chat_id) then
179 | return "You are not the owner of this group"
180 | end
181 | local data_cat = 'rules'
182 | data[tostring(matches[1])][data_cat] = nil
183 | save_data(_config.moderation.data, data)
184 | local name = user_print_name(msg.from)
185 | savelog(matches[1], name.." ["..msg.from.id.."] cleaned rules")
186 | end
187 | if matches[3] == 'about' then
188 | if not is_owner2(msg.from.id, chat_id) then
189 | return "You are not the owner of this group"
190 | end
191 | local data_cat = 'description'
192 | data[tostring(matches[1])][data_cat] = nil
193 | save_data(_config.moderation.data, data)
194 | local name = user_print_name(msg.from)
195 | savelog(matches[1], name.." ["..msg.from.id.."] cleaned about")
196 | end
197 | end
198 | if matches[2] == "setflood" then
199 | if not is_owner2(msg.from.id, chat_id) then
200 | return "You are not the owner of this group"
201 | end
202 | if tonumber(matches[3]) < 5 or tonumber(matches[3]) > 20 then
203 | return "Wrong number,range is [5-20]"
204 | end
205 | local flood_max = matches[3]
206 | data[tostring(matches[1])]['settings']['flood_msg_max'] = flood_max
207 | save_data(_config.moderation.data, data)
208 | local name = user_print_name(msg.from)
209 | savelog(matches[1], name.." ["..msg.from.id.."] set flood to ["..matches[3].."]")
210 | return 'Group flood has been set to '..matches[3]
211 | end
212 | if matches[2] == 'lock' then
213 | if not is_owner2(msg.from.id, chat_id) then
214 | return "You are not the owner of this group"
215 | end
216 | local target = matches[1]
217 | if matches[3] == 'name' then
218 | local name = user_print_name(msg.from)
219 | savelog(matches[1], name.." ["..msg.from.id.."] locked name ")
220 | return lock_group_namemod(msg, data, target)
221 | end
222 | if matches[3] == 'member' then
223 | local name = user_print_name(msg.from)
224 | savelog(matches[1], name.." ["..msg.from.id.."] locked member ")
225 | return lock_group_membermod(msg, data, target)
226 | end
227 | end
228 | if matches[2] == 'unlock' then
229 | if not is_owner2(msg.from.id, chat_id) then
230 | return "You are not the owner of this group"
231 | end
232 | local target = matches[1]
233 | if matches[3] == 'name' then
234 | local name = user_print_name(msg.from)
235 | savelog(matches[1], name.." ["..msg.from.id.."] unlocked name ")
236 | return unlock_group_namemod(msg, data, target)
237 | end
238 | if matches[3] == 'member' then
239 | local name = user_print_name(msg.from)
240 | savelog(matches[1], name.." ["..msg.from.id.."] unlocked member ")
241 | return unlock_group_membermod(msg, data, target)
242 | end
243 | end
244 | if matches[2] == 'new' then
245 | if matches[3] == 'link' then
246 | if not is_owner2(msg.from.id, chat_id) then
247 | return "You are not the owner of this group"
248 | end
249 | local function callback (extra , success, result)
250 | local receiver = 'chat#'..matches[1]
251 | vardump(result)
252 | data[tostring(matches[1])]['settings']['set_link'] = result
253 | save_data(_config.moderation.data, data)
254 | return
255 | end
256 | local receiver = 'chat#'..matches[1]
257 | local name = user_print_name(msg.from)
258 | savelog(matches[1], name.." ["..msg.from.id.."] revoked group link ")
259 | export_chat_link(receiver, callback, true)
260 | return "Created a new new link ! \n owner can get it by /owners "..matches[1].." get link"
261 | end
262 | end
263 | if matches[2] == 'get' then
264 | if matches[3] == 'link' then
265 | if not is_owner2(msg.from.id, chat_id) then
266 | return "You are not the owner of this group"
267 | end
268 | local group_link = data[tostring(matches[1])]['settings']['set_link']
269 | if not group_link then
270 | return "Create a link using /newlink first !"
271 | end
272 | local name = user_print_name(msg.from)
273 | savelog(matches[1], name.." ["..msg.from.id.."] requested group link ["..group_link.."]")
274 | return "Group link:\n"..group_link
275 | end
276 | end
277 | if matches[1] == 'changeabout' and matches[2] and is_owner2(msg.from.id, matches[2]) then
278 | local target = matches[2]
279 | local about = matches[3]
280 | local name = user_print_name(msg.from)
281 | savelog(matches[2], name.." ["..msg.from.id.."] has changed group description to ["..matches[3].."]")
282 | return set_description(target, about)
283 | end
284 | if matches[1] == 'changerules' and is_owner2(msg.from.id, matches[2]) then
285 | local rules = matches[3]
286 | local target = matches[2]
287 | local name = user_print_name(msg.from)
288 | savelog(matches[2], name.." ["..msg.from.id.."] has changed group rules to ["..matches[3].."]")
289 | return set_rules(target, rules)
290 | end
291 | if matches[1] == 'changename' and is_owner2(msg.from.id, matches[2]) then
292 | local new_name = string.gsub(matches[3], '_', ' ')
293 | data[tostring(matches[2])]['settings']['set_name'] = new_name
294 | save_data(_config.moderation.data, data)
295 | local group_name_set = data[tostring(matches[2])]['settings']['set_name']
296 | local to_rename = 'chat#id'..matches[2]
297 | local name = user_print_name(msg.from)
298 | savelog(matches[2], "Group {} name changed to [ "..new_name.." ] by "..name.." ["..msg.from.id.."]")
299 | rename_chat(to_rename, group_name_set, ok_cb, false)
300 | end
301 | if matches[1] == 'loggroup' and matches[2] and is_owner2(msg.from.id, matches[2]) then
302 | savelog(matches[2], "------")
303 | send_document("user#id".. msg.from.id,"./groups/logs/"..matches[2].."log.txt", ok_cb, false)
304 | end
305 | end
306 | end
307 | return {
308 | patterns = {
309 | "^[!/]owners (%d+) ([^%s]+) (.*)$",
310 | "^[!/]owners (%d+) ([^%s]+)$",
311 | "^[!/](changeabout) (%d+) (.*)$",
312 | "^[!/](changerules) (%d+) (.*)$",
313 | "^[!/](changename) (%d+) (.*)$",
314 | "^[!/](loggroup) (%d+)$"
315 | },
316 | run = run
317 | }
318 |
--------------------------------------------------------------------------------
/plugins/p.lua:
--------------------------------------------------------------------------------
1 | do
2 |
3 | -- Returns the key (index) in the config.enabled_plugins table
4 | local function plugin_enabled( name )
5 | for k,v in pairs(_config.enabled_plugins) do
6 | if name == v then
7 | return k
8 | end
9 | end
10 | -- If not found
11 | return false
12 | end
13 |
14 | -- Returns true if file exists in plugins folder
15 | local function plugin_exists( name )
16 | for k,v in pairs(plugins_names()) do
17 | if name..'.lua' == v then
18 | return true
19 | end
20 | end
21 | return false
22 | end
23 |
24 | local function list_all_plugins(only_enabled)
25 | local text = ''
26 | local nsum = 0
27 | for k, v in pairs( plugins_names( )) do
28 | -- 👌 enabled, 😔 disabled
29 | local status = '😔'
30 | nsum = nsum+1
31 | nact = 0
32 | -- Check if is enabled
33 | for k2, v2 in pairs(_config.enabled_plugins) do
34 | if v == v2..'.lua' then
35 | status = '👌'
36 | end
37 | nact = nact+1
38 | end
39 | if not only_enabled or status == '👌' then
40 | -- get the name
41 | v = string.match (v, "(.*)%.lua")
42 | text = text..nsum..'. '..v..' '..status..'\n'
43 | end
44 | end
45 | local text = text..'\nThere are '..nsum..' plugins installed.\n'..nact..' plugins enabled and '..nsum-nact..' disabled'
46 | return text
47 | end
48 |
49 | local function list_plugins(only_enabled)
50 | local text = ''
51 | local nsum = 0
52 | for k, v in pairs( plugins_names( )) do
53 | -- فعال enabled, 😔 disabled
54 | local status = '😔'
55 | nsum = nsum+1
56 | nact = 0
57 | -- Check if is enabled
58 | for k2, v2 in pairs(_config.enabled_plugins) do
59 | if v == v2..'.lua' then
60 | status = '👌'
61 | end
62 | nact = nact+1
63 | end
64 | if not only_enabled or status == 'فعاله' then
65 | -- get the name
66 | v = string.match (v, "(.*)%.lua")
67 | text = text..v..' '..status..'\n'
68 | end
69 | end
70 | local text = text..'\n'..nact..' plugins enabled from '..nsum..' plugins installed.'
71 | return text
72 | end
73 |
74 | local function reload_plugins( )
75 | plugins = {}
76 | load_plugins()
77 | return list_plugins(true)
78 | end
79 |
80 |
81 | local function enable_plugin( plugin_name )
82 | print('checking if '..plugin_name..' exists')
83 | -- Check if plugin is enabled
84 | if plugin_enabled(plugin_name) then
85 | return 'Plugin '..plugin_name..' is enabled'
86 | end
87 | -- Checks if plugin exists
88 | if plugin_exists(plugin_name) then
89 | -- Add to the config table
90 | table.insert(_config.enabled_plugins, plugin_name)
91 | print(plugin_name..' added to _config table')
92 | save_config()
93 | -- Reload the plugins
94 | return reload_plugins( )
95 | else
96 | return 'Plugin '..plugin_name..' does not exists'
97 | end
98 | end
99 |
100 | local function disable_plugin( name, chat )
101 | -- Check if plugins exists
102 | if not plugin_exists(name) then
103 | return 'Plugin '..name..' does not exists'
104 | end
105 | local k = plugin_enabled(name)
106 | -- Check if plugin is enabled
107 | if not k then
108 | return 'Plugin '..name..' not enabled'
109 | end
110 | -- Disable and reload
111 | table.remove(_config.enabled_plugins, k)
112 | save_config( )
113 | return reload_plugins(true)
114 | end
115 |
116 | local function disable_plugin_on_chat(receiver, plugin)
117 | if not plugin_exists(plugin) then
118 | return "Plugin doesn't exists"
119 | end
120 |
121 | if not _config.disabled_plugin_on_chat then
122 | _config.disabled_plugin_on_chat = {}
123 | end
124 |
125 | if not _config.disabled_plugin_on_chat[receiver] then
126 | _config.disabled_plugin_on_chat[receiver] = {}
127 | end
128 |
129 | _config.disabled_plugin_on_chat[receiver][plugin] = true
130 |
131 | save_config()
132 | return 'Plugin '..plugin..' disabled on this chat'
133 | end
134 |
135 | local function reenable_plugin_on_chat(receiver, plugin)
136 | if not _config.disabled_plugin_on_chat then
137 | return 'There aren\'t any disabled plugins'
138 | end
139 |
140 | if not _config.disabled_plugin_on_chat[receiver] then
141 | return 'There aren\'t any disabled plugins for this chat'
142 | end
143 |
144 | if not _config.disabled_plugin_on_chat[receiver][plugin] then
145 | return 'This plugin is not disabled'
146 | end
147 |
148 | _config.disabled_plugin_on_chat[receiver][plugin] = false
149 | save_config()
150 | return 'Plugin '..plugin..' is enabled again'
151 | end
152 |
153 | local function run(msg, matches)
154 | -- Show the available plugins
155 | if matches[1] == '!plugins' and is_sudo(msg) then --after changed to moderator mode, set only sudo
156 | return list_all_plugins()
157 | end
158 |
159 | -- Re-enable a plugin for this chat
160 | if matches[1] == 'enable' and matches[3] == 'chat' then
161 | local receiver = get_receiver(msg)
162 | local plugin = matches[2]
163 | print("enable "..plugin..' on this chat')
164 | return reenable_plugin_on_chat(receiver, plugin)
165 | end
166 |
167 | -- Enable a plugin
168 | if matches[1] == 'enable' and is_sudo(msg) then --after changed to moderator mode, set only sudo
169 | local plugin_name = matches[2]
170 | print("enable: "..matches[2])
171 | return enable_plugin(plugin_name)
172 | end
173 |
174 | -- Disable a plugin on a chat
175 | if matches[1] == 'disable' and matches[3] == 'chat' then
176 | local plugin = matches[2]
177 | local receiver = get_receiver(msg)
178 | print("disable "..plugin..' on this chat')
179 | return disable_plugin_on_chat(receiver, plugin)
180 | end
181 |
182 | -- Disable a plugin
183 | if matches[1] == 'disable' and is_sudo(msg) then --after changed to moderator mode, set only sudo
184 | if matches[2] == 'plugins' then
185 | return 'This plugin can\'t be disabled'
186 | end
187 | print("disable: "..matches[2])
188 | return disable_plugin(matches[2])
189 | end
190 |
191 | -- Reload all the plugins!
192 | if matches[1] == 'reload' and is_sudo(msg) then --after changed to moderator mode, set only sudo
193 | return reload_plugins(true)
194 | end
195 | end
196 |
197 | return {
198 | description = "Plugin to manage other plugins. Enable, disable or reload.",
199 | usage = {
200 | moderator = {
201 | "!plugins disable [plugin] chat : disable plugin only this chat.",
202 | "!plugins enable [plugin] chat : enable plugin only this chat.",
203 | },
204 | sudo = {
205 | "!plugins : list all plugins.",
206 | "!plugins enable [plugin] : enable plugin.",
207 | "!plugins disable [plugin] : disable plugin.",
208 | "!plugins reload : reloads all plugins." },
209 | },
210 | patterns = {
211 | "^!plugins$",
212 | "^!plugins? (enable) ([%w_%.%-]+)$",
213 | "^!plugins? (disable) ([%w_%.%-]+)$",
214 | "^!plugins? (enable) ([%w_%.%-]+) (chat)",
215 | "^!plugins? (disable) ([%w_%.%-]+) (chat)",
216 | "^!plugins? (reload)$" },
217 | run = run,
218 | moderated = true, -- set to moderator mode
219 | --privileged = true
220 | }
221 |
222 | end
223 |
--------------------------------------------------------------------------------
/plugins/plugmanager.lua:
--------------------------------------------------------------------------------
1 | do
2 |
3 | local function run(msg, matches)
4 | if not is_sudo(msg) then
5 | return "you have not accsess to filemanager"
6 | end
7 | local receiver = get_receiver(msg)
8 | if matches[1] == 'بفرس' then
9 |
10 | local file = matches[3]
11 |
12 | if matches[2] == 'sticker' and not matches[4] then
13 | send_document(receiver, "./media/"..file..".webp", ok_cb, false)
14 | end
15 |
16 | if matches[2] == 'photo' then
17 | send_photo(receiver, "./media/"..file..".jpeg", ok_cb, false)
18 | send_photo(receiver, "./media/"..file..".jpg", ok_cb, false)
19 | send_photo(receiver, "./media/"..file..".png", ok_cb, false)
20 | end
21 |
22 | if matches[2] == 'GIF' and not matches[4] then
23 | send_photo(receiver, "./media/"..file..".gif", ok_cb, false)
24 | end
25 |
26 | if matches[2] == 'music' then
27 | send_audio(receiver, "./media/"..file..".mp3", ok_cb, false)
28 | send_audio(receiver, "./media/"..file..".flac", ok_cb, false)
29 | send_audio(receiver, "./media/"..file..".aac", ok_cb, false)
30 | end
31 |
32 | if matches[2] == 'video' then
33 | send_photo(receiver, "./media/"..file..".avi", ok_cb, false)
34 | send_photo(receiver, "./media/"..file..".mpeg", ok_cb, false)
35 | send_photo(receiver, "./media/"..file..".mp4", ok_cb, false)
36 | end
37 |
38 | if matches[2] == 'file' then
39 | local extension = matches[4]
40 | send_document(receiver, "./media/"..file..'.'..extension, ok_cb, false)
41 | end
42 |
43 | if matches[2] == 'plugin' then
44 | send_document(receiver, "./plugins/"..file..".lua", ok_cb, false)
45 | end
46 |
47 | if matches[2] == 'dev' or matches[2] == 'm4ster' or matches[2] == 'master' or matches[2] == 'developer' or matches[2] == 'creator'then
48 | local extension = matches[4]
49 | if matches[3] == 'file' then
50 | send_document(receiver, "./media/M4STER.png", ok_cb, false)
51 | elseif matches[3] ~= 'file' or not matches[3] then
52 | send_photo(receiver, "./media/M4STER.png", ok_cb, false)
53 | end
54 | end
55 |
56 | if matches[2] == 'manual' and is_admin(msg) then
57 | local ruta = matches[3]
58 | local document = matches[4]
59 | send_document(receiver, "./"..ruta.."/"..document, ok_cb, false)
60 | end
61 |
62 | end
63 |
64 | if matches[1] == 'extensions' then
65 | return 'No disponible actualmente'
66 | end
67 |
68 | if matches[1] == 'list' and matches[2] == 'files' then
69 | return 'No disponible actualmente'
70 | --send_document(receiver, "./media/files/files.txt", ok_cb, false)
71 | end
72 | end
73 |
74 | return {
75 | description = "Kicking ourself (bot) from unmanaged groups.",
76 | usage = {
77 | "!list files : Envía un archivo con los nombres de todo lo que se puede enviar",
78 | "!extensions : Envía un mensaje con las extensiones para cada tipo de archivo permitidas",
79 | "➖➖➖➖➖➖➖➖➖➖",
80 | "!send sticker : Envía ese sticker del servidor",
81 | "!send photo : Envía esa foto del servidor",
82 | "!send GIF : Envía ese GIF del servidor",
83 | "!send music : Envía esa canción del servidor",
84 | "!send video : Envía ese video del servidor",
85 | "!send file : Envía ese archivo del servidor",
86 | "!send plugin : Envía ese archivo del servidor",
87 | "!send manual : Envía un archivo desde el directorio TeleSeed",
88 | "!send dev : Envía una foto del desarrollador"
89 | },
90 | patterns = {
91 | "^(بفرس) (.*) (.*) (.*)$",
92 | "^(بفرس) (.*) (.*)$",
93 | "^(بفرس) (.*)$",
94 | "^[!/](list) (files)$",
95 | "^[!/](extensions)$"
96 | },
97 | run = run
98 | }
99 | end
100 |
101 |
102 |
103 | --MODDED by @M4STER_ANGEL
104 |
--------------------------------------------------------------------------------
/plugins/quran.lua:
--------------------------------------------------------------------------------
1 | do
2 | umbrella = "http://umbrella.shayan-soft.ir/quran/" -- database
3 |
4 | -- get sound of sura
5 | local function read_sura(chat_id, target)
6 | local readq = http.request(umbrella.."Sura"..target..".mp3")
7 | local url = umbrella.."Sura"..target..".mp3"
8 | local file = download_to_file(url)
9 | local cb_extra = {file_path=file}
10 | return send_document("chat#id"..chat_id, file, rmtmp_cb, cb_extra)
11 | end
12 |
13 | -- get text of sura
14 | local function view_sura(chat_id, target)
15 | local viewq = http.request(umbrella.."quran ("..target..").txt")
16 | return viewq
17 | end
18 |
19 | -- run script
20 | local function run(msg, matches)
21 | local chat_id = msg.to.id
22 |
23 | if matches[1] == "read" then
24 | local target = matches[2]
25 | return read_sura(chat_id, target)
26 |
27 | elseif matches[1] == "sura" then
28 | local target = matches[2]
29 | return view_sura(chat_id, target)
30 |
31 | elseif matches [1] == "quran" then
32 | local qlist = http.request(umbrella.."list.txt") -- list of suras
33 | return qlist
34 |
35 | end
36 | end
37 |
38 | -- other help and commands
39 | return {
40 | description = "Umbrella Quran Project",
41 | usage = {
42 | "!sura (num) : view arabic sura",
43 | "!read (num) : send sound of sura",
44 | "!quran : sura list of quran",
45 | },
46 | patterns = {
47 | "^[!/](sura) (.+)$",
48 | "^[!/](read) (.+)$",
49 | "^[!/](quran)$",
50 | },
51 | run = run,
52 | }
53 | end
54 |
55 | -- thanks to shayan
56 |
--------------------------------------------------------------------------------
/plugins/set.lua:
--------------------------------------------------------------------------------
1 | local function save_value(msg, name, value)
2 | if (not name or not value) then
3 | return "Usage: !set var_name value"
4 | end
5 | local hash = nil
6 | if msg.to.type == 'chat' then
7 | hash = 'chat:'..msg.to.id..':variables'
8 | end
9 | if hash then
10 | redis:hset(hash, name, value)
11 | return "Saved "..name
12 | end
13 | end
14 | local function run(msg, matches)
15 | if not is_momod(msg) then
16 | return "For moderators only!"
17 | end
18 | local name = string.sub(matches[1], 1, 50)
19 | local value = string.sub(matches[2], 1, 1000)
20 | local name1 = user_print_name(msg.from)
21 | savelog(msg.to.id, name1.." ["..msg.from.id.."] saved ["..name.."] as > "..value )
22 | local text = save_value(msg, name, value)
23 | return text
24 | end
25 |
26 | return {
27 | patterns = {
28 | "^[!/]save ([^%s]+) (.+)$"
29 | },
30 | run = run
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/plugins/stats.lua:
--------------------------------------------------------------------------------
1 | do
2 |
3 | -- Returns a table with `name` and `msgs`
4 | local function get_msgs_user_chat(user_id, chat_id)
5 | local user_info = {}
6 | local uhash = 'user:'..user_id
7 | local user = redis:hgetall(uhash)
8 | local um_hash = 'msgs:'..user_id..':'..chat_id
9 | user_info.msgs = tonumber(redis:get(um_hash) or 0)
10 | user_info.name = user_print_name(user)..' ['..user_id..']'
11 | return user_info
12 | end
13 |
14 | local function chat_stats(chat_id)
15 | -- Users on chat
16 | local hash = 'chat:'..chat_id..':users'
17 | local users = redis:smembers(hash)
18 | local users_info = {}
19 | -- Get user info
20 | for i = 1, #users do
21 | local user_id = users[i]
22 | local user_info = get_msgs_user_chat(user_id, chat_id)
23 | table.insert(users_info, user_info)
24 | end
25 | -- Sort users by msgs number
26 | table.sort(users_info, function(a, b)
27 | if a.msgs and b.msgs then
28 | return a.msgs > b.msgs
29 | end
30 | end)
31 | local text = 'users in this chat \n'
32 | for k,user in pairs(users_info) do
33 | text = text..user.name..' = '..user.msgs..'\n'
34 | end
35 | local file = io.open("./groups/lists/"..chat_id.."stats.txt", "w")
36 | file:write(text)
37 | file:flush()
38 | file:close()
39 | send_document("chat#id"..chat_id,"./groups/lists/"..chat_id.."stats.txt", ok_cb, false)
40 | return --text
41 | end
42 |
43 | local function chat_stats2(chat_id)
44 | -- Users on chat
45 | local hash = 'chat:'..chat_id..':users'
46 | local users = redis:smembers(hash)
47 | local users_info = {}
48 |
49 | -- Get user info
50 | for i = 1, #users do
51 | local user_id = users[i]
52 | local user_info = get_msgs_user_chat(user_id, chat_id)
53 | table.insert(users_info, user_info)
54 | end
55 |
56 | -- Sort users by msgs number
57 | table.sort(users_info, function(a, b)
58 | if a.msgs and b.msgs then
59 | return a.msgs > b.msgs
60 | end
61 | end)
62 |
63 | local text = 'users in this chat \n'
64 | for k,user in pairs(users_info) do
65 | text = text..user.name..' = '..user.msgs..'\n'
66 | end
67 | return text
68 | end
69 | -- Save stats, ban user
70 | local function bot_stats()
71 |
72 | local redis_scan = [[
73 | local cursor = '0'
74 | local count = 0
75 |
76 | repeat
77 | local r = redis.call("SCAN", cursor, "MATCH", KEYS[1])
78 | cursor = r[1]
79 | count = count + #r[2]
80 | until cursor == '0'
81 | return count]]
82 |
83 | -- Users
84 | local hash = 'msgs:*:'..our_id
85 | local r = redis:eval(redis_scan, 1, hash)
86 | local text = 'Users: '..r
87 |
88 | hash = 'chat:*:users'
89 | r = redis:eval(redis_scan, 1, hash)
90 | text = text..'\nGroups: '..r
91 | return text
92 | end
93 | local function run(msg, matches)
94 | if matches[1]:lower() == 'teleseed' then -- Put everything you like :)
95 | local about = _config.about_text
96 | local name = user_print_name(msg.from)
97 | savelog(msg.to.id, name.." ["..msg.from.id.."] used /teleseed ")
98 | return about
99 | end
100 | if matches[1]:lower() == "statslist" then
101 | if not is_momod(msg) then
102 | return "For mods only !"
103 | end
104 | local chat_id = msg.to.id
105 | local name = user_print_name(msg.from)
106 | savelog(msg.to.id, name.." ["..msg.from.id.."] requested group stats ")
107 | return chat_stats2(chat_id)
108 | end
109 | if matches[1]:lower() == "stats" then
110 | if not matches[2] then
111 | if not is_momod(msg) then
112 | return "For mods only !"
113 | end
114 | if msg.to.type == 'chat' then
115 | local chat_id = msg.to.id
116 | local name = user_print_name(msg.from)
117 | savelog(msg.to.id, name.." ["..msg.from.id.."] requested group stats ")
118 | return chat_stats(chat_id)
119 | else
120 | return
121 | end
122 | end
123 | if matches[2] == "teleseed" then -- Put everything you like :)
124 | if not is_admin(msg) then
125 | return "For admins only !"
126 | else
127 | return bot_stats()
128 | end
129 | end
130 | if matches[2] == "group" then
131 | if not is_admin(msg) then
132 | return "For admins only !"
133 | else
134 | return chat_stats(matches[3])
135 | end
136 | end
137 | end
138 | end
139 | return {
140 | patterns = {
141 | "^[!/]([Ss]tats)$",
142 | "^[!/]([Ss]tatslist)$",
143 | "^[!/]([Ss]tats) (group) (%d+)",
144 | "^[!/]([Ss]tats) (teleseed)",-- Put everything you like :)
145 | "^[!/]([Tt]eleseed)"-- Put everything you like :)
146 | },
147 | run = run
148 | }
149 |
150 | end
151 |
--------------------------------------------------------------------------------
/plugins/tagall.lua:
--------------------------------------------------------------------------------
1 | --Tag ppl with username and a msg after it
2 | local function tagall(cb_extra, success, result)
3 | local receiver = cb_extra.receiver
4 | local chat_id = "chat#id"..result.id
5 | local text = ''
6 | local i = 0 + 1
7 | for k,v in pairs(result.members) do
8 | if v.username then
9 | text = text..i.."- @"..v.username.."\n"
10 | end
11 | end
12 | text = text.."\n"..cb_extra.msg_text
13 | send_large_msg(receiver, text)
14 | end
15 | local function run(msg, matches)
16 | local receiver = get_receiver(msg)
17 | if not is_owner(msg) then
18 | return "For owner only !"
19 | end
20 | if matches[1] then
21 | chat_info(receiver, tagall, {receiver = receiver,msg_text = matches[1]})
22 | end
23 | return
24 | end
25 | return {
26 |
27 | description = "Will tag all ppl with a msg.",
28 | usage = {
29 | "/tagall [msg]."
30 | },
31 | patterns = {
32 | "^[!/]tagall +(.+)$"
33 | },
34 | run = run
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/plugins/terminal.lua:
--------------------------------------------------------------------------------
1 | function run_sh(msg, matches)
2 | name = get_name(msg)
3 | text = ''
4 | -- if config.sh_enabled == false then
5 | -- text = '!sh command is disabled'
6 | -- else
7 | -- if is_sudo(msg) then
8 | -- bash = msg.text:sub(4,-1)
9 | -- text = run_bash(bash)
10 | -- else
11 | -- text = name .. ' you have no power here!'
12 | -- end
13 | -- end
14 | if is_sudo(msg) then
15 | bash = msg.text:sub(4,-1)
16 | text = run_bash(bash)
17 | else
18 | text = name .. ' you have no power here!'
19 | end
20 | return text
21 | end
22 |
23 | function run_bash(str)
24 | local cmd = io.popen(str)
25 | local result = cmd:read('*all')
26 | cmd:close()
27 | return result
28 | end
29 |
30 | function on_getting_dialogs(cb_extra,success,result)
31 | if success then
32 | local dialogs={}
33 | for key,value in pairs(result) do
34 | for chatkey, chat in pairs(value.peer) do
35 | print(chatkey,chat)
36 | if chatkey=="id" then
37 | table.insert(dialogs,chat.."\n")
38 | end
39 | if chatkey=="print_name" then
40 | table.insert(dialogs,chat..": ")
41 | end
42 | end
43 | end
44 |
45 | send_msg(cb_extra[1],table.concat(dialogs),ok_cb,false)
46 | end
47 | end
48 | function run(msg, matches)
49 | if not is_sudo(msg) then
50 | return "You aren't allowed!"
51 | end
52 | local receiver = get_receiver(msg)
53 | if string.match then
54 | text = run_bash(matches[1])
55 | send_large_msg(receiver, text, ok_cb, false)
56 | return
57 | end
58 | end
59 | return {
60 | description = "shows cpuinfo",
61 | usage = "!cpu",
62 | patterns = {"^[Tt]r (.*)$"},
63 | run = run
64 | }
65 |
--------------------------------------------------------------------------------
/plugins/xy.lua:
--------------------------------------------------------------------------------
1 | do
2 | local function run(msg, matches)
3 | local bot_id = id-bot -- ایدی بات
4 | local fbotmain = your-id -- ایدی خودت
5 |
6 | if matches[1] == 'left' and is_admin(msg) or msg.action.type == "chat_add_user" and msg.action.user.id == tonumber(bot_id) and not is_sudo(msg) then
7 | chat_del_user("chat#id"..msg.to.id, 'user#id'..bot_id, ok_cb, false)
8 | elseif msg.action.type == "chat_del_user" and msg.action.user.id == tonumber(fbotmain) then
9 | chat_add_user("chat#id"..msg.to.id, 'user#id'..fbotmain, ok_cb, false)
10 | end
11 | end
12 |
13 | return {
14 | patterns = {
15 | "^[!/]([Ll][Ee][Ff][Tt])$",
16 | "^!!tgservice (.+)$",
17 | },
18 | run = run
19 | }
20 | end
21 |
--------------------------------------------------------------------------------