Browse Source

Merge develop into master

Update to 0.3.3

Add CloudConvert API
Add !cclean to clean the chat from deleted accounts
Add !chats and !unread to get information about all chats and unread messages
Add .ggl to send a google search (similar to lmgtfy)

Minor fixes for some modules.
Nicolas "Colin" Neht 4 months ago
parent
commit
31c94ef86c

+ 3
- 1
.env.sample View File

@@ -16,4 +16,6 @@ LOGGER_GROUP = -1001234567890
16 16
 # Other site's API KEYS
17 17
 #
18 18
 ACCGEN_API = "ABCDEF-GHIJKL-MNOPQR-STUVWX"
19
-# https://accgen.cathook.club
19
+# https://accgen.cathook.club
20
+CC_API = "123456789abcdefg"
21
+# https://cloudconvert.com

+ 7
- 3
HELP.md View File

@@ -27,8 +27,6 @@ This program is a Userbot for the [Telegram Messenger](https://telegram.org) bas
27 27
 
28 28
 ### Administration (`admin.py`)
29 29
 
30
-These work only in reply to another user.
31
-
32 30
 | Command | Action |
33 31
 |---------|--------|
34 32
 | `?ban x` | Bans a replied-to user for time `x` |
@@ -36,6 +34,9 @@ These work only in reply to another user.
36 34
 | `?mute x` | Mutes a replied-to user for time `x` |
37 35
 | `?unmute` | Unmutes a replied-to user |
38 36
 | `?kick` | Kicks a replied-to user |
37
+| `!cclean` | Remove Deleted Accounts from your chat |
38
+
39
+With the exception of `!cclean`, the above commands only work in reply.
39 40
 
40 41
 Timed restrictions can be applied in the following scheme:
41 42
 
@@ -62,13 +63,15 @@ Evaluate and Execute whithin Telegram
62 63
 
63 64
 ### Information (`get_info.py`)
64 65
 
65
-Get information about your administration and chat
66
+Get information about your administration, members of your chat and all your chats.
66 67
 
67 68
 | Command | Description |
68 69
 |---------|-------------|
69 70
 | `!admins` | Gives out a list of all admins in a chat. |
70 71
 | `!members` | Gives out counter of all members, bots and deleted accounts in that group. |
71 72
 | `.id` | Gives out the File ID of a replied-to media. If there is neither a media nor a reply it will be the Chat ID. |
73
+| `!chats` | Get an overview on how many chats you have in groups, supergroup, with bots, etc. |
74
+| `!unread` | Get an overview on unread messages, mentions and chats marked as unread |
72 75
 
73 76
 ### Memes (`memes.py`)
74 77
 
@@ -76,6 +79,7 @@ Get information about your administration and chat
76 79
 |---------|-------------|--------|
77 80
 | `dog`, ๐Ÿ•, ๐Ÿถ, ๐Ÿฉ | Sends an image of a dog ๐Ÿถ๐Ÿ• | [random.dog](https://random.dog/)[*](https://github.com/AdenFlorian/random.dog#api) |
78 81
 | `.mock` | Send mocking Spongebob ๐Ÿงฝ | [@Stickerizerbot](https://t.me/Stickerizerbot) |
82
+| `.ggl` | Send a Google Search ๐Ÿ” | Same as `.mock` |
79 83
 
80 84
 ### Miscellaneous (`misc.py`)
81 85
 

+ 9
- 10
pyrobot/__init__.py View File

@@ -20,7 +20,7 @@ if sys.version_info[0] < 3 or sys.version_info[1] < 6:
20 20
     quit(1)
21 21
 
22 22
 # Now for the rest
23
-__version__ = '0.3.2'
23
+__version__ = '0.3.3'
24 24
 __author__ = 'Nicolas "Colin" Neht'
25 25
 __source__ = 'https://git.colinshark.de/PyroBot/PyroBot'
26 26
 __copyright__ = 'Copyright (c) 2019 ' + __author__
@@ -30,18 +30,17 @@ __copystring__ = f"PyroBot v{__version__} | {__copyright__}"
30 30
 dotenv.load_dotenv()
31 31
 
32 32
 # Get the Values from our .env
33
-if os.getenv("___PLEASE_REMOVE_THIS_LINE___") is None:
34
-    API_ID = os.getenv("API_ID")
35
-    API_HASH = os.getenv("API_HASH")
33
+API_ID = os.getenv("API_ID")
34
+API_HASH = os.getenv("API_HASH")
36 35
 
37
-    LOGGER = os.getenv("LOGGER")
36
+LOGGER = os.getenv("LOGGER")
37
+try:
38 38
     LOGGER_GROUP = int(os.getenv("LOGGER_GROUP"))
39
+except ValueError:
40
+    LOGGER_GROUP = os.getenv("LOGGER_GROUP")
39 41
 
40
-    ACCGEN_API = os.getenv("ACCGEN_API")
41
-    CC_API = os.getenv("CC_API")
42
-else:
43
-    LOGS.error("The .env doesn't seem to be edited, please do so.")
44
-    quit(1)
42
+ACCGEN_API = os.getenv("ACCGEN_API")
43
+CC_API = os.getenv("CC_API")
45 44
 
46 45
 # Create Database if there is none yet.
47 46
 PYRO_DB = str(Path(__file__).parent.parent / 'pyrobot.db')

+ 1
- 0
pyrobot/__main__.py View File

@@ -17,3 +17,4 @@ else:
17 17
     LOGS.info(f"You're logged in as \"{ME}\"! Test it by typing .alive in any chat.")
18 18
     LOGS.info(f"Your bot is Version {__version__}\n")
19 19
     BOT.idle()
20
+    print("\nUserbot Stopped\n")

+ 33
- 9
pyrobot/modules/admin.py View File

@@ -2,7 +2,7 @@ from time import sleep, time
2 2
 
3 3
 from pyrobot import BOT
4 4
 from pyrogram import Filters, Message
5
-from pyrogram.errors import UserAdminInvalid
5
+from pyrogram.errors import UserAdminInvalid, FloodWait
6 6
 
7 7
 from ..interval import IntervalHelper
8 8
 from ..helpers import LogMessage
@@ -107,8 +107,7 @@ def ban_hammer(bot: BOT, message: Message):
107 107
             BOT.kick_chat_member(
108 108
                 chat_id=message.chat.id,
109 109
                 user_id=message.reply_to_message.from_user.id,
110
-                until_date=Timer(message)
111
-            )
110
+                until_date=Timer(message))
112 111
             if len(message.command) > 1:
113 112
                 message.edit(BANNED_TIME.format(
114 113
                     message,
@@ -128,8 +127,7 @@ def unban(bot: BOT, message: Message):
128 127
         try:
129 128
             BOT.unban_chat_member(
130 129
                 chat_id=message.chat.id,
131
-                user_id=message.reply_to_message.from_user.id
132
-            )
130
+                user_id=message.reply_to_message.from_user.id)
133 131
             message.edit(UNBANNED.format(message))
134 132
             LogMessage(UNBANNED_LOG.format(
135 133
                 message,
@@ -146,8 +144,7 @@ def mute_hammer(bot: BOT, message: Message):
146 144
                 chat_id=message.chat.id,
147 145
                 user_id=message.reply_to_message.from_user.id,
148 146
                 until_date=Timer(message),
149
-                can_send_messages=False,
150
-            )
147
+                can_send_messages=False,)
151 148
             if len(message.command) > 1:
152 149
                 message.edit(MUTED_TIME.format(
153 150
                     message,
@@ -176,8 +173,7 @@ def unmute(bot: BOT, message: Message):
176 173
                 can_send_polls=True,
177 174
                 can_change_info=True,
178 175
                 can_invite_users=True,
179
-                can_pin_messages=True
180
-            )
176
+                can_pin_messages=True)
181 177
             message.edit(UNMUTED.format(message))
182 178
             LogMessage(UNMUTED_LOG.format(
183 179
                 message,
@@ -203,3 +199,31 @@ def kick_user(bot: BOT, message: Message):
203 199
                 str(message.chat.id).replace("-100", "")))
204 200
         except UserAdminInvalid:
205 201
             RestrictFailed(message)
202
+
203
+
204
+@BOT.on_message(Filters.command("cclean", "!") & Filters.me)
205
+def clean_deleted(bot: BOT, message: Message):
206
+    if AdminCheck(message) is True:
207
+        message.edit("`Iterating through memberlist...`")
208
+        all_members = BOT.iter_chat_members(message.chat.id)
209
+        to_remove = []
210
+        removed = []
211
+
212
+        for member in all_members:
213
+            if member.user.is_deleted:
214
+                to_remove.append(member.user.id)
215
+
216
+        message.edit(f"`{len(to_remove)} deleted accounts found.`")
217
+
218
+        for usr in to_remove:
219
+            try:
220
+                BOT.kick_chat_member(
221
+                    chat_id=message.chat.id,
222
+                    user_id=usr)
223
+                removed.append(usr)
224
+            except UserAdminInvalid:
225
+                pass
226
+            except FloodWait as e:
227
+                sleep(e.x)
228
+
229
+        message.edit(f"Removed {len(removed)} deleted accounts.")

+ 5
- 1
pyrobot/modules/cloudconvert.py View File

@@ -21,7 +21,11 @@ def cc_gif(bot: BOT, message: Message):
21 21
     except FileNotFoundError:
22 22
         pass
23 23
 
24
-    conv_url = message.command[1]
24
+    try:
25
+        conv_url = message.command[1]
26
+    except IndexError:
27
+        message.edit("No URL to convert")
28
+        return
25 29
     conv_ext = re.findall(r"\w+$", conv_url)
26 30
 
27 31
     try:

+ 1
- 0
pyrobot/modules/evaluation.py View File

@@ -2,6 +2,7 @@ import os
2 2
 from time import sleep
3 3
 
4 4
 from pyrogram import Filters, Message
5
+from pyrogram.api import functions, types
5 6
 
6 7
 from pyrobot import BOT
7 8
 

+ 134
- 1
pyrobot/modules/get_info.py View File

@@ -1,4 +1,4 @@
1
-from time import sleep
1
+from time import time, sleep
2 2
 
3 3
 from pyrogram import Filters, Message
4 4
 from pyrobot import BOT
@@ -29,6 +29,33 @@ MEMBER_INFO = (
29 29
     "โ•  Deleted Accounts: `{}`\n"
30 30
     "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•")
31 31
 
32
+CHAT_INFO = (
33
+    "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
34
+    "โ•‘ **Overview Chatlist**\n"
35
+    "โ•‘ Total Chats: {}\n"
36
+    "โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
37
+    "โ•‘ Private Chats: {}\n"
38
+    "โ•‘ Bots: {}\n"
39
+    "โ•‘ Groups: {}\n"
40
+    "โ•‘ Supergroups: {}\n"
41
+    "โ•‘ Channels: {}\n"
42
+    "โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
43
+    "โ•‘ Time elapsed: {} seconds\n"
44
+    "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•")
45
+
46
+UNREAD_INFO = (
47
+    "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
48
+    "โ•‘ **Unread Messages**\n"
49
+    "โ•‘ Total: `{total_msg}` in {total_chats} Chats\n"
50
+    "โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
51
+    "โ•‘ Messages from\n"
52
+    "โ•‘ `{msg_private}` msg - {chat_private} Users\n"
53
+    "โ•‘ `{msg_bots}` msg - {chat_bots} Bots\n"
54
+    "โ•‘ `{msg_groups}` msg - {chat_groups} Groups\n"
55
+    "โ•‘ `{msg_super}` msg - {chat_super} Supergroups\n"
56
+    "โ•‘ `{msg_channel}` msg - {chat_channel} Channels\n"
57
+    "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•")
58
+
32 59
 # -- Constants End -- #
33 60
 
34 61
 
@@ -159,3 +186,109 @@ def get_file(bot: BOT, message: Message):
159 186
         message.edit("This chat's ID:\n`{}`".format(message.chat.id))
160 187
     else:
161 188
         message.edit("File_ID:\n`{}`".format(file_id))
189
+
190
+
191
+@BOT.on_message(Filters.command("chats", "!") & Filters.me)
192
+def get_chats(bot: BOT, message: Message):
193
+    total = 0
194
+    private = 0
195
+    channel = 0
196
+    group = 0
197
+    supergroup = 0
198
+    bots = 0
199
+    private_bots = []
200
+
201
+    start = int(time())
202
+    message.edit("Getting Chatlist...")
203
+    for dialog in BOT.iter_dialogs():
204
+        total += 1
205
+        if dialog.chat.type == 'private':
206
+            private_bots.append(dialog.chat.id)  # Save for later parsing.
207
+        elif dialog.chat.type == 'channel':
208
+            channel += 1
209
+        elif dialog.chat.type == 'group':
210
+            group += 1
211
+        elif dialog.chat.type == 'supergroup':
212
+            supergroup += 1
213
+
214
+    message.edit("Checking for bots...")
215
+    chunk_size = 200
216
+    for i in range(0, len(private_bots), chunk_size):
217
+        for priv in BOT.get_users(private_bots[i:i + chunk_size]):
218
+            if priv.is_bot:
219
+                bots += 1
220
+            else:
221
+                private += 1
222
+
223
+    message.edit(CHAT_INFO.format(
224
+        total,
225
+        private,
226
+        bots,
227
+        group,
228
+        supergroup,
229
+        channel,
230
+        int(time()) - start))
231
+
232
+
233
+@BOT.on_message(Filters.command("unread", "!") & Filters.me)
234
+def get_unreads(bot: BOT, message: Message):
235
+    total_messages_unread = 0
236
+    total_chats_unread = 0
237
+    unread_msg_priv = 0
238
+    unread_chat_priv = 0
239
+    unread_msg_bot = 0
240
+    unread_chat_bot = 0
241
+    unread_msg_group = 0
242
+    unread_chat_group = 0
243
+    unread_msg_super = 0
244
+    unread_chat_super = 0
245
+    unread_msg_channel = 0
246
+    unread_chat_channel = 0
247
+    # A fuckton of variables (:
248
+    chunk_size = 200
249
+    could_be_bot = []
250
+
251
+    message.edit("Getting dialogs...")
252
+    all_dialogs = BOT.iter_dialogs()
253
+    message.edit("Formatting...")
254
+    for dialog in all_dialogs:
255
+        if dialog.unread_messages_count:
256
+            total_messages_unread += dialog.unread_messages_count
257
+            if dialog.chat.type == 'private':
258
+                could_be_bot.append(dialog)
259
+                total_chats_unread += 1
260
+            elif dialog.chat.type == 'group':
261
+                unread_msg_group += dialog.unread_messages_count
262
+                unread_chat_group += 1
263
+                total_chats_unread += 1
264
+            elif dialog.chat.type == 'supergroup':
265
+                unread_msg_super += dialog.unread_messages_count
266
+                unread_chat_super += 1
267
+                total_chats_unread += 1
268
+            elif dialog.chat.type == 'channel':
269
+                unread_msg_channel += dialog.unread_messages_count
270
+                unread_chat_channel += 1
271
+                total_chats_unread += 1
272
+
273
+    for i in range(0, len(could_be_bot), chunk_size):
274
+        for priv in BOT.get_users([x.chat.id for x in could_be_bot[i:i + chunk_size]]):
275
+            if priv.is_bot:
276
+                unread_msg_bot += could_be_bot[i].unread_messages_count
277
+                unread_chat_bot += 1
278
+            elif not priv.is_bot:
279
+                unread_msg_priv += could_be_bot[i].unread_messages_count
280
+                unread_chat_priv += 1
281
+
282
+    message.edit(UNREAD_INFO.format(
283
+        total_msg=total_messages_unread,
284
+        total_chats=total_chats_unread,
285
+        msg_private=str(unread_msg_priv).rjust(6, " "),
286
+        chat_private=unread_chat_priv,
287
+        msg_bots=str(unread_msg_bot).rjust(6, " "),
288
+        chat_bots=unread_chat_bot,
289
+        msg_groups=str(unread_msg_group).rjust(6, " "),
290
+        chat_groups=unread_chat_group,
291
+        msg_super=str(unread_msg_super).rjust(6, " "),
292
+        chat_super=unread_chat_super,
293
+        msg_channel=str(unread_msg_channel).rjust(6, " "),
294
+        chat_channel=unread_chat_channel))

+ 41
- 8
pyrobot/modules/memes.py View File

@@ -28,8 +28,7 @@ def send_dog(bot: BOT, message: Message):
28 28
         chat_id=message.chat.id,
29 29
         photo=doggo['url'],
30 30
         caption="doggo",
31
-        reply_to_message_id=ReplyCheck(message)
32
-    )
31
+        reply_to_message_id=ReplyCheck(message))
33 32
     if message.from_user.is_self:
34 33
         message.delete()
35 34
 
@@ -51,10 +50,44 @@ def mock_people(bot: BOT, message: Message):
51 50
     mock_results = BOT.get_inline_bot_results(
52 51
         "stickerizerbot",
53 52
         "#7" + mock_text)
54
-    BOT.send_inline_bot_result(
55
-        chat_id=message.chat.id,
56
-        query_id=mock_results.query_id,
57
-        result_id=mock_results.results[0].id,
58
-        reply_to_message_id=ReplyCheck(message),
59
-        hide_via=True)
53
+    try:
54
+        BOT.send_inline_bot_result(
55
+            chat_id=message.chat.id,
56
+            query_id=mock_results.query_id,
57
+            result_id=mock_results.results[0].id,
58
+            reply_to_message_id=ReplyCheck(message),
59
+            hide_via=True)
60
+    except TimeoutError:
61
+        message.edit("@StickerizerBot didn't respond in time.")
62
+        sleep(2)
63
+    message.delete()
64
+
65
+
66
+@BOT.on_message(Filters.command("ggl", ".") & Filters.me)
67
+def google_sticker(bot: BOT, message: Message):
68
+    cmd = message.command
69
+
70
+    if len(cmd) > 1:
71
+        ggl_text = " ".join(cmd[1:])
72
+    elif message.reply_to_message and len(cmd) == 1:
73
+        ggl_text = message.reply_to_message.text
74
+    elif not message.reply_to_message and len(cmd) == 1:
75
+        message.edit("I need something to google")
76
+        sleep(2)
77
+        message.delete()
78
+        return
79
+
80
+    ggl_result = BOT.get_inline_bot_results(
81
+        "stickerizerbot",
82
+        "#12" + ggl_text)
83
+    try:
84
+        BOT.send_inline_bot_result(
85
+            chat_id=message.chat.id,
86
+            query_id=ggl_result.query_id,
87
+            result_id=ggl_result.results[0].id,
88
+            reply_to_message_id=ReplyCheck(message),
89
+            hide_via=False)
90
+    except TimeoutError:
91
+        message.edit("@StickerizerBot didn't respond in time.")
92
+        sleep(2)
60 93
     message.delete()

+ 13
- 6
pyrobot/modules/steam.py View File

@@ -6,7 +6,8 @@ from pyrobot import BOT, ACCGEN_API
6 6
 
7 7
 # -- Constants -- #
8 8
 
9
-API = "https://accgen.cathook.club/api/v1/account/" + ACCGEN_API
9
+if ACCGEN_API:
10
+    API = "https://accgen.cathook.club/api/v1/account/" + ACCGEN_API
10 11
 
11 12
 ACC_MSG = (
12 13
     "โ•”โ•โ•โ•โ•โ•\n"
@@ -36,13 +37,19 @@ def steam_accgen(bot: BOT, message: Message):
36 37
         sleep(3)
37 38
         message.delete()
38 39
         return
39
-    acc = requests.get(API).json()
40
+    acc = requests.get(API)
41
+    try:
42
+        acc.raise_for_status()
43
+        acc.json()
44
+    except Exception as e:
45
+        message.edit(f"`{e}`".replace(ACCGEN_API, "<key>"))
46
+        sleep(5)
47
+        message.delete()
48
+        return
40 49
 
41 50
     message.edit(
42 51
         ACC_MSG.format(
43 52
             login=acc['login'],
44 53
             password=acc['password'],
45
-            steamid=acc['steamid']
46
-        ),
47
-        disable_web_page_preview=True
48
-    )
54
+            steamid=acc['steamid']),
55
+        disable_web_page_preview=True)

+ 4
- 1
pyrobot/modules/whois.py View File

@@ -20,6 +20,7 @@ WHOIS = (
20 20
     "Common Groups: `{common_groups}`\n"
21 21
     "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•\n"
22 22
     "Bio:\n{bio}")
23
+
23 24
 WHOIS_PIC = (
24 25
     "**WHO IS \"{full_name}\"?**\n"
25 26
     "[Link to profile](tg://user?id={user_id})\n"
@@ -54,7 +55,9 @@ def ReplyCheck(message: Message):
54 55
 
55 56
 
56 57
 def LastOnline(user: User):
57
-    if user.status.recently:
58
+    if user.is_bot:
59
+        return ""
60
+    elif user.status.recently:
58 61
         return "Recently"
59 62
     elif user.status.within_week:
60 63
         return "Within the last week"

+ 1
- 0
requirements.txt View File

@@ -3,3 +3,4 @@ pyrogram
3 3
 tgcrypto
4 4
 python-dotenv
5 5
 cloudconvert
6
+speedtest-cli

Loadingโ€ฆ
Cancel
Save