├── .deepsource.toml ├── .gitignore ├── .pep8speaks.yml ├── LICENSE ├── Procfile ├── README.md ├── assistant ├── __init__.py ├── __main__.py ├── bot.py ├── config.py ├── cus_filters.py ├── database.py ├── logger.py ├── plugins │ ├── __init__.py │ ├── alive.py │ ├── antiflood.py │ ├── blacklist.py │ ├── gadmin.py │ ├── id.py │ ├── inline_docs.py │ ├── json.py │ ├── paste.py │ ├── ping.py │ ├── reply.py │ ├── repo.py │ ├── report.py │ ├── rules.py │ ├── start.py │ ├── verify_new_members.py │ └── warn.py ├── utils │ ├── __init__.py │ ├── docs.py │ └── tools.py └── versions.py ├── requirements.txt ├── run └── runtime.txt /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "python" 5 | enabled = true 6 | dependency_file_paths = ["requirements.txt"] 7 | 8 | [analyzers.meta] 9 | runtime_version = "3.x.x" 10 | max_line_length = 100 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # config files 132 | config.ini 133 | config.env 134 | .vscode/ 135 | *.session 136 | log.txt 137 | unknown_errors.txt -------------------------------------------------------------------------------- /.pep8speaks.yml: -------------------------------------------------------------------------------- 1 | # File : .pep8speaks.yml 2 | 3 | scanner: 4 | linter: flake8 5 | 6 | flake8: 7 | max-line-length: 100 8 | 9 | message: 10 | opened: 11 | header: "@{name}, Thanks for opening this PR." 12 | updated: 13 | header: "@{name}, Thanks for updating this PR." -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: bash run -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Userge-Assistant 2 | assistant-bot for manage [userge OT group](https://t.me/UsergeOT) 3 | -------------------------------------------------------------------------------- /assistant/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from .logger import logging # noqa 10 | from .config import Config # noqa 11 | from .bot import bot # noqa 12 | from . import cus_filters # noqa 13 | from .database import DB, save_data, load_data # noqa 14 | -------------------------------------------------------------------------------- /assistant/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from assistant import bot 10 | 11 | if __name__ == "__main__": 12 | bot.run() 13 | -------------------------------------------------------------------------------- /assistant/bot.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | __all__ = ["bot", "START_TIME"] 10 | 11 | import time 12 | 13 | from pyrogram import Client 14 | 15 | from . import Config, logging 16 | 17 | _LOG = logging.getLogger(__name__) 18 | START_TIME = time.time() 19 | 20 | bot = Client(":memory:", 21 | api_id=Config.APP_ID, 22 | api_hash=Config.API_HASH, 23 | bot_token=Config.BOT_TOKEN, 24 | plugins={'root': "assistant.plugins", 25 | 'exclude': ['antiflood', 'blacklist', 'gadmin', # 😟😞 26 | 'report', 'warn', 'verify_new_members']}) 27 | 28 | _LOG.info("assistant-bot initialized!") 29 | -------------------------------------------------------------------------------- /assistant/config.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | __all__ = ["Config"] 10 | 11 | import os 12 | 13 | from dotenv import load_dotenv 14 | 15 | if os.path.isfile("config.env"): 16 | load_dotenv("config.env") 17 | 18 | 19 | class Config: 20 | """ assistant configs """ 21 | APP_ID = int(os.environ.get("APP_ID", 0)) 22 | API_HASH = os.environ.get("API_HASH") 23 | BOT_TOKEN = os.environ.get("BOT_TOKEN") 24 | AUTH_CHATS = set([-1001481357570]) # @UserGeOt 25 | if os.environ.get("AUTH_CHATS"): 26 | AUTH_CHATS.update(map(int, os.environ.get("AUTH_CHATS").split())) 27 | WHITELIST_CHATS = set([-1001465749479]) # @UserGeSpam 28 | if os.environ.get("WHITELIST_CHATS"): 29 | WHITELIST_CHATS.update(map(int, os.environ.get("WHITELIST_CHATS").split())) 30 | DEV_USERS = ( 31 | 1158855661, # @Krishna_Singhal 32 | 1110621941, # @PhycoNinja13b 33 | 921420874, # @juznem 34 | 837784353 # @rking_32 35 | ) 36 | ADMINS = {} 37 | MAX_MSG_LENGTH = 4096 38 | -------------------------------------------------------------------------------- /assistant/cus_filters.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | __all__ = ["auth_chats", "auth_users", "whitelist_chats"] 10 | 11 | import asyncio 12 | 13 | from pyrogram import filters, Client 14 | from pyrogram.types import Message 15 | 16 | from . import Config, logging 17 | 18 | _LOG = logging.getLogger(__name__) 19 | _FETCHING = False 20 | 21 | 22 | async def _is_admin_or_dev(_, bot: Client, msg: Message) -> bool: 23 | global _FETCHING # pylint: disable=global-statement 24 | if msg.chat.id not in Config.AUTH_CHATS: 25 | return False 26 | if not msg.from_user: 27 | return False 28 | if msg.from_user.id in Config.DEV_USERS: 29 | return True 30 | while _FETCHING: 31 | _LOG.info("waiting for fetching task ... sleeping (5s) !") 32 | await asyncio.sleep(5) 33 | if msg.chat.id not in Config.ADMINS: 34 | _FETCHING = True 35 | admins = [] 36 | _LOG.info("fetching data from [%s] ...", msg.chat.id) 37 | # pylint: disable=protected-access 38 | async for c_m in bot.iter_chat_members(msg.chat.id): 39 | if c_m.status in ("creator", "administrator"): 40 | admins.append(c_m.user.id) 41 | Config.ADMINS[msg.chat.id] = tuple(admins) 42 | _LOG.info("data fetched from [%s] !", msg.chat.id) 43 | del admins 44 | _FETCHING = False 45 | return msg.from_user.id in Config.ADMINS[msg.chat.id] 46 | 47 | 48 | async def _is_chat_whitelist(_, __, msg: Message) -> bool: 49 | if msg.chat.id in Config.WHITELIST_CHATS: 50 | return True 51 | return False 52 | 53 | 54 | auth_chats = filters.chat(list(Config.AUTH_CHATS)) 55 | auth_users = filters.create(_is_admin_or_dev) 56 | whitelist_chats = filters.create(_is_chat_whitelist) 57 | -------------------------------------------------------------------------------- /assistant/database.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | __all__ = ["DB", "save_data", "load_data"] 10 | 11 | import json 12 | from typing import Dict 13 | 14 | from assistant import bot 15 | from pyrogram.errors import MessageNotModified 16 | 17 | 18 | class DB: 19 | CHANNEL_ID = -1001480669647 20 | WARN_LIMIT_ID = 7 21 | WARN_MODE_ID = 8 22 | WARN_DATA_ID = 9 23 | BLACKLIST_MODE_ID = 10 24 | BLACKLIST_DATA_ID = 11 25 | 26 | 27 | async def load_data(msg_id: int) -> Dict: 28 | msg = await bot.get_messages(DB.CHANNEL_ID, msg_id) 29 | if msg: 30 | return json.loads(msg.text) 31 | return {} 32 | 33 | 34 | async def save_data(msg_id: int, text: str) -> None: 35 | try: 36 | await bot.edit_message_text( 37 | DB.CHANNEL_ID, 38 | msg_id, 39 | f"`{text}`", 40 | disable_web_page_preview=True 41 | ) 42 | except MessageNotModified: 43 | pass 44 | -------------------------------------------------------------------------------- /assistant/logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | __all__ = ["logging"] 10 | 11 | import logging 12 | 13 | # enable logging 14 | logging.basicConfig( 15 | level=logging.INFO, 16 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" 17 | ) 18 | 19 | logging.getLogger("pyrogram").setLevel(logging.WARNING) 20 | -------------------------------------------------------------------------------- /assistant/plugins/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | -------------------------------------------------------------------------------- /assistant/plugins/alive.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import time 10 | import random 11 | 12 | from pyrogram import filters 13 | from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton 14 | from pyrogram.errors import FileIdInvalid, FileReferenceEmpty, BadRequest 15 | 16 | from assistant import bot, cus_filters, versions 17 | from assistant.bot import START_TIME 18 | from assistant.utils import time_formatter 19 | 20 | LOGO_DATA = [] 21 | MSG_IDS = [499509, 499428, 496502, 496360, 496498] 22 | 23 | 24 | @bot.on_message(filters.command("alive") & cus_filters.auth_chats) 25 | async def _alive(_, message: Message): 26 | try: 27 | await _sendit(message.chat.id) 28 | except (FileIdInvalid, FileReferenceEmpty, BadRequest): 29 | await _refresh_data() 30 | await _sendit(message.chat.id) 31 | 32 | 33 | async def _refresh_data(): 34 | LOGO_DATA.clear() 35 | for msg in await bot.get_messages('UserGeOt', MSG_IDS): 36 | if not msg.animation: 37 | continue 38 | gif = msg.animation 39 | LOGO_DATA.append(gif.file_id) 40 | 41 | 42 | async def _sendit(chat_id): 43 | if not LOGO_DATA: 44 | await _refresh_data() 45 | caption = f""" 46 | **🤖 Bot Uptime** : `{time_formatter(time.time() - START_TIME)}` 47 | **🤖 Bot Version** : `{versions.__assistant_version__}` 48 | **️️⭐ Python** : `{versions.__python_version__}` 49 | **💥 Pyrogram** : `{versions.__pyro_version__}` """ 50 | button = InlineKeyboardMarkup( 51 | [ 52 | [ 53 | InlineKeyboardButton( 54 | text="License", 55 | url=("https://github.com/" 56 | "UsergeTeam/Userge-Assistant/blob/master/LICENSE")), 57 | InlineKeyboardButton( 58 | text="Repo", 59 | url="https://github.com/UsergeTeam/Userge-Assistant") 60 | ] 61 | ] 62 | ) 63 | file_id = random.choice(LOGO_DATA) 64 | await bot.send_animation(chat_id=chat_id, 65 | animation=file_id, 66 | caption=caption, 67 | reply_markup=button) 68 | -------------------------------------------------------------------------------- /assistant/plugins/antiflood.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import time 10 | 11 | from pyrogram import filters 12 | from pyrogram.types import Message 13 | from assistant import bot, cus_filters 14 | 15 | DATA = {} 16 | 17 | MSG_LIMIT = 8 18 | WARN_LIMIT = 5 19 | MIN_DELAY = 3 20 | 21 | 22 | @bot.on_message(filters.incoming & ~filters.edited & cus_filters.auth_chats & 23 | ~cus_filters.auth_users & ~cus_filters.whitelist_chats, group=1) 24 | async def _flood(_, message: Message): 25 | chat_flood = DATA.get(message.chat.id) 26 | if chat_flood is None: 27 | data = { 28 | 'user_id': message.from_user.id, 29 | 'time': time.time(), 30 | 'count': 1 31 | } 32 | DATA[message.chat.id] = data 33 | return 34 | cur_user = message.from_user.id 35 | if cur_user != chat_flood['user_id']: 36 | data = { 37 | 'user_id': cur_user, 38 | 'time': time.time(), 39 | 'count': 1 40 | } 41 | DATA[message.chat.id] = data 42 | return 43 | prev_count = chat_flood['count'] 44 | prev_time = chat_flood['time'] 45 | if (time.time() - prev_time) < MIN_DELAY: 46 | count = prev_count + 1 47 | if count >= MSG_LIMIT: 48 | await message.chat.kick_member(cur_user, until_date=int(time.time() + 45)) 49 | await message.reply("**MAX FLOOD LIMIT REACHED**\n User Has been Kicked.") 50 | elif count == WARN_LIMIT: 51 | await message.reply("**WARN**\n `Flood Detected !`") 52 | else: 53 | count = 1 54 | DATA[message.chat.id] = {'user_id': cur_user, 'time': time.time(), 'count': count} 55 | message.continue_propagation() 56 | -------------------------------------------------------------------------------- /assistant/plugins/blacklist.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import re 10 | import time 11 | import json 12 | import asyncio 13 | 14 | from typing import Dict, List 15 | from pyrogram import filters 16 | from pyrogram.types import Message, ChatPermissions 17 | 18 | from assistant import bot, cus_filters as Filters, DB, save_data, load_data 19 | from assistant.plugins.warn import warn as warn_user 20 | from assistant.utils import check_bot_rights 21 | 22 | 23 | @bot.on_message( 24 | filters.command("addblacklist") & Filters.auth_chats & Filters.auth_users) 25 | async def _add_blacklist(_, msg: Message): 26 | if msg.text and len(msg.text) == 13: 27 | await msg.reply("`Input not found...`") 28 | return 29 | _, args = msg.text.split(maxsplit=1) 30 | chat_id = str(msg.chat.id) 31 | 32 | BLACK_LIST = await load_data(DB.BLACKLIST_DATA_ID) 33 | triggers = list({trigger.strip() 34 | for trigger in args.lower().split("\n") if trigger.strip()}) 35 | for word in triggers: 36 | if BLACK_LIST.get(chat_id): 37 | BLACK_LIST[chat_id].append(word) 38 | else: 39 | BLACK_LIST[chat_id] = [word] 40 | await save_data(DB.BLACKLIST_DATA_ID, json.dumps(BLACK_LIST)) 41 | if len(triggers) == 1: 42 | out = f"added `{triggers[0]}` to blacklist." 43 | else: 44 | out = f"added `{len(triggers)} words` to blacklist." 45 | await msg.reply(out) 46 | 47 | 48 | @bot.on_message( 49 | filters.command("delblacklist") & Filters.auth_chats & Filters.auth_users) 50 | async def _del_blacklist(_, msg: Message): 51 | global BLACK_LIST # pylint: disable=global-statement 52 | if msg.text and len(msg.text) == 13: 53 | await msg.reply("`Input not found...`") 54 | return 55 | _, args = msg.text.split(maxsplit=1) 56 | chat_id = str(msg.chat.id) 57 | 58 | triggers = list({trigger.strip() 59 | for trigger in args.split("\n") if trigger.strip()}) 60 | success = 0 61 | failure = 0 62 | BLACK_LIST = await load_data(DB.BLACKLIST_DATA_ID) 63 | for word in triggers: 64 | if word in BLACK_LIST.get(chat_id): 65 | BLACK_LIST[chat_id].remove(word) 66 | success += 1 67 | else: 68 | failure += 1 69 | await save_data(DB.BLACKLIST_DATA_ID, json.dumps(BLACK_LIST)) 70 | if len(triggers) == 1: 71 | if success: 72 | out = f"`{triggers[0]}` deleted from blacklist." 73 | else: 74 | out = f"`{triggers[0]}` is not in blacklist." 75 | elif failure == len(triggers): 76 | out = "`None of these words are in my blacklist.`" 77 | elif success == len(triggers): 78 | out = f"`{len(triggers)} words` deleted from blacklist." 79 | else: 80 | out = f"`{success} words` deleted from blacklist, " 81 | out += f"`{failure} words` not in blacklist." 82 | await msg.reply(out) 83 | 84 | 85 | @bot.on_message( 86 | filters.command("blacklist") & Filters.auth_chats) 87 | async def _blacklist(_, msg: Message): 88 | chat_id = str(msg.chat.id) 89 | BLACK_LIST = await load_data(DB.BLACKLIST_DATA_ID) 90 | if BLACK_LIST.get(chat_id) is None: 91 | bl_words = f"`Blacklist empty for {msg.chat.title}`" 92 | else: 93 | bl_words = f"Blacklist Words in `{msg.chat.title}`:-\n" 94 | for trigger in BLACK_LIST.get(chat_id): 95 | bl_words += f"- `{trigger}`\n" 96 | await msg.reply(bl_words) 97 | 98 | 99 | @bot.on_message( 100 | filters.command("setblacklist") & Filters.auth_chats & Filters.auth_users) 101 | async def _set_blacklist_mode(_, msg: Message): 102 | if msg.text and len(msg.text) == 13: 103 | await msg.reply("`Input not found...`") 104 | return 105 | _, args = msg.text.split(maxsplit=1) 106 | chat_id = str(msg.chat.id) 107 | BLACKLIST_MODE = await load_data(DB.BLACKLIST_MODE_ID) 108 | _MODE = {chat_id: "warn"} 109 | if 'warn' in args.lower(): 110 | _MODE = {chat_id: "warn"} 111 | await msg.reply("`Blacklist Mode Updated to Warn`") 112 | elif 'ban' in args.lower(): 113 | _MODE = {chat_id: "ban"} 114 | await msg.reply("`Blacklist Mode Updated to Ban`") 115 | elif 'kick' in args.lower(): 116 | _MODE = {chat_id: "kick"} 117 | await msg.reply("`Blacklist Mode Updated to Kick`") 118 | elif 'mute' in args.lower(): 119 | _MODE = {chat_id: "mute"} 120 | await msg.reply("`Blacklist Mode Updated to Mute`") 121 | elif 'off' in args.lower(): 122 | _MODE = {chat_id: "off"} 123 | await msg.reply("`Blacklist Turned Off...`") 124 | elif 'del' in args.lower(): 125 | _MODE = {chat_id: "del"} 126 | await msg.reply("`Now Blacklisted word will only delete.`") 127 | else: 128 | await msg.reply("`Invalid arguments, Exiting...`") 129 | BLACKLIST_MODE.update(_MODE) 130 | await save_data(DB.BLACKLIST_MODE_ID, json.dumps(BLACKLIST_MODE)) 131 | 132 | 133 | @bot.on_message( 134 | filters.incoming & ~filters.edited & Filters.auth_chats & ~Filters.auth_users, group=1 135 | ) 136 | async def _filter_blacklist(_, msg: Message): 137 | chat_id = str(msg.chat.id) 138 | BLACK_LIST = await load_data(DB.BLACKLIST_DATA_ID) 139 | BLACKLIST_MODE = await load_data(DB.BLACKLIST_MODE_ID) 140 | if BLACKLIST_MODE.get(chat_id) is None: 141 | BLACKLIST_MODE.update({chat_id: "warn"}) 142 | await save_data(DB.BLACKLIST_MODE_ID, json.dumps(BLACKLIST_MODE)) 143 | if BLACK_LIST.get(chat_id) is None: 144 | return 145 | 146 | text = None 147 | if msg.text: 148 | text = msg.text.lower() 149 | elif msg.caption: 150 | text = msg.caption.lower() 151 | if text and BLACK_LIST.get(chat_id) is not None: 152 | for trigger in BLACK_LIST.get(chat_id): 153 | pattern = r"( |^|[^\w])" + re.escape(trigger) + r"( |$|[^\w])" 154 | if re.search(pattern, text, re.IGNORECASE): 155 | reason = f"Due to match on {trigger} Blacklisted word." 156 | try: 157 | if await check_bot_rights(msg.chat.id, "can_delete_messages"): 158 | await msg.delete() 159 | if BLACKLIST_MODE.get(chat_id) == "del": 160 | if await check_bot_rights(msg.chat.id, "can_delete_messages"): 161 | await msg.reply(f"#DELETED\n\n{reason}") 162 | elif BLACKLIST_MODE.get(chat_id) == "warn": 163 | await warn_user(msg, msg.chat.id, msg.from_user.id, reason) 164 | elif BLACKLIST_MODE.get(chat_id) == "ban": 165 | await asyncio.gather( 166 | bot.kick_chat_member(msg.chat.id, msg.from_user.id), 167 | msg.reply(f"#BANNED\n\n{reason}") 168 | ) 169 | elif BLACKLIST_MODE.get(chat_id) == "kick": 170 | await asyncio.gather( 171 | bot.kick_chat_member( 172 | msg.chat.id, msg.from_user.id, time.time() + 45), 173 | msg.reply(f"#KICKED\n\n{reason}") 174 | ) 175 | elif BLACKLIST_MODE.get(chat_id) == "mute": 176 | await asyncio.gather( 177 | bot.restrict_chat_member( 178 | msg.chat.id, msg.from_user.id, ChatPermissions()), 179 | msg.reply(f"#MUTED\n\n{reason}") 180 | ) 181 | except Exception: 182 | pass 183 | break 184 | -------------------------------------------------------------------------------- /assistant/plugins/gadmin.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import time 10 | import asyncio 11 | 12 | from pyrogram import filters 13 | from pyrogram.types import Message, ChatPermissions 14 | from pyrogram.errors import ( 15 | FloodWait, UserAdminInvalid, UsernameInvalid, PeerIdInvalid, UserIdInvalid) 16 | 17 | from assistant import bot, cus_filters 18 | from assistant.utils import ( 19 | is_dev, is_self, is_admin, 20 | sed_sticker, check_rights, 21 | check_bot_rights, extract_time) 22 | 23 | 24 | @bot.on_message( 25 | filters.command("ban") & cus_filters.auth_chats & cus_filters.auth_users) 26 | async def _ban_user(_, msg: Message): 27 | chat_id = msg.chat.id 28 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 29 | return 30 | cmd = len(msg.text) 31 | replied = msg.reply_to_message 32 | reason = '' 33 | if replied: 34 | id_ = replied.from_user.id 35 | if cmd > 4: 36 | _, reason = msg.text.split(maxsplit=1) 37 | elif cmd > 4: 38 | _, args = msg.text.split(maxsplit=1) 39 | if ' ' in args: 40 | id_, reason = args.split(' ', maxsplit=1) 41 | else: 42 | id_ = args 43 | else: 44 | await msg.reply("`No valid User_id or message specified.`") 45 | return 46 | try: 47 | user = await bot.get_users(id_) 48 | user_id = user.id 49 | mention = user.mention 50 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 51 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 52 | return 53 | if await is_self(user_id): 54 | await sed_sticker(msg) 55 | return 56 | if is_dev(user_id): 57 | await msg.reply("`He is My Master, I will not Ban him.`") 58 | return 59 | if is_admin(chat_id, user_id): 60 | await msg.reply("`User is Admin, Can't Ban him.`") 61 | return 62 | if not await check_bot_rights(chat_id, "can_restrict_members"): 63 | await msg.reply("`Give me rights to Ban Users.`") 64 | await sed_sticker(msg) 65 | return 66 | sent = await msg.reply("`Trying to Ban User.. Hang on!! ⏳`") 67 | try: 68 | await bot.kick_chat_member(chat_id, user_id) 69 | await sent.edit( 70 | f"#BAN\n" 71 | f"USER: {mention}\n" 72 | f"REASON: `{reason or None}`") 73 | except Exception as e_f: # pylint: disable=broad-except 74 | await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 75 | 76 | 77 | @bot.on_message( 78 | filters.command("tban") & cus_filters.auth_chats & cus_filters.auth_users) 79 | async def _tban_user(_, msg: Message): 80 | chat_id = msg.chat.id 81 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 82 | return 83 | cmd = len(msg.text) 84 | replied = msg.reply_to_message 85 | if replied: 86 | id_ = replied.from_user.id 87 | if cmd <= 5: 88 | await msg.reply("`Time limit not found.`") 89 | return 90 | _, args = msg.text.split(maxsplit=1) 91 | elif cmd > 5: 92 | _, text = msg.text.split(maxsplit=1) 93 | if ' ' in text: 94 | id_, args = text.split(' ', maxsplit=1) 95 | else: 96 | await msg.reply("`Time limit not found.`") 97 | else: 98 | await msg.reply("`No valid User_id or message specified.`") 99 | return 100 | if ' ' in args: 101 | split = args.split(None, 1) 102 | time_val = split[0].lower() 103 | reason = split[1] 104 | else: 105 | time_val = args 106 | reason = '' 107 | 108 | time_ = await extract_time(msg, time_val) 109 | if not time_: 110 | return 111 | try: 112 | user = await bot.get_users(id_) 113 | user_id = user.id 114 | mention = user.mention 115 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 116 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 117 | return 118 | if await is_self(user_id): 119 | await sed_sticker(msg) 120 | return 121 | if is_dev(user_id): 122 | await msg.reply("`He is My Master, I will not Ban him.`") 123 | return 124 | if is_admin(chat_id, user_id): 125 | await msg.reply("`User is Admin, Can't Ban him.`") 126 | return 127 | if not await check_bot_rights(chat_id, "can_restrict_members"): 128 | await msg.reply("`Give me rights to Ban Users.`") 129 | await sed_sticker(msg) 130 | return 131 | sent = await msg.reply("`Trying to Ban User.. Hang on!! ⏳`") 132 | try: 133 | await bot.kick_chat_member( 134 | chat_id, user_id, time_) 135 | await asyncio.sleep(1) 136 | await sent.edit( 137 | f"#TEMP_BAN\n" 138 | f"USER: {mention}\n" 139 | f"TIME: `{time_val}`\n" 140 | f"REASON: `{reason or None}`") 141 | except Exception as e_f: # pylint: disable=broad-except 142 | await sent.edit(f"`Something went wrong 🤔`\n\n**ERROR**: `{e_f}`") 143 | 144 | 145 | @bot.on_message( 146 | filters.command("unban") & cus_filters.auth_chats & cus_filters.auth_users) 147 | async def _unban_user(_, msg: Message): 148 | chat_id = msg.chat.id 149 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 150 | return 151 | replied = msg.reply_to_message 152 | if replied: 153 | id_ = replied.from_user.id 154 | elif len(msg.text) > 6: 155 | _, id_ = msg.text.split(maxsplit=1) 156 | else: 157 | await msg.reply("`No valid User_id or message specified.`") 158 | return 159 | try: 160 | user_id = (await bot.get_users(id_)).id 161 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 162 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 163 | return 164 | if await is_self(user_id): 165 | return 166 | if is_admin(chat_id, user_id): 167 | await msg.reply("`User is Admin.`") 168 | return 169 | if not await check_bot_rights(chat_id, "can_restrict_members"): 170 | await msg.reply("`Give me rights to UnBan Users.`") 171 | await sed_sticker(msg) 172 | return 173 | sent = await msg.reply("`Trying to UnBan User.. Hang on!! ⏳`") 174 | try: 175 | await bot.unban_chat_member(chat_id, user_id) 176 | await sent.edit("`🛡Unbanned Successfully...`") 177 | except Exception as e_f: # pylint: disable=broad-except 178 | await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 179 | 180 | 181 | @bot.on_message( 182 | filters.command("kick") & cus_filters.auth_chats & cus_filters.auth_users) 183 | async def _kick_user(_, msg: Message): 184 | chat_id = msg.chat.id 185 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 186 | return 187 | cmd = len(msg.text) 188 | replied = msg.reply_to_message 189 | reason = '' 190 | if replied: 191 | id_ = replied.from_user.id 192 | if cmd > 5: 193 | _, reason = msg.text.split(maxsplit=1) 194 | elif cmd > 5: 195 | _, args = msg.text.split(maxsplit=1) 196 | if ' ' in args: 197 | id_, reason = args.split(' ', maxsplit=1) 198 | else: 199 | id_ = args 200 | else: 201 | await msg.reply("`No valid User_id or message specified.`") 202 | return 203 | try: 204 | user = await bot.get_users(id_) 205 | user_id = user.id 206 | mention = user.mention 207 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 208 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 209 | return 210 | if await is_self(user_id): 211 | await sed_sticker(msg) 212 | return 213 | if is_dev(user_id): 214 | await msg.reply("`He is My Master, I will not Kick him.`") 215 | return 216 | if is_admin(chat_id, user_id): 217 | await msg.reply("`User is Admin, Can't Kick him.`") 218 | return 219 | if not await check_bot_rights(chat_id, "can_restrict_members"): 220 | await msg.reply("`Give me rights to Kick Users.`") 221 | await sed_sticker(msg) 222 | return 223 | sent = await msg.reply("`Trying to Kick User.. Hang on!! ⏳`") 224 | try: 225 | await bot.kick_chat_member(chat_id, user_id, int(time.time() + 60)) 226 | await sent.edit( 227 | "#KICK\n" 228 | f"USER: {mention}\n" 229 | f"REASON: `{reason or None}`") 230 | except Exception as e_f: # pylint: disable=broad-except 231 | await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 232 | 233 | 234 | @bot.on_message( 235 | filters.command("promote") & cus_filters.auth_chats & cus_filters.auth_users) 236 | async def _promote_user(_, msg: Message): 237 | chat_id = msg.chat.id 238 | if not await check_rights(chat_id, msg.from_user.id, "can_promote_members"): 239 | return 240 | replied = msg.reply_to_message 241 | if replied: 242 | id_ = replied.from_user.id 243 | elif len(msg.text) > 8: 244 | _, id_ = msg.text.split(maxsplit=1) 245 | else: 246 | await msg.reply("`No valid User_id or message specified.`") 247 | return 248 | try: 249 | user_id = (await bot.get_users(id_)).id 250 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 251 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 252 | return 253 | if await is_self(user_id): 254 | return 255 | if is_admin(chat_id, user_id): 256 | await msg.reply("`User is Already Promoted`") 257 | return 258 | if not await check_bot_rights(chat_id, "can_promote_members"): 259 | await msg.reply("`Give me rights to Promote User.`") 260 | await sed_sticker(msg) 261 | return 262 | sent = await msg.reply("`Trying to Promote User.. Hang on!! ⏳`") 263 | try: 264 | await bot.promote_chat_member(chat_id, user_id, 265 | can_change_info=True, 266 | can_delete_messages=True, 267 | can_restrict_members=True, 268 | can_invite_users=True, 269 | can_pin_messages=True) 270 | await sent.edit("`👑 Promoted Successfully..`") 271 | except Exception as e_f: # pylint: disable=broad-except 272 | await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 273 | 274 | 275 | @bot.on_message( 276 | filters.command("demote") & cus_filters.auth_chats & cus_filters.auth_users) 277 | async def _demote_user(_, msg: Message): 278 | chat_id = msg.chat.id 279 | if not await check_rights(chat_id, msg.from_user.id, "can_promote_members"): 280 | return 281 | replied = msg.reply_to_message 282 | if replied: 283 | id_ = replied.from_user.id 284 | elif len(msg.text) > 7: 285 | _, id_ = msg.text.split(maxsplit=1) 286 | else: 287 | await msg.reply("`No valid User_id or message specified.`") 288 | return 289 | try: 290 | user_id = (await bot.get_users(id_)).id 291 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 292 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 293 | return 294 | if await is_self(user_id): 295 | await sed_sticker(msg) 296 | return 297 | if is_dev(user_id): 298 | return 299 | if not is_admin(chat_id, user_id): 300 | await msg.reply("`Cant demote a Demoted User`") 301 | return 302 | if not await check_bot_rights(chat_id, "can_promote_members"): 303 | await msg.reply("`Give me rights to Demote User.`") 304 | await sed_sticker(msg) 305 | return 306 | sent = await msg.reply("`Trying to Demote User.. Hang on!! ⏳`") 307 | try: 308 | await bot.promote_chat_member(chat_id, user_id, 309 | can_change_info=False, 310 | can_delete_messages=False, 311 | can_restrict_members=False, 312 | can_invite_users=False, 313 | can_pin_messages=False) 314 | await sent.edit("`🛡 Demoted Successfully..`") 315 | except Exception as e_f: # pylint: disable=broad-except 316 | await sent.edit(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 317 | 318 | 319 | @bot.on_message( 320 | filters.command("mute") & cus_filters.auth_chats & cus_filters.auth_users) 321 | async def _mute_user(_, msg: Message): 322 | chat_id = msg.chat.id 323 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 324 | return 325 | cmd = len(msg.text) 326 | replied = msg.reply_to_message 327 | reason = '' 328 | if replied: 329 | id_ = replied.from_user.id 330 | if cmd > 5: 331 | _, reason = msg.text.split(maxsplit=1) 332 | elif cmd > 5: 333 | _, args = msg.text.split(maxsplit=1) 334 | if ' ' in args: 335 | id_, reason = args.split(' ', maxsplit=1) 336 | else: 337 | id_ = args 338 | else: 339 | await msg.reply("`No valid User_id or message specified.`") 340 | return 341 | try: 342 | user = await bot.get_users(id_) 343 | user_id = user.id 344 | mention = user.mention 345 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 346 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 347 | return 348 | if await is_self(user_id): 349 | await sed_sticker(msg) 350 | return 351 | if is_dev(user_id): 352 | await msg.reply("`He is My Master, I will not Mute him.`") 353 | return 354 | if is_admin(chat_id, user_id): 355 | await msg.reply("`User is Admin, Can't Mute him.`") 356 | return 357 | if not await check_bot_rights(chat_id, "can_restrict_members"): 358 | await msg.reply("`Give me rights to Mute Users.`") 359 | await sed_sticker(msg) 360 | return 361 | sent = await msg.reply("`Trying to Mute User.. Hang on!! ⏳`") 362 | try: 363 | await bot.restrict_chat_member(chat_id, user_id, ChatPermissions()) 364 | await asyncio.sleep(1) 365 | await sent.edit( 366 | f"#MUTE\n" 367 | f"USER: {mention}\n" 368 | f"TIME: `Forever`\n" 369 | f"REASON: `{reason or None}`") 370 | except Exception as e_f: # pylint: disable=broad-except 371 | await sent.edit(f"`Something went wrong 🤔`\n\n**ERROR**: `{e_f}`") 372 | 373 | 374 | @bot.on_message( 375 | filters.command("tmute") & cus_filters.auth_chats & cus_filters.auth_users) 376 | async def _tmute_user(_, msg: Message): 377 | chat_id = msg.chat.id 378 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 379 | return 380 | cmd = len(msg.text) 381 | replied = msg.reply_to_message 382 | if replied: 383 | id_ = replied.from_user.id 384 | if cmd <= 6: 385 | await msg.reply("`Time limit not found.`") 386 | return 387 | _, args = msg.text.split(maxsplit=1) 388 | elif cmd > 6: 389 | _, text = msg.text.split(maxsplit=1) 390 | if ' ' in text: 391 | id_, args = text.split(' ', maxsplit=1) 392 | else: 393 | await msg.reply("`Time limit not found.`") 394 | else: 395 | await msg.reply("`No valid User_id or message specified.`") 396 | return 397 | if ' ' in args: 398 | split = args.split(None, 1) 399 | time_val = split[0].lower() 400 | reason = split[1] 401 | else: 402 | time_val = args 403 | reason = '' 404 | 405 | time_ = await extract_time(msg, time_val) 406 | if not time_: 407 | return 408 | try: 409 | user = await bot.get_users(id_) 410 | user_id = user.id 411 | mention = user.mention 412 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 413 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 414 | return 415 | if await is_self(user_id): 416 | await sed_sticker(msg) 417 | return 418 | if is_dev(user_id): 419 | await msg.reply("`He is My Master, I will not Mute him.`") 420 | return 421 | if is_admin(chat_id, user_id): 422 | await msg.reply("`User is Admin, Can't Mute him.`") 423 | return 424 | if not await check_bot_rights(chat_id, "can_restrict_members"): 425 | await msg.reply("`Give me rights to Mute Users.`") 426 | await sed_sticker(msg) 427 | return 428 | sent = await msg.reply("`Trying to Mute User.. Hang on!! ⏳`") 429 | try: 430 | await bot.restrict_chat_member( 431 | chat_id, user_id, ChatPermissions(), time_) 432 | await asyncio.sleep(1) 433 | await sent.edit( 434 | f"#TEMP_MUTE\n" 435 | f"USER: {mention}\n" 436 | f"TIME: `{time_val}`\n" 437 | f"REASON: `{reason or None}`") 438 | except Exception as e_f: # pylint: disable=broad-except 439 | await sent.edit(f"`Something went wrong 🤔`\n\n**ERROR**: `{e_f}`") 440 | 441 | 442 | @bot.on_message( 443 | filters.command("unmute") & cus_filters.auth_chats & cus_filters.auth_users) 444 | async def _unmute_user(_, msg: Message): 445 | chat_id = msg.chat.id 446 | if not await check_rights(chat_id, msg.from_user.id, "can_restrict_members"): 447 | return 448 | replied = msg.reply_to_message 449 | if replied: 450 | id_ = replied.from_user.id 451 | elif len(msg.text) > 7: 452 | _, id_ = msg.text.split(maxsplit=1) 453 | else: 454 | await msg.reply("`No valid User_id or message specified.`") 455 | return 456 | try: 457 | user_id = (await bot.get_users(id_)).id 458 | except (UsernameInvalid, PeerIdInvalid, UserIdInvalid): 459 | await msg.reply("`Invalid user_id or username, try again with valid info ⚠`") 460 | return 461 | if await is_self(user_id): 462 | return 463 | if is_admin(chat_id, user_id): 464 | await msg.reply("`User is Admin.`") 465 | return 466 | if not await check_bot_rights(chat_id, "can_restrict_members"): 467 | await msg.reply("`Give me rights to UnMute Users.`") 468 | await sed_sticker(msg) 469 | return 470 | sent = await msg.reply("`Trying to UnMute User.. Hang on!! ⏳`") 471 | try: 472 | await bot.unban_chat_member(chat_id, user_id) 473 | await sent.edit("`🛡 Successfully Unmuted..`") 474 | except Exception as e_f: # pylint: disable=broad-except 475 | await sent.edit(f"`Something went wrong!` 🤔\n\n**ERROR:** `{e_f}`") 476 | 477 | 478 | @bot.on_message( 479 | filters.command("zombies") & cus_filters.auth_chats & cus_filters.auth_users) 480 | async def _zombie_clean(_, msg: Message): 481 | chat_id = msg.chat.id 482 | if "clean" in msg.text.lower(): 483 | del_users = 0 484 | del_admins = 0 485 | del_total = 0 486 | del_stats = r"`Zero zombie accounts found in this chat... WOOHOO group is clean.. \^o^/`" 487 | if await check_bot_rights(chat_id, "can_restrict_members"): 488 | sent = await msg.reply("`Hang on!! cleaning zombie accounts from this chat..`") 489 | async for member in bot.iter_chat_members(chat_id): 490 | if member.user.is_deleted: 491 | try: 492 | await bot.kick_chat_member( 493 | chat_id, member.user.id, int(time.time() + 45)) 494 | except UserAdminInvalid: 495 | del_users -= 1 496 | del_admins += 1 497 | except FloodWait as e_f: 498 | time.sleep(e_f.x) 499 | del_users += 1 500 | del_total += 1 501 | if del_admins > 0: 502 | del_stats = f"`👻 Found` **{del_total}** `total zombies..`\ 503 | \n`🗑 Cleaned` **{del_users}** `zombie (deleted) accounts from this chat..`\ 504 | \n🛡 **{del_admins}** `deleted admin accounts are skipped!!`" 505 | else: 506 | del_stats = f"`👻 Found` **{del_total}** `total zombies..`\ 507 | \n`🗑 Cleaned` **{del_users}** `zombie (deleted) accounts from this chat..`" 508 | await sent.edit(f"{del_stats}") 509 | else: 510 | await msg.reply("`Give me rights to clean Zombies from this group.`") 511 | await sed_sticker(msg) 512 | else: 513 | del_users = 0 514 | del_stats = r"`Zero zombie accounts found in this chat... WOOHOO group is clean.. \^o^/`" 515 | sent = await msg.reply("`🔎 Searching for zombie accounts in this chat..`") 516 | async for member in bot.iter_chat_members(chat_id): 517 | if member.user.is_deleted: 518 | del_users += 1 519 | if del_users > 0: 520 | del_stats = f"`Found` **{del_users}** `zombie accounts in this chat.`" 521 | await sent.edit( 522 | f"🕵️‍♂️ {del_stats} `you can clean them using .zombies -c`") 523 | else: 524 | await sent.edit(f"{del_stats}") 525 | 526 | 527 | @bot.on_message( 528 | filters.command("pin") & cus_filters.auth_chats & cus_filters.auth_users) 529 | async def _pin(_, msg: Message): 530 | chat_id = msg.chat.id 531 | if not await check_rights(chat_id, msg.from_user.id, "can_pin_messages"): 532 | return 533 | if not await check_bot_rights(chat_id, "can_pin_messages"): 534 | await msg.reply("`Give me Rights to Pin Msgs.`") 535 | await sed_sticker(msg) 536 | return 537 | replied = msg.reply_to_message 538 | if not replied: 539 | await msg.reply("`Reply Msg to Pin.`") 540 | return 541 | msg_id = replied.message_id 542 | if "silent" in msg.text.lower(): 543 | try: 544 | await bot.pin_chat_message( 545 | chat_id, msg_id, disable_notification=True) 546 | except Exception as e_f: # pylint: disable=broad-except 547 | await msg.reply(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 548 | else: 549 | try: 550 | await bot.pin_chat_message(chat_id, msg_id) 551 | except Exception as e_f: # pylint: disable=broad-except 552 | await msg.reply(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 553 | 554 | 555 | @bot.on_message( 556 | filters.command("unpin") & cus_filters.auth_chats & cus_filters.auth_users) 557 | async def _unpin(_, msg: Message): 558 | chat_id = msg.chat.id 559 | if not await check_rights(chat_id, msg.from_user.id, "can_pin_messages"): 560 | return 561 | if not await check_bot_rights(chat_id, "can_pin_messages"): 562 | await msg.reply("`Give me Rights to UnPin Msgs.`") 563 | await sed_sticker(msg) 564 | return 565 | try: 566 | if msg.reply_to_message: 567 | await bot.unpin_chat_message(chat_id, message.reply_to_message.message_id) 568 | else: 569 | await bot.unpin_all_chat_messages(chat_id) 570 | except Exception as e_f: # pylint: disable=broad-except 571 | await msg.reply(f"`Something went wrong! 🤔`\n\n**ERROR:** `{e_f}`") 572 | -------------------------------------------------------------------------------- /assistant/plugins/id.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import Message 11 | 12 | from assistant import bot, cus_filters 13 | 14 | 15 | @bot.on_message(filters.command("id") & cus_filters.auth_chats) 16 | async def _id(_, message: Message): 17 | msg = message.reply_to_message or message 18 | out_str = f"👥 **Chat ID** : `{(msg.forward_from_chat or msg.chat).id}`\n" 19 | out_str += f"💬 **Message ID** : `{msg.forward_from_message_id or msg.message_id}`\n" 20 | if msg.from_user: 21 | out_str += f"🙋‍♂️ **From User ID** : `{msg.from_user.id}`\n" 22 | file_id, file_unique_id = None, None 23 | if msg.audio: 24 | type_ = "audio" 25 | file_id = msg.audio.file_id 26 | file_unique_id = msg.audio.file_unique_id 27 | elif msg.animation: 28 | type_ = "animation" 29 | file_id = msg.animation.file_id 30 | file_unique_id = msg.animation.file_unique_id 31 | elif msg.document: 32 | type_ = "document" 33 | file_id = msg.document.file_id 34 | file_unique_id = msg.document.file_unique_id 35 | elif msg.photo: 36 | type_ = "photo" 37 | file_id = msg.photo.file_id 38 | file_unique_id = msg.photo.file_unique_id 39 | elif msg.sticker: 40 | type_ = "sticker" 41 | file_id = msg.sticker.file_id 42 | file_unique_id = msg.sticker.file_unique_id 43 | elif msg.voice: 44 | type_ = "voice" 45 | file_id = msg.voice.file_id 46 | file_unique_id = msg.voice.file_unique_id 47 | elif msg.video_note: 48 | type_ = "video_note" 49 | file_id = msg.video_note.file_id 50 | file_unique_id = msg.video_note.file_unique_id 51 | elif msg.video: 52 | type_ = "video" 53 | file_id = msg.video.file_id 54 | file_unique_id = msg.video.file_unique_id 55 | if (file_id and file_unique_id) is not None: 56 | out_str += f"● **Type:** `{type_}`\n" 57 | out_str += f"📄 **File ID:** `{file_id}`\n" 58 | out_str += f"📄 **File UNIQUE ID:** `{file_unique_id}`" 59 | await message.reply(out_str) 60 | -------------------------------------------------------------------------------- /assistant/plugins/inline_docs.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram.types import ( 10 | InlineQuery, InlineQueryResultArticle, InputTextMessageContent, 11 | InlineQueryResultPhoto, InlineKeyboardButton, InlineKeyboardMarkup) 12 | 13 | from assistant import bot 14 | from assistant.utils import docs 15 | 16 | 17 | @bot.on_inline_query() 18 | async def inline_docs(_, i_q: InlineQuery): 19 | query = i_q.query.lower() 20 | 21 | if query == "": 22 | await i_q.answer( 23 | results=docs.USERGE, 24 | cache_time=5, 25 | switch_pm_text="🔍 Type to search UserGe Docs", 26 | switch_pm_parameter="start", 27 | ) 28 | 29 | return 30 | results = [] 31 | if query in ["decorator", "decorators"]: 32 | results.append( 33 | InlineQueryResultArticle( 34 | title="Decorators", 35 | description="UserGe Decorators online documentation page", 36 | input_message_content=InputTextMessageContent( 37 | f"{docs.intro}" 38 | f"`Online Documentation Page for UserGe Decorators.`" 39 | ), 40 | reply_markup=InlineKeyboardMarkup([[ 41 | InlineKeyboardButton( 42 | "📚 Online docs", 43 | url=docs.decorators 44 | ) 45 | ]]), 46 | thumb_url=docs.USERGE_THUMB, 47 | ) 48 | ) 49 | 50 | for i in docs.DECORATORS: 51 | results.append( 52 | InlineQueryResultArticle( 53 | title=i[0], 54 | description=i[1], 55 | input_message_content=InputTextMessageContent( 56 | docs.intro + i[2], disable_web_page_preview=True 57 | ), 58 | thumb_url=docs.DECORATORS_THUMB 59 | ) 60 | ) 61 | elif query == "deployment": 62 | results.append( 63 | InlineQueryResultArticle( 64 | title="Deployment", 65 | description="UserGe Deployment online documentation page", 66 | input_message_content=InputTextMessageContent( 67 | f"{docs.intro}" 68 | f"`Online Documentation Page for UserGe Deployment.`" 69 | ), 70 | reply_markup=InlineKeyboardMarkup([[ 71 | InlineKeyboardButton( 72 | "📚 Online docs", 73 | url=docs.deployment 74 | ) 75 | ]]), 76 | thumb_url=docs.USERGE_THUMB, 77 | ) 78 | ) 79 | 80 | for i in docs.DEPLOYMENT: 81 | results.append( 82 | InlineQueryResultArticle( 83 | title=i[0], 84 | description=i[1], 85 | input_message_content=InputTextMessageContent( 86 | docs.intro + i[2], disable_web_page_preview=True 87 | ), 88 | thumb_url=docs.DEPLOYMENT_THUMB 89 | ) 90 | ) 91 | elif query in ["var", "vars"]: 92 | results.append( 93 | InlineQueryResultArticle( 94 | title="VARS", 95 | description="UserGe Vars online documentation page", 96 | input_message_content=InputTextMessageContent( 97 | f"{docs.intro}" 98 | f"`Online Documentation Page for UserGe Vars.`" 99 | ), 100 | reply_markup=InlineKeyboardMarkup([[ 101 | InlineKeyboardButton( 102 | "📚 Online docs", 103 | url=docs.vars 104 | ) 105 | ]]), 106 | thumb_url=docs.USERGE_THUMB, 107 | ) 108 | ) 109 | 110 | for i in docs.VARS: 111 | results.append( 112 | InlineQueryResultArticle( 113 | title=i[0], 114 | description=i[1], 115 | input_message_content=InputTextMessageContent( 116 | docs.intro + i[2], disable_web_page_preview=True 117 | ), 118 | thumb_url=docs.VARS_THUMB 119 | ) 120 | ) 121 | elif query in ["mode", "modes"]: 122 | results.append( 123 | InlineQueryResultArticle( 124 | title="UserGe Modes", 125 | description="UserGe Modes online documentation page", 126 | input_message_content=InputTextMessageContent( 127 | f"{docs.intro}" 128 | f"`Online Documentation Page for UserGe Modes.`" 129 | ), 130 | reply_markup=InlineKeyboardMarkup([[ 131 | InlineKeyboardButton( 132 | "📚 Online docs", 133 | url=docs.modes 134 | ) 135 | ]]), 136 | thumb_url=docs.USERGE_THUMB, 137 | ) 138 | ) 139 | 140 | for i in docs.MODES: 141 | results.append( 142 | InlineQueryResultArticle( 143 | title=i[0], 144 | description=i[1], 145 | input_message_content=InputTextMessageContent( 146 | docs.intro + i[2], disable_web_page_preview=True 147 | ), 148 | thumb_url=i[3] 149 | ) 150 | ) 151 | elif query in ["example", "examples"]: 152 | results.append( 153 | InlineQueryResultArticle( 154 | title="UserGe Example", 155 | description="UserGe Example-Plugins online documentation page", 156 | input_message_content=InputTextMessageContent( 157 | f"{docs.intro}" 158 | f"`Online Documentation Page for UserGe Example-Plugins.`" 159 | ), 160 | reply_markup=InlineKeyboardMarkup([[ 161 | InlineKeyboardButton( 162 | "📚 Online docs", 163 | url=docs.examples 164 | ) 165 | ]]), 166 | thumb_url=docs.USERGE_THUMB, 167 | ) 168 | ) 169 | 170 | for i in docs.EXAMPLES: 171 | results.append( 172 | InlineQueryResultArticle( 173 | title=i[0], 174 | description=i[1], 175 | input_message_content=InputTextMessageContent( 176 | docs.intro + i[2], disable_web_page_preview=True 177 | ), 178 | thumb_url=docs.EXAMPLE_THUMB 179 | ) 180 | ) 181 | elif query in ["faq", "faqs"]: 182 | results.append( 183 | InlineQueryResultArticle( 184 | title="UserGe-FAQs", 185 | description="UserGe-FAQs online documentation page", 186 | input_message_content=InputTextMessageContent( 187 | f"{docs.intro}" 188 | f"`Online Documentation Page for UserGe-FAQs.`" 189 | ), 190 | reply_markup=InlineKeyboardMarkup([[ 191 | InlineKeyboardButton( 192 | "📚 Online docs", 193 | url=docs.faqs 194 | ) 195 | ]]), 196 | thumb_url=docs.USERGE_THUMB, 197 | ) 198 | ) 199 | 200 | for i in range(len(docs.FAQS)): 201 | results.append( 202 | InlineQueryResultArticle( 203 | title=f"FAQ {i+1}", 204 | description=docs.FAQS[i][0], 205 | input_message_content=InputTextMessageContent( 206 | f"{docs.intro}**FAQ {i+1}:-**\n" 207 | f"[{docs.FAQS[i][0]}]({docs.FAQS[i][1]})", 208 | disable_web_page_preview=True 209 | ), 210 | thumb_url=docs.FAQS_THUMB 211 | ) 212 | ) 213 | elif query in ["error", "errors"]: 214 | results.append( 215 | InlineQueryResultArticle( 216 | title="Errors and their Fixes", 217 | input_message_content=InputTextMessageContent( 218 | f"{docs.intro}" 219 | f"`Online Documentation Page for UserGe-Errors.`" 220 | ), 221 | reply_markup=InlineKeyboardMarkup([[ 222 | InlineKeyboardButton( 223 | "📚 Online docs", 224 | url=docs.errors 225 | ) 226 | ]]), 227 | thumb_url=docs.ERRORS_THUMB, 228 | ) 229 | ) 230 | 231 | for i in range(len(docs.ERRORS)): 232 | results.append( 233 | InlineQueryResultPhoto( 234 | photo_url=f"{docs.ERRORS[i][2]}", 235 | title=f"{docs.ERRORS[i][0]}", 236 | caption=( 237 | "__Click On the below Button to Get the Solution.__" 238 | ), 239 | reply_markup=InlineKeyboardMarkup([[ 240 | InlineKeyboardButton( 241 | "📚 Solution", 242 | url=f"{docs.errors}{docs.ERRORS[i][1]}" 243 | ) 244 | ]]), 245 | ) 246 | ) 247 | if results: 248 | switch_pm_text = f"📖 {len(results)} Results for \"{query}\"" 249 | await i_q.answer( 250 | results=results, 251 | cache_time=5, 252 | switch_pm_text=switch_pm_text, 253 | switch_pm_parameter="start" 254 | ) 255 | else: 256 | await i_q.answer( 257 | results=[], 258 | cache_time=5, 259 | switch_pm_text=f'❌ No results for "{query}"', 260 | switch_pm_parameter="okay" 261 | ) 262 | -------------------------------------------------------------------------------- /assistant/plugins/json.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import Message 11 | 12 | from assistant import bot, cus_filters, Config 13 | 14 | 15 | @bot.on_message(filters.command("json") & cus_filters.auth_chats & cus_filters.auth_users) 16 | async def _json(_, message: Message): 17 | msg = str(message.reply_to_message) if message.reply_to_message else str(message) 18 | if len(msg) > Config.MAX_MSG_LENGTH: 19 | await message.reply("`too large !`") 20 | else: 21 | await message.reply(msg) 22 | -------------------------------------------------------------------------------- /assistant/plugins/paste.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import os 10 | 11 | import aiohttp 12 | from aiohttp import ClientResponseError, ServerTimeoutError, TooManyRedirects 13 | from assistant import Config, bot, cus_filters 14 | from pyrogram import filters 15 | from pyrogram.types import Message 16 | 17 | NEKOBIN_URL = "https://nekobin.com/" 18 | 19 | @bot.on_message(filters.command("paste") & cus_filters.auth_chats) 20 | async def nekobin_paste(_, message: Message): 21 | """ Pastes the text directly to Nekobin """ 22 | cmd = len(message.text) 23 | msg = await message.reply("`Processing...`") 24 | text = None 25 | if message.text and cmd > 6: 26 | _, args = message.text.split(maxsplit=1) 27 | text = args 28 | replied = message.reply_to_message 29 | file_ext = '.txt' 30 | if not cmd > 6 and replied and replied.document and replied.document.file_size < 2 ** 20 * 10: 31 | file_ext = os.path.splitext(replied.document.file_name)[1] 32 | path = await replied.download("downloads/") 33 | with open(path, 'r') as d_f: 34 | text = d_f.read() 35 | os.remove(path) 36 | elif not cmd > 6 and replied and replied.text: 37 | text = replied.text 38 | if not text: 39 | await msg.edit("`input not found!`") 40 | return 41 | await msg.edit("`Pasting text...`") 42 | async with aiohttp.ClientSession() as ses: 43 | async with ses.post(NEKOBIN_URL + "api/documents", json={"content": text}) as resp: 44 | if resp.status == 201: 45 | response = await resp.json() 46 | key = response['result']['key'] 47 | final_url = NEKOBIN_URL + key + file_ext 48 | reply_text = f"**Nekobin** [URL]({final_url})" 49 | await msg.edit(reply_text, disable_web_page_preview=True) 50 | else: 51 | await msg.edit("`Failed to reach Nekobin`") 52 | 53 | 54 | 55 | @bot.on_message(filters.command("getpaste") & cus_filters.auth_chats) 56 | async def get_paste_(_, message: Message): 57 | """ fetches the content of a Nekobin URL """ 58 | if message.text and len(message.text) == 9: 59 | await message.reply("`input not found!`") 60 | return 61 | _, args = message.text.split(maxsplit=1) 62 | link = args 63 | msg = await message.reply("`Getting paste content...`") 64 | if link.startswith(NEKOBIN_URL): 65 | link = link[len(NEKOBIN_URL):] 66 | raw_link = f'{NEKOBIN_URL}raw/{link}' 67 | elif link.startswith("nekobin.com/"): 68 | link = link[len("nekobin.com/"):] 69 | raw_link = f'{NEKOBIN_URL}raw/{link}' 70 | else: 71 | await msg.edit("`Is that even a paste url?`") 72 | return 73 | async with aiohttp.ClientSession(raise_for_status=True) as ses: 74 | try: 75 | async with ses.get(raw_link) as resp: 76 | text = await resp.text() 77 | except ServerTimeoutError as e_r: 78 | await msg.edit(f"`Request timed out -> {e_r}`") 79 | except TooManyRedirects as e_r: 80 | await msg.edit("`Request exceeded the configured `" 81 | f"`number of maximum redirections -> {e_r}`") 82 | except ClientResponseError as e_r: 83 | await msg.edit(f"`Request returned an unsuccessful status code -> {e_r}`") 84 | else: 85 | if len(text) > Config.MAX_MSG_LENGTH: 86 | await msg.edit("`Content Too Large...`") 87 | else: 88 | await msg.edit("--Fetched Content Successfully!--" 89 | f"\n\n**Content** :\n`{text}`") 90 | -------------------------------------------------------------------------------- /assistant/plugins/ping.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from datetime import datetime 10 | 11 | from pyrogram import filters 12 | from pyrogram.types import Message 13 | 14 | from assistant import bot, cus_filters 15 | 16 | 17 | @bot.on_message(filters.command("ping") & cus_filters.auth_chats) 18 | async def _ping(_, message: Message): 19 | start = datetime.now() 20 | replied = await message.reply('`Pong!`') 21 | end = datetime.now() 22 | m_s = (end - start).microseconds / 1000 23 | await replied.edit(f"**Pong!**\n`{m_s} ms`") 24 | -------------------------------------------------------------------------------- /assistant/plugins/reply.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import Message 11 | 12 | from assistant import bot, cus_filters 13 | 14 | 15 | @bot.on_message(filters.command("reply") & cus_filters.auth_chats & cus_filters.auth_users) 16 | async def _reply(_, message: Message): 17 | replid = message.reply_to_message 18 | if not replid: 19 | return 20 | _, text = message.text.html.split(maxsplit=1) 21 | if not text: 22 | return 23 | await message.delete() 24 | await replid.reply(f"{text.strip()}\n**cc** : {message.from_user.mention}") 25 | -------------------------------------------------------------------------------- /assistant/plugins/repo.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import ( 11 | Message, InlineKeyboardMarkup, InlineKeyboardButton) 12 | 13 | from assistant import bot, cus_filters 14 | 15 | 16 | @bot.on_message(filters.command("repo") & cus_filters.auth_chats) 17 | async def _rules(_, message: Message): 18 | replied = message.reply_to_message 19 | if replied: 20 | msg_id = replied.message_id 21 | else: 22 | msg_id = message.message_id 23 | markup = InlineKeyboardMarkup( 24 | [ 25 | [ 26 | InlineKeyboardButton( 27 | text="Official Channel", 28 | url="https://t.me/TheUserGe"), 29 | InlineKeyboardButton( 30 | text="Unofficial Help", 31 | url="https://t.me/UnofficialPluginsHelp") 32 | ], 33 | [ 34 | InlineKeyboardButton( 35 | text="Main Repo", 36 | url="https://github.com/UsergeTeam/UserGe"), 37 | InlineKeyboardButton( 38 | text="Plugins Repo", 39 | url="https://github.com/UsergeTeam/Userge-Plugins") 40 | ], 41 | [ 42 | InlineKeyboardButton( 43 | text="Tutorial", 44 | url="https://t.me/usergeot/612003") 45 | ] 46 | ] 47 | ) 48 | await bot.send_message(message.chat.id, 49 | text=("**Welcome**\n" 50 | "__Check out our channels and Repo's 🤘__"), 51 | reply_to_message_id=msg_id, 52 | reply_markup=markup) 53 | -------------------------------------------------------------------------------- /assistant/plugins/report.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import Message 11 | 12 | from assistant import bot, cus_filters, Config 13 | from assistant.utils import is_self, is_admin, is_dev 14 | 15 | 16 | @bot.on_message(filters.command("report") & cus_filters.auth_chats) 17 | async def _report(_, msg: Message): 18 | replied = msg.reply_to_message 19 | if not replied: 20 | return 21 | f_u_id = replied.from_user.id 22 | if await is_self(f_u_id) or is_dev(f_u_id) or is_admin(msg.chat.id, f_u_id): 23 | return 24 | if len(msg.text) < 9: 25 | return 26 | _, args = msg.text.split(maxsplit=1) 27 | if not args: 28 | return 29 | reason = f"**Reported User:** {replied.from_user.mention}\n" 30 | reason += f"**Reported Msg link:** {replied.link}\n" 31 | reason += f"**Reason:** `{args}`\n\n" 32 | reason += f"**Report From:** {msg.from_user.mention}" 33 | sent = await msg.reply("`Reporting ...`") 34 | for admin_id in Config.ADMINS.get(msg.chat.id): 35 | try: 36 | await bot.send_message(admin_id, reason, disable_web_page_preview=True) 37 | except Exception: # pylint: disable=broad-except 38 | pass 39 | await sent.edit("`Reported to all Admins !`") 40 | -------------------------------------------------------------------------------- /assistant/plugins/rules.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import ( 11 | Message, InlineKeyboardMarkup, InlineKeyboardButton) 12 | 13 | from assistant import bot, cus_filters 14 | 15 | 16 | @bot.on_message(filters.command("rules") & cus_filters.auth_chats) 17 | async def _rules(_, message: Message): 18 | replied = message.reply_to_message 19 | if replied: 20 | msg_id = replied.message_id 21 | else: 22 | msg_id = message.message_id 23 | markup = InlineKeyboardMarkup( 24 | [ 25 | [ 26 | InlineKeyboardButton( 27 | text="Read Rules", 28 | url="https://t.me/usergeot/537063" 29 | ) 30 | ] 31 | ] 32 | ) 33 | await bot.send_message(chat_id=message.chat.id, 34 | text="**⚠️ Here Our RULES ⚠️**", 35 | reply_to_message_id=msg_id, 36 | reply_markup=markup) 37 | -------------------------------------------------------------------------------- /assistant/plugins/start.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram import filters 10 | from pyrogram.types import ( 11 | Message, InlineKeyboardMarkup, InlineKeyboardButton) 12 | 13 | from assistant import bot 14 | from assistant.utils.docs import HELP 15 | 16 | 17 | @bot.on_message(filters.private) 18 | async def _start_(_, msg: Message): 19 | await msg.reply( 20 | HELP, 21 | disable_web_page_preview=True, 22 | parse_mode="markdown", 23 | reply_markup=InlineKeyboardMarkup([[ 24 | InlineKeyboardButton( 25 | "🗂 Source Code", 26 | url="https://github.com/UserGeTeam/UserGe-Assistant" 27 | ), 28 | InlineKeyboardButton( 29 | "😎 Use Inline!", 30 | switch_inline_query="" 31 | ) 32 | ]]) 33 | ) 34 | -------------------------------------------------------------------------------- /assistant/plugins/verify_new_members.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import asyncio 10 | 11 | from pyrogram import filters 12 | from pyrogram.types import ( 13 | Message, ChatPermissions, CallbackQuery, 14 | InlineKeyboardMarkup, InlineKeyboardButton) 15 | from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant 16 | 17 | from assistant import bot, cus_filters 18 | from assistant.utils import check_bot_rights 19 | 20 | 21 | @bot.on_message( 22 | filters.group & filters.new_chat_members & cus_filters.auth_chats) 23 | async def _verify_msg_(_, msg: Message): 24 | """ Verify Msg for New chat Members """ 25 | chat_id = msg.chat.id 26 | for member in msg.new_chat_members: 27 | try: 28 | user_status = (await msg.chat.get_member(member.id)).status 29 | if user_status in ("restricted", "kicked"): 30 | continue 31 | except Exception: 32 | pass 33 | if member.is_bot or not await check_bot_rights(chat_id, "can_restrict_members"): 34 | file_id, text, buttons = await wc_msg(member) 35 | reply = await msg.reply_animation( 36 | animation=file_id, 37 | caption=text, 38 | reply_markup=buttons 39 | ) 40 | await asyncio.sleep(120) 41 | await reply.delete() 42 | else: 43 | await bot.restrict_chat_member(chat_id, member.id, ChatPermissions()) 44 | try: 45 | await bot.get_chat_member("TheUserGe", member.id) 46 | except UserNotParticipant: 47 | await force_sub(msg, member) 48 | else: 49 | await verify_keyboard(msg, member) 50 | msg.continue_propagation() 51 | 52 | 53 | async def verify_keyboard(msg: Message, user): 54 | """ keyboard for verifying """ 55 | _msg = f""" Hi {user.mention}, Welcome to {msg.chat.title}. 56 | To Chat here, Please click on the button below. """ 57 | button = InlineKeyboardMarkup( 58 | [ 59 | [ 60 | InlineKeyboardButton( 61 | text="Verify now 🤖", 62 | callback_data=f"verify_cq({user.id} {msg.message_id})") 63 | ] 64 | ] 65 | ) 66 | await msg.reply_text(_msg, reply_markup=button) 67 | 68 | 69 | async def force_sub(msg: Message, user): 70 | """ keyboard for force user to join channel """ 71 | _msg = f""" Hi {user.mention}, Welcome to {msg.chat.title}. 72 | Seems that you haven't join our Updates Channel. 73 | __Click on Join Now and Unmute yourself.__ """ 74 | button = InlineKeyboardMarkup( 75 | [ 76 | [ 77 | InlineKeyboardButton( 78 | text="Join Now", 79 | url="https://t.me/TheUserGe"), 80 | InlineKeyboardButton( 81 | text="Unmute Me", 82 | callback_data=f"joined_unmute({user.id} {msg.message_id})") 83 | ] 84 | ] 85 | ) 86 | await msg.reply_text(_msg, reply_markup=button) 87 | 88 | 89 | async def wc_msg(user): 90 | """ arguments and reply_markup for sending after verify """ 91 | gif = await bot.get_messages("UserGeOt", 510608) 92 | file_id = gif.animation.file_id 93 | text = f""" **Welcome** {user.mention}, 94 | __Check out the Button below. and feel free to ask here.__ 🤘 """ 95 | buttons = InlineKeyboardMarkup( 96 | [ 97 | [ 98 | InlineKeyboardButton( 99 | text="More info.", 100 | url="https://t.me/usergeot/637843" 101 | ) 102 | ] 103 | ] 104 | ) 105 | return file_id, text, buttons 106 | 107 | 108 | @bot.on_callback_query(filters.regex(pattern=r"verify_cq\((.+?)\)")) 109 | async def _verify_user_(_, c_q: CallbackQuery): 110 | _a, _b = c_q.matches[0].group(1).split(' ', maxsplit=1) 111 | user_id = int(_a) 112 | msg_id = int(_b) 113 | if c_q.from_user.id == user_id: 114 | await c_q.message.delete() 115 | await bot.unban_chat_member(c_q.message.chat.id, user_id) 116 | file_id, text, buttons = await wc_msg(await bot.get_users(user_id)) 117 | msg = await bot.send_animation( 118 | c_q.message.chat.id, 119 | animation=file_id, 120 | caption=text, reply_markup=buttons, 121 | reply_to_message_id=msg_id 122 | ) 123 | await asyncio.sleep(120) 124 | await msg.delete() 125 | else: 126 | await c_q.answer("This message is not for you. 😐", show_alert=True) 127 | 128 | 129 | @bot.on_callback_query(filters.regex(pattern=r"joined_unmute\((.+?)\)")) 130 | async def _on_joined_unmute_(_, c_q: CallbackQuery): 131 | if not c_q.message.chat: 132 | return 133 | _a, _b = c_q.matches[0].group(1).split(' ', maxsplit=1) 134 | user_id = int(_a) 135 | msg_id = int(_b) 136 | bot_id = (await bot.get_me()).id 137 | chat_id = c_q.message.chat.id 138 | 139 | user = await bot.get_users(user_id) 140 | 141 | if c_q.from_user.id == user_id: 142 | get_user = await bot.get_chat_member(chat_id, user_id) 143 | if get_user.restricted_by and get_user.restricted_by.id == bot_id: 144 | try: 145 | await bot.get_chat_member("TheUserGe", user_id) 146 | except UserNotParticipant: 147 | await c_q.answer( 148 | "Click on Join Now button to Join our Updates Channel" 149 | " and click on Unmute me Button again.", show_alert=True) 150 | else: 151 | await c_q.message.delete() 152 | await bot.unban_chat_member(c_q.message.chat.id, user_id) 153 | f_d, txt, btns = await wc_msg(user) 154 | msg = await bot.send_animation( 155 | c_q.message.chat.id, 156 | animation=f_d, 157 | caption=txt, reply_markup=btns, 158 | reply_to_message_id=msg_id 159 | ) 160 | await asyncio.sleep(120) 161 | await msg.delete() 162 | else: 163 | await c_q.answer( 164 | "Admins Muted you for another reason, I Can't unmute you.", 165 | show_alert=True) 166 | else: 167 | await c_q.answer( 168 | f"This Message is Only for {user.first_name}", show_alert=True) 169 | -------------------------------------------------------------------------------- /assistant/plugins/warn.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import time 10 | import json 11 | 12 | from pyrogram import filters 13 | from pyrogram.types import ( 14 | Message, CallbackQuery, ChatPermissions, 15 | InlineKeyboardMarkup, InlineKeyboardButton) 16 | 17 | from assistant import bot, cus_filters, DB, save_data, load_data 18 | from assistant.utils import is_admin, is_dev, is_self, sed_sticker 19 | 20 | 21 | async def warn(msg: Message, chat_id: int, user_id: int, reason: str = "None"): 22 | replied = msg.reply_to_message or msg 23 | mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})" 24 | 25 | w_lt = await load_data(DB.WARN_LIMIT_ID) 26 | w_me = await load_data(DB.WARN_MODE_ID) 27 | DATA = await load_data(DB.WARN_DATA_ID) 28 | 29 | if not DATA.get(str(chat_id)): 30 | DATA[str(chat_id)] = {} 31 | if not ( 32 | w_lt.get(str(chat_id)) or w_me.get(str(chat_id)) 33 | ): 34 | w_lt[str(chat_id)] = 3 35 | w_me[str(chat_id)] = "ban" 36 | w_l = w_lt.get(str(chat_id)) 37 | w_m = w_me.get(str(chat_id)) 38 | if not DATA[str(chat_id)].get(str(user_id)): 39 | w_d = { 40 | 'limit': 1, 41 | 'reason': [reason] 42 | } 43 | DATA[str(chat_id)][str(user_id)] = w_d # warning data 44 | keyboard = InlineKeyboardMarkup( 45 | [ 46 | [ 47 | InlineKeyboardButton( 48 | "Remove Warn", 49 | callback_data=f"rm_warn({user_id})") 50 | ] 51 | ] 52 | ) 53 | reply_text = f"**#Warned**\n{mention} `has 1/{w_l} warnings.`\n" 54 | reply_text += f"**Reason:** `{reason}`" 55 | await replied.reply_text(reply_text, reply_markup=keyboard) 56 | else: 57 | p_l = DATA[str(chat_id)][str(user_id)]['limit'] # previous limit 58 | nw_l = p_l + 1 # new limit 59 | if nw_l >= w_l: 60 | if w_m == "ban": 61 | await bot.kick_chat_member(chat_id, user_id) 62 | exec_str = 'BANNED' 63 | elif w_m == "kick": 64 | await bot.kick_chat_member( 65 | chat_id, user_id, time.time() + 300) 66 | exec_str = 'KICKED' 67 | else: 68 | await bot.restrict_chat_member( 69 | chat_id, user_id, ChatPermissions()) 70 | exec_str = 'MUTED' 71 | reasons = ('\n'.join(DATA[str(chat_id)][str(user_id)]['reason']) + '\n' + str(reason)) 72 | await msg.reply( 73 | f"**#WARNED_{exec_str}**\n" 74 | f"**{exec_str} User:** {mention}\n" 75 | f"**Warn Counts:** `{nw_l}/{w_l} Warnings`\n" 76 | f"**Reason:** `{reasons}`") 77 | DATA[str(chat_id)].pop(str(user_id)) 78 | 79 | else: 80 | DATA[str(chat_id)][str(user_id)]['limit'] = nw_l 81 | DATA[str(chat_id)][str(user_id)]['reason'].append(reason) 82 | keyboard = InlineKeyboardMarkup( 83 | [ 84 | [ 85 | InlineKeyboardButton( 86 | "Remove Warn", 87 | callback_data=f"rm_warn({user_id})") 88 | ] 89 | ] 90 | ) 91 | r_t = f"**#Warned**\n{mention} `has {nw_l}/{w_l} warnings.`\n" 92 | r_t += f"**Reason:** `{reason}`" # r_t = reply text 93 | await replied.reply_text(r_t, reply_markup=keyboard) 94 | await save_data(DB.WARN_DATA_ID, json.dumps(DATA)) 95 | await save_data(DB.WARN_MODE_ID, json.dumps(w_me)) 96 | await save_data(DB.WARN_LIMIT_ID, json.dumps(w_lt)) 97 | 98 | 99 | @bot.on_message( 100 | filters.command("warn") & cus_filters.auth_chats & cus_filters.auth_users) 101 | async def _warn_user(_, msg: Message): 102 | replied = msg.reply_to_message 103 | if not replied: 104 | return 105 | chat_id = msg.chat.id 106 | user_id = replied.from_user.id 107 | if is_dev(user_id): 108 | await msg.reply("`He is My Master, Can't Warn him.`") 109 | return 110 | if await is_self(user_id): 111 | await sed_sticker(msg) 112 | return 113 | if is_admin(chat_id, user_id): 114 | await msg.reply("`User is Admin, Can't Warn him.`") 115 | return 116 | cmd = len(msg.text) 117 | reason = None 118 | if msg.text and cmd > 5: 119 | _, reason = msg.text.split(maxsplit=1) 120 | await warn(msg, chat_id, user_id, reason) 121 | 122 | 123 | @bot.on_callback_query(filters.regex(pattern=r"rm_warn\((.+?)\)")) 124 | async def remove_warn(_, c_q: CallbackQuery): 125 | user_id = str(c_q.matches[0].group(1)) 126 | DATA = await load_data(DB.WARN_DATA_ID) 127 | if is_admin(c_q.message.chat.id, c_q.from_user.id, check_devs=True): 128 | if DATA.get(str(c_q.message.chat.id)) is None: 129 | await c_q.edit_message_text( 130 | "This User already not have any Warn.") 131 | return 132 | if DATA[str(c_q.message.chat.id)].get(user_id): 133 | up_l = DATA[str(c_q.message.chat.id)][user_id]['limit'] - 1 # up_l = updated limit 134 | if up_l > 0: 135 | DATA[str(c_q.message.chat.id)][user_id]['limit'] = up_l 136 | del DATA[str(c_q.message.chat.id)][user_id]['reason'][-1] 137 | else: 138 | DATA[str(c_q.message.chat.id)].pop(user_id) 139 | await save_data(DB.WARN_DATA_ID, json.dumps(DATA)) 140 | text = f"[{c_q.from_user.first_name}](tg://user?id={c_q.from_user.id})" 141 | text += " `removed this Warn.`" 142 | await c_q.edit_message_text(text) 143 | else: 144 | await c_q.edit_message_text( 145 | "This User already not have any Warn.") 146 | else: 147 | await c_q.answer( 148 | "Only Admins can remove this Warn", show_alert=True) 149 | 150 | 151 | @bot.on_message( 152 | filters.command("setwarn") & cus_filters.auth_chats & cus_filters.auth_users) 153 | async def _set_warn_mode_and_limit(_, msg: Message): 154 | chat_id = str(msg.chat.id) 155 | cmd = len(msg.text) 156 | if msg.text and cmd == 8: 157 | await msg.reply("`Input not found!`") 158 | return 159 | _, args = msg.text.split(maxsplit=1) 160 | WARN_MODE = await load_data(DB.WARN_MODE_ID) 161 | WARN_LIMIT = await load_data(DB.WARN_LIMIT_ID) 162 | _MODE = {chat_id: 'ban'} 163 | _LIMIT = {chat_id: 3} 164 | if 'ban' in args.lower(): 165 | _MODE = {chat_id: 'ban'} 166 | await msg.reply("`Warning Mode Updated to Ban`") 167 | elif 'kick' in args.lower(): 168 | _MODE = {chat_id: 'kick'} 169 | await msg.reply("`Warning Mode Updated to Kick`") 170 | elif 'mute' in args.lower(): 171 | _MODE = {chat_id: 'mute'} 172 | await msg.reply("`Warning Mode Updated to Mute`") 173 | elif args[0].isnumeric(): 174 | input_ = int(args[0]) 175 | if input_ < 3: 176 | await msg.reply("`Can't Warn Limit less then 3`") 177 | return 178 | _LIMIT = {chat_id: input_} 179 | await msg.reply(f"`Warn limit Updated to {input_} Warns.`") 180 | else: 181 | await msg.reply("`invalid arguments, exiting...`") 182 | WARN_MODE.update(_MODE) 183 | WARN_LIMIT.update(_LIMIT) 184 | await save_data(DB.WARN_MODE_ID, json.dumps(WARN_MODE)) 185 | await save_data(DB.WARN_LIMIT_ID, json.dumps(WARN_LIMIT)) 186 | 187 | 188 | @bot.on_message( 189 | filters.command("resetwarn") & cus_filters.auth_chats & cus_filters.auth_users) 190 | async def _reset_all_warns(_, msg: Message): 191 | replied = msg.reply_to_message 192 | if not replied: 193 | return 194 | user_id = replied.from_user.id 195 | if is_dev(user_id): 196 | await msg.reply("`He is My Master, I never Warned him.`") 197 | return 198 | if await is_self(user_id): 199 | return 200 | if is_admin(msg.chat.id, user_id): 201 | await msg.reply("`He is admin, I never Warned him.`") 202 | return 203 | DATA = await load_data(DB.WARN_DATA_ID) 204 | if DATA.get(str(msg.chat.id)) is None: 205 | await msg.reply("`User already not have any warn.`") 206 | return 207 | if DATA[str(msg.chat.id)].get(str(user_id)): 208 | DATA[str(msg.chat.id)].pop(str(user_id)) 209 | await save_data(DB.WARN_DATA_ID, json.dumps(DATA)) 210 | await msg.reply("`All Warns are removed for this User.`") 211 | else: 212 | await msg.reply("`User already not have any warn.`") 213 | 214 | 215 | @bot.on_message(filters.command("warns") & cus_filters.auth_chats) 216 | async def _check_warns_of_user(_, msg: Message): 217 | replied = msg.reply_to_message 218 | if replied: 219 | user_id = str(replied.from_user.id) 220 | mention = f"[{replied.from_user.first_name}](tg://user?id={user_id})" 221 | else: 222 | user_id = str(msg.from_user.id) 223 | mention = f"[{msg.from_user.first_name}](tg://user?id={user_id})" 224 | if is_dev(int(user_id)): 225 | await msg.reply("`He is My Master, I never Warned him.`") 226 | return 227 | if await is_self(int(user_id)): 228 | return 229 | if is_admin(msg.chat.id, int(user_id)): 230 | await msg.reply("`He is admin, I never Warned him.`") 231 | return 232 | if replied and not is_admin(msg.chat.id, msg.from_user.id, check_devs=True): 233 | await msg.reply("`You can only see your Warnings.`") 234 | return 235 | DATA = await load_data(DB.WARN_DATA_ID) 236 | w_l = (await load_data(DB.WARN_LIMIT_ID)).get(str(msg.chat.id)) 237 | if DATA.get(str(msg.chat.id)) is None: 238 | await msg.reply("`Warnings not Found.`") 239 | return 240 | 241 | if DATA[str(msg.chat.id)].get(user_id): 242 | w_c = DATA[str(msg.chat.id)][user_id]['limit'] # warn counts 243 | reason = '\n'.join(DATA[str(msg.chat.id)][user_id]['reason']) 244 | reply_msg = ( 245 | "**#WARNINGS**\n" 246 | f"**User:** {mention}\n" 247 | f"**Warn Counts:** `{w_c}/{w_l} Warnings.`\n" 248 | f"**Reason:** `{reason}`") 249 | await msg.reply(reply_msg) 250 | else: 251 | await msg.reply("`Warnings not Found.`") 252 | -------------------------------------------------------------------------------- /assistant/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from .tools import ( # noqa 10 | is_admin, is_dev, is_self, 11 | check_rights, check_bot_rights, 12 | sed_sticker, time_formatter, extract_time) 13 | -------------------------------------------------------------------------------- /assistant/utils/docs.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | from pyrogram.types import ( 10 | InlineQueryResultArticle, InputTextMessageContent, 11 | InlineKeyboardMarkup, InlineKeyboardButton) 12 | 13 | intro = "**📚 UserGe Docs**\n\n" 14 | 15 | USERGE_THUMB = "https://imgur.com/download/Inyeb1S" 16 | USER_THUMB = "https://i.imgur.com/h6ZyB71.png" 17 | BOT_THUMB = "https://i.imgur.com/zRglRz3.png" 18 | DUAL_THUMB = "https://i.imgur.com/ZTcIANz.png" 19 | CONTENT_THUMB = "https://i.imgur.com/v1XSJ1D.png" 20 | REPO_THUMB = "https://i.imgur.com/hoRVXM3.png" 21 | GC_THUMB = "https://i.imgur.com/lDpSgmg_d.png" 22 | 23 | DECORATORS_THUMB = "https://i.imgur.com/xp3jld1.png" 24 | DEPLOYMENT_THUMB = "https://i.imgur.com/S5lY8fy.png" 25 | VARS_THUMB = "https://i.imgur.com/dw1lLBX.png" 26 | EXAMPLE_THUMB = "https://i.imgur.com/NY4uasQ.png" 27 | FAQS_THUMB = "https://i.imgur.com/b33rM21.png" 28 | ERRORS_THUMB = "https://i.imgur.com/hv2r4nm.png" 29 | 30 | userge_wiki = "https://theuserge.github.io/" 31 | decorators = "https://theuserge.github.io/decorators.html" 32 | deployment = "https://theuserge.github.io/deployment.html" 33 | vars = f"{deployment}#list-of-available-vars" 34 | modes = f"{deployment}#userge-modes" 35 | examples = "https://theuserge.github.io/examples.html" 36 | faqs = "https://theuserge.github.io/faq.html" 37 | errors = "https://theuserge.github.io/errors.html" 38 | 39 | HELP = ( 40 | "🤖 **UserGe Assistant**\n\n" 41 | 42 | 43 | "You can use this bot in inline mode to search for UserGe Docs and FAQs" 44 | f" and All Methods available in [UserGe Docs]({userge_wiki}).\n\n" 45 | 46 | "**__Search__**\n" 47 | "`@UsergeBot `\n\n" 48 | 49 | "**__List of Queries__**\n" 50 | "`Decorators`\n" 51 | "`Deployment`\n" 52 | "`Vars`\n" 53 | "`Modes`\n" 54 | "`Example`\n" 55 | "`Faqs`\n" 56 | "`Errors`" 57 | ) 58 | 59 | USERGE = [ 60 | InlineQueryResultArticle( 61 | title="About UserGe", 62 | input_message_content=InputTextMessageContent( 63 | "**👑 UserGe**\n\n" 64 | "**[UserGe](https://github.com/usergeteam/userge) **" 65 | "**is a Powerful , Pluggable Telegram UserBot written in **" 66 | "**[Python](https://www.python.org/) using **" 67 | "**[Pyrogram](https://github.com/pyrogram).**", 68 | disable_web_page_preview=True 69 | ), 70 | reply_markup=InlineKeyboardMarkup( 71 | [ 72 | [ 73 | InlineKeyboardButton("👥 Community", url="https://t.me/UserGeOt") 74 | ], 75 | [ 76 | InlineKeyboardButton("🗂 GitHub", url="https://github.com/UserGeTeam/UserGe"), 77 | InlineKeyboardButton("📂 Docs", url=f"{userge_wiki}") 78 | ] 79 | ] 80 | ), 81 | description="UserGe is a Powerful , Pluggable Telegram UserBot.", 82 | thumb_url=USERGE_THUMB 83 | ), 84 | InlineQueryResultArticle( 85 | title="About UserGe Assistant", 86 | input_message_content=InputTextMessageContent( 87 | HELP, disable_web_page_preview=True, parse_mode="markdown" 88 | ), 89 | reply_markup=InlineKeyboardMarkup([[ 90 | InlineKeyboardButton( 91 | "🗂 Source Code", 92 | url="https://github.com/UserGeTeam/UserGe-Assistant" 93 | ), 94 | InlineKeyboardButton( 95 | "😎 Use Inline!", 96 | switch_inline_query="" 97 | ) 98 | ]]), 99 | description="How to use UserGe Assistant Bot.", 100 | thumb_url=BOT_THUMB, 101 | ), 102 | InlineQueryResultArticle( 103 | title="Quick Links", 104 | input_message_content=InputTextMessageContent( 105 | "📚 **UserGe Docs**\n\n" 106 | "`Quick Links.`", 107 | disable_web_page_preview=True, 108 | ), 109 | reply_markup=InlineKeyboardMarkup([[ 110 | InlineKeyboardButton( 111 | "Online Docs 📚", url=f"{userge_wiki}#quick-links" 112 | ) 113 | ]]), 114 | description="See Contents available in UserGe wiki.", 115 | thumb_url=CONTENT_THUMB 116 | ), 117 | InlineQueryResultArticle( 118 | title="UserGe-Repository", 119 | input_message_content=InputTextMessageContent( 120 | "📚 **UserGe Docs**\n\n" 121 | "`UserGe-Repositories.`", 122 | disable_web_page_preview=True, 123 | ), 124 | reply_markup=InlineKeyboardMarkup([[ 125 | InlineKeyboardButton( 126 | "Github 🗂", url=f"{userge_wiki}" 127 | ) 128 | ]]), 129 | description="All UserGe-Repositories.", 130 | thumb_url=REPO_THUMB 131 | ), 132 | InlineQueryResultArticle( 133 | title="Groups and Channels", 134 | input_message_content=InputTextMessageContent( 135 | "📚 **UserGe Docs**\n\n" 136 | "`Join Our Updates Channel and Support Group.`", 137 | disable_web_page_preview=True, 138 | ), 139 | reply_markup=InlineKeyboardMarkup([[ 140 | InlineKeyboardButton( 141 | "Groups and Channels 👥", 142 | url=f"{userge_wiki}" 143 | ) 144 | ]]), 145 | description="Join UserGe support Group and Updates Channel.", 146 | thumb_url=GC_THUMB 147 | ) 148 | ] 149 | 150 | DECORATORS = [ 151 | ( 152 | "UserGe Callback Decorators.", 153 | "Userge have it's own custom decorators.", 154 | f"[UserGe Callback Decorators.]({decorators}#userge-callback-decorators)" 155 | ), 156 | ( 157 | "Parameters", 158 | "Required and Non-required Parameters of Decorators.", 159 | f"[Parameters]({decorators}#parameters)" 160 | ), 161 | ( 162 | "Examples", 163 | "Example of Decorators.", 164 | f"[Example of Decorators]({decorators}#examples)" 165 | ) 166 | ] 167 | 168 | DEPLOYMENT = [ 169 | ( 170 | "Config Vars.", 171 | "About Config Vars and Explanation.", 172 | f"[Config Vars]({deployment}#config-vars--setting-up-vars)" 173 | ), 174 | ( 175 | "Branches", 176 | "Check available Branches in UserGe repo.", 177 | f"[Branches]({deployment}#steps-to-deploy)" 178 | ), 179 | ( 180 | "Deploy to Heroku", 181 | "Directly Deploy to Heroku.", 182 | f"[Deploy to Heroku]({deployment}#deploying-with-heroku)" 183 | ), 184 | ( 185 | "Deploy with termux", 186 | "Deploy UserGe with Termux.", 187 | f"[Deploy with Termux](https://theuserge.github.io/termux.html)" 188 | ), 189 | ( 190 | "Deploying with Docker", 191 | "Deploy UserGe using Docker.", 192 | f"[Deploy with Docker]({deployment}#deploying-with-docker-)" 193 | ), 194 | ( 195 | "Deploying with Legacy Method", 196 | "Deploying UserGe with Legacy Method.", 197 | f"[Deploying with Legacy Method]({deployment}#deploying-with-legacy-method)" 198 | ) 199 | ] 200 | 201 | ERRORS = [ 202 | ( 203 | "description : Bad request : chat not found", 204 | "#1-description--bad-request--chat-not-found", 205 | "https://telegra.ph/file/1b707364fd2bb0e6a3805.jpg" 206 | ), 207 | ( 208 | "ERROR :: Required Command : jq : could not be found !", 209 | "#2-error--required-command--jq--could-not-be-found-", 210 | "https://telegra.ph/file/28e9365af63d3b509f501.jpg" 211 | ), 212 | ( 213 | "'fatal: bad revision 'HEAD...upstream/master'", 214 | "#3-fatal-bad-revision-headupstreammaster", 215 | "https://telegra.ph/file/aeda709f622f34ae3802d.jpg" 216 | ), 217 | ( 218 | "Error R14 (memory quota exceeded)", 219 | "#4-error-r14-memory-quota-exceeded", 220 | "https://telegra.ph/file/d5f90faff504b334e541f.jpg" 221 | ), 222 | ( 223 | "GitCommandError", 224 | "#5-gitcommanderror", 225 | "https://telegra.ph/file/1a286bbd6284f71abfed4.jpg" 226 | ) 227 | ] 228 | 229 | VARS = [ 230 | ( 231 | "Api Id and Api hash", 232 | "How to get Api Id and Api hash", 233 | f"[API_ID and API_HASH]({deployment}#1-api_id-and-api_hash)" 234 | ), 235 | ( 236 | "Database Url", 237 | "How to get Database Url", 238 | f"[DATABASE_URL]({deployment}#2-database_url)" 239 | ), 240 | ( 241 | "Log Channel Id", 242 | "How to get Log Channel Id", 243 | f"[LOG_CHANNEL_ID]({deployment}#3-log_channel_id)" 244 | ), 245 | ( 246 | "Load Unofficial Plugins", 247 | "How to Load Unofficial Plugins.", 248 | f"[LOAD_UNOFFICIAL_PLUGINS]({deployment}#1-load_unofficial_plugins)" 249 | ), 250 | ( 251 | "Custom Plugins Repo", 252 | "Add custom plugins repo", 253 | f"[CUSTOM_PLUGINS_REPO]({deployment}#2-custom_plugins_repo)" 254 | ), 255 | ( 256 | "Assert single instance", 257 | "What is assert single instance", 258 | f"[ASSERT_SINGLE_INSTANCE]({deployment}#3-assert_single_instance)" 259 | ), 260 | ( 261 | "Workers", 262 | "Explained Workers Var", 263 | f"[WORKERS]({deployment}#4-workers)" 264 | ), 265 | ( 266 | "Rss chat id", 267 | "What is rss chat id", 268 | f"[RSS_CHAT_ID]({deployment}#5-rss_chat_id)" 269 | ), 270 | ( 271 | "Gdrive Client Id and Client Secret", 272 | "How to get G_DRIVE_CLIENT_ID and G_DRIVE_CLIENT_SECRET", 273 | f"[G_DRIVE_CLIENT_ID and G_DRIVE_CLIENT_SECRET]({deployment}#6-g_drive_client_id--g_drive_client_secret)" 274 | ), 275 | ( 276 | "G_DRIVE_ID_TD", 277 | "Explained G_DRIVE_IS_TD", 278 | f"[G_DRIVE_IS_TD]({deployment}#7-g_drive_is_td)" 279 | ), 280 | ( 281 | "G_DRIVE_INDEX_LINK", 282 | "How to get Index Link", 283 | f"[G_DRIVE_INDEX_LINK]({deployment}#8-g_drive_index_link)" 284 | ), 285 | ( 286 | "Down Path", 287 | "Explained about Download Path", 288 | f"[DOWN_PATH]({deployment}#9-down_path)" 289 | ), 290 | ( 291 | "Preferred Language", 292 | "Explained Preferred Language", 293 | f"[PREFERRED_LANGUAGE]({deployment}#10-preferred_language)" 294 | ), 295 | ( 296 | "Currency Api", 297 | "How to get Currency Api", 298 | f"[CURRENCY_API]({deployment}#11-currency_api)" 299 | ), 300 | ( 301 | "Ocr Space Api Key", 302 | "How to get Ocr Space Pai Key.", 303 | f"[OCR_SPACE_API_KEY]({deployment}#12-next-var-is-ocr_space_api_key)" 304 | ), 305 | ( 306 | "Weather Defcity", 307 | "Weather Default City.", 308 | f"[WEATHER_DEFCITY]({deployment}#13-weather_defcity)" 309 | ), 310 | ( 311 | "Userge antispam api", 312 | "What is userge antispam api", 313 | f"[USERGE_ANTISPAM_API]({deployment}#14-userge_antispam_api)" 314 | ), 315 | ( 316 | "Spamwatch Api", 317 | "How to get SpamWatch Api.", 318 | f"[SPAM_WATCH_API]({deployment}#15-spam_watch_api)" 319 | ), 320 | ( 321 | "Open Weather Map", 322 | "How to get Open Weather Map.", 323 | f"[OEPN_WEATHER_MAP]({deployment}#16-open_weather_map)" 324 | ), 325 | ( 326 | "Remove Background Api", 327 | "How to get Remove Background Api.", 328 | f"[REMOVE_BG_API_KEY]({deployment}#17-remove_bg_api_key)" 329 | ), 330 | ( 331 | "Gdrive Parent folder Id", 332 | "How to get Gdrive Parent folder Id", 333 | f"[G_DRIVE_PARENT_ID]({deployment}#18-g_drive_parent_id)" 334 | ), 335 | ( 336 | "Command Trigger", 337 | "What is Command Trigger.", 338 | f"[CMD_TRIGGER]({deployment}#19-cmd_trigger)" 339 | ), 340 | ( 341 | "Sudo Trigger", 342 | "What is Sudo Trigger.", 343 | f"[SUDO_TRIGGER]({deployment}#20-sudo_trigger)" 344 | ), 345 | ( 346 | "Upstream Repo", 347 | "What is Upstream Repo", 348 | f"[UPSTREAM_REPO]({deployment}#21-upstream_repo)" 349 | ), 350 | ( 351 | "Finished Progress Bar", 352 | "What is Finished Progress Bar.", 353 | f"[FINISHED_PROGRESS_STR]({deployment}#22-finished_progress_str)" 354 | ), 355 | ( 356 | "UnFinished Progress Bar", 357 | "What is UnFinished Progress Bar.", 358 | f"[UNFINISHED_PROGRESS_STR]({deployment}#23-unfinished_progress_str)" 359 | ), 360 | ( 361 | "Custom Pack Name", 362 | "What is Custom Pack Name.", 363 | f"[CUSTOM_PACK_NAME]({deployment}#24-custom_pack_name)" 364 | ), 365 | ( 366 | "Alive Media", 367 | "How to get Alive Media var.", 368 | f"[ALIVE_MEDIA]({deployment}#25-alive_media)" 369 | ), 370 | ( 371 | "Heroku Api Key", 372 | "How to get Heroku Api Key", 373 | f"[HEROKU_API_KEY]({deployment}#26-heroku_api_key)" 374 | ), 375 | ( 376 | "Heroku App Name", 377 | "How to get Heroku App Name", 378 | f"[HEROKU_APP_NAME]({deployment}#27-heroku_app_name)" 379 | ), 380 | ( 381 | "Max duration", 382 | "What is max duration", 383 | f"[MAX_DURATION]({deployment}#28-max_duration)" 384 | ), 385 | ( 386 | "Heroku Session String", 387 | "How to get Heroku Session String", 388 | f"[HU_STRING_SESSION]({deployment}#1-user-mode)" 389 | ), 390 | ( 391 | "Plugin Channel ID.", 392 | "How to Add/Load Custom Plugins?", 393 | f"[PLUGINS_CHANNEL_ID]({faqs}#26-how-to-addload-custom-plugins)" 394 | ), 395 | ] 396 | 397 | MODES = [ 398 | ( 399 | "User Mode", 400 | "Explained Docs for User Mode.", 401 | f"[What is User Mode?]({deployment}#1-user-mode)", 402 | f"{USER_THUMB}" 403 | ), 404 | ( 405 | "Bot Mode", 406 | "Explained Docs for Bot Mode.", 407 | f"[What is Bot Mode?]({deployment}#2-bot-mode)", 408 | f"{BOT_THUMB}" 409 | ), 410 | ( 411 | "Dual Mode", 412 | "Explained Docs for Dual Mode.", 413 | f"[What is Dual Mode?]({deployment}#3-dual-mode)", 414 | f"{DUAL_THUMB}" 415 | ) 416 | ] 417 | 418 | EXAMPLES = [ 419 | ( 420 | "Cmd Example", 421 | "Explained Docs for Cmd Example.", 422 | f"[Example Cmd]({deployment}#example-command)" 423 | ), 424 | ( 425 | "Filter Example", 426 | "Explained Docs for Filter Example.", 427 | f"[Example Filters]({deployment}#example-filter)" 428 | ) 429 | ] 430 | 431 | FAQS = [ 432 | ("How to Setup userge?", f"{faqs}#1-how-to-setup-userge"), 433 | ("How to Add unofficial plugins?", 434 | f"{faqs}#2-how-to-add-unofficial-plugins"), 435 | ("How to genrate String Session?", f"{faqs}#3-how-to-generate-string-session-"), 436 | ("How to get all cmd list?", f"{faqs}#4-how-to-get-all-commands-list"), 437 | ("How to use a cmd?", f"{faqs}#5-how-to-use-a-command"), 438 | ("What is sudo and how to enable it?", f"{faqs}#6-what-is-sudo-how-to-enable-it"), 439 | ("How to Setup Google Drive and GDrive Parent Id?", 440 | f"{faqs}#7-how-to-setup-google-drive-how-to-setup-gdrive-parent-id"), 441 | ("What is bot mode and how to enable bot mode?", 442 | f"{faqs}#8-what-is-bot-mode-how-to-enable-bot-mode"), 443 | ("How to get Help Menu as Inline Mode?", 444 | f"{faqs}#9-how-to-get-help-menu-as-inline-mode"), 445 | ("What is dyno saver and what is .die cmd?", 446 | f"{faqs}#10-what-is-dyno-saver-what-is-die-only-for-heroku-users"), 447 | ("How to add buttons in Notes/Filters?", 448 | f"{faqs}#11-how-to-add-buttons-in-text-notes-and-filters"), 449 | ("How to setup Lydia ?", 450 | f"{faqs}#12-how-to-setup-lydia-"), 451 | ("What is floodwait?", f"{faqs}#13-what-is-floodwait"), 452 | ("How to setup deezloader?", f"{faqs}#14-how-to-setup-deezloader"), 453 | ("What is spamwatch?", f"{faqs}#15-what-is-spamwatch"), 454 | ("How to set your own custom media for .alive?", 455 | f"{faqs}#16how-to-set-your-own-custom-media-for-alive"), 456 | ("How to send secret message in userge bot ?", 457 | f"{faqs}#17-how-to-send-secret-message-using-your-userge-bot"), 458 | ("How to clear download path?", f"{faqs}#18-how-to-clear-downloads-path"), 459 | ("How to stop autopic?", f"{faqs}#19-how-to-stop-autopic"), 460 | ("How to Unzip, Unrar and Unpacks files?", f"{faqs}#20-how-to-unzip-unrar-and-unpack-files-in-userge"), 461 | ("How to add media in pm permit?", f"{faqs}#21-how-to-add-media-in-custom-pm-permit"), 462 | ("How to use spam watch api?", f"{faqs}#22-how-to-use-spam-watch-api"), 463 | ("How to update userbot?", f"{faqs}#23-how-to-update-userge-userbot"), 464 | ("How to know dyno usage?", f"{faqs}#24-how-to-know-dyno-usage"), 465 | ("File type issue while downloading from direct link?", 466 | f"{faqs}#25-file-type-issue-while-downloading-from-link"), 467 | ("How to Add/Load Custom Plugins?", f"{faqs}#26-how-to-addload-custom-plugins") 468 | ] 469 | -------------------------------------------------------------------------------- /assistant/utils/tools.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 2 | # 3 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 4 | # and is released under the "GNU v3.0 License Agreement". 5 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 6 | # 7 | # All rights reserved. 8 | 9 | import time 10 | 11 | from pyrogram.types import Message 12 | 13 | from assistant import bot, Config 14 | 15 | _BOT_ID = 0 16 | 17 | 18 | def time_formatter(seconds: float) -> str: 19 | """ humanize time """ 20 | minutes, seconds = divmod(int(seconds), 60) 21 | hours, minutes = divmod(minutes, 60) 22 | days, hours = divmod(hours, 24) 23 | tmp = ((str(days) + "d, ") if days else "") + \ 24 | ((str(hours) + "h, ") if hours else "") + \ 25 | ((str(minutes) + "m, ") if minutes else "") + \ 26 | ((str(seconds) + "s, ") if seconds else "") 27 | return tmp[:-2] 28 | 29 | 30 | async def extract_time(msg, time_val): 31 | if any(time_val.endswith(unit) for unit in ('m', 'h', 'd')): 32 | unit = time_val[-1] 33 | time_num = time_val[:-1] # type: str 34 | if not time_num.isdigit(): 35 | await msg.reply("`Invalid time amount specified.`") 36 | return 37 | 38 | if unit == 'm': 39 | bantime = int(time.time() + int(time_num) * 60) 40 | elif unit == 'h': 41 | bantime = int(time.time() + int(time_num) * 60 * 60) 42 | elif unit == 'd': 43 | bantime = int(time.time() + int(time_num) * 24 * 60 * 60) 44 | else: 45 | await msg.reply("`Any other unit of time you know..?`") 46 | return 47 | return bantime 48 | else: 49 | await msg.reply("`Need time in format of m, h or d`") 50 | return 51 | 52 | 53 | def is_admin(chat_id: int, user_id: int, check_devs: bool = False) -> bool: 54 | """ check user is admin or not in this chat """ 55 | if check_devs and is_dev(user_id): 56 | return True 57 | if chat_id not in Config.ADMINS: 58 | return False 59 | return user_id in Config.ADMINS[chat_id] 60 | 61 | 62 | def is_dev(user_id: int) -> bool: 63 | """ returns user is dev or not """ 64 | return user_id in Config.DEV_USERS 65 | 66 | 67 | async def is_self(user_id: int) -> bool: 68 | """ returns user is assistant or not """ 69 | global _BOT_ID # pylint: disable=global-statement 70 | if not _BOT_ID: 71 | _BOT_ID = (await bot.get_me()).id 72 | return user_id == _BOT_ID 73 | 74 | 75 | async def check_rights(chat_id: int, user_id: int, rights: str) -> bool: 76 | """ check admin rights """ 77 | user = await bot.get_chat_member(chat_id, user_id) 78 | if user.status == "member": 79 | return False 80 | if user.status == "administrator": 81 | if getattr(user, rights, None): 82 | return True 83 | return False 84 | return False 85 | 86 | 87 | async def check_bot_rights(chat_id: int, rights: str) -> bool: 88 | """ check bot rights """ 89 | global _BOT_ID # pylint: disable=global-statement 90 | if not _BOT_ID: 91 | _BOT_ID = (await bot.get_me()).id 92 | bot_ = await bot.get_chat_member(chat_id, _BOT_ID) 93 | if bot_.status == "administrator": 94 | if getattr(bot_, rights, None): 95 | return True 96 | return False 97 | return False 98 | 99 | 100 | async def sed_sticker(msg: Message): 101 | """ send default sticker """ 102 | sticker = (await bot.get_messages('UserGeOt', 498697)).sticker.file_id 103 | await msg.reply_sticker(sticker) 104 | -------------------------------------------------------------------------------- /assistant/versions.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=missing-module-docstring 2 | # 3 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 4 | # 5 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 6 | # and is released under the "GNU v3.0 License Agreement". 7 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 8 | # 9 | # All rights reserved. 10 | 11 | from sys import version_info 12 | 13 | from pyrogram import __version__ as __pyro_version__ # noqa 14 | 15 | __assistant_version__ = "v1" 16 | __python_version__ = f"{version_info[0]}.{version_info[1]}.{version_info[2]}" 17 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiofiles 2 | aiohttp 3 | pyrogram==1.1.6 4 | python-dotenv 5 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >. 4 | # 5 | # This file is part of < https://github.com/UsergeTeam/Userge-Assistant > project, 6 | # and is released under the "GNU v3.0 License Agreement". 7 | # Please see < https://github.com/Userge-Assistant/blob/master/LICENSE > 8 | # 9 | # All rights reserved. 10 | 11 | python3.8 -m assistant 12 | -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.8.5 --------------------------------------------------------------------------------