├── .gitignore ├── README.txt ├── bot.py ├── requirements.txt └── sample-conf.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *vscode/ 3 | conf.py 4 | 5 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | THE CODE IN THIS REPO IS CURRENTLY OUTDATED AND NO LONGER WORKS. PLEASE CONSIDER UPDATING YOURSELF OR USE SOME OTHER REPO. THANKS! 2 | 3 | 4 | Installation: 5 | Using the bash on ubuntu linux or almost any other linux distro 6 | 1: cd BOT_FOLDER 7 | 2: pip install -r requirements.txt 8 | 9 | Setup: 10 | 1: open conf.py with your favourite text editor 11 | 2: Rest of the setup instruction for conf.py are already there. 12 | 3: After setting up conf.py run the bot 13 | 14 | 15 | Run: 16 | 1: In the bash shell type "python bot.py" to run. 17 | 2: type "python bot.py &" to run in the background so you may close the terminal. 18 | 19 | 20 | 21 | #Thanks! -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | '''' 3 | Author: Rehman Ali 4 | Python version used: Python3 5 | 6 | NOTE: Please don't mess with code if you don't understand what you are doing. 7 | ''' 8 | 9 | import conf as config 10 | import socks 11 | import discord 12 | from discord import errors 13 | import requests 14 | import socket 15 | import re 16 | import logging 17 | from box import Box as box 18 | from colorama import Back, Fore, init, Style 19 | from aiohttp import client_exceptions as clientExcps 20 | 21 | init(autoreset=True) 22 | 23 | colorSchemes = { 24 | 'SUCCESS': f"{Back.GREEN}{Fore.BLACK}{Style.NORMAL}", 25 | 'FAILURE': f"{Back.RED}{Fore.WHITE}{Style.BRIGHT}", 26 | 'WARNING': f"{Back.YELLOW}{Fore.BLACK}{Style.BRIGHT}", 27 | 'RESET': f"{Style.RESET_ALL}" 28 | } 29 | colorSchemes = box(colorSchemes) 30 | 31 | logging.basicConfig(format=f'{colorSchemes.FAILURE}[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.ERROR) 32 | 33 | 34 | 35 | bot = discord.Client() 36 | baseUrl = f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}" 37 | 38 | 39 | def replaceMentions(mentions, msg, channel): 40 | if channel: 41 | for ch in mentions: 42 | # msg = msg.replace(str(f"#{ch.id}"), '') 43 | msg = re.sub(f"<#{ch.id}>", '', msg) 44 | msg = re.sub(f"<{ch.id}>", '', msg) 45 | msg = re.sub(f"<*{ch.id}>", '', msg) 46 | msg = re.sub(f"<*{ch.id}*>", '', msg) 47 | msg = re.sub(f"<{ch.id}*>", '', msg) 48 | elif not channel: 49 | for member in mentions: 50 | msg = re.sub(f"<@{member.id}>", '', msg) 51 | msg = re.sub(f"<@!{member.id}>", '', msg) 52 | msg = re.sub(f"<{member.id}>", '', msg) 53 | msg = re.sub(f"<*{member.id}*>", '', msg) 54 | msg = re.sub(f"<{member.id}*>", '', msg) 55 | msg = re.sub(f"<*{member.id}>", '', msg) 56 | return str(msg) 57 | 58 | def removeTags(msg): 59 | msg = re.sub(r"@\w*", '', msg) 60 | msg = requests.utils.quote(msg) 61 | #print(f"{colorSchemes.SUCCESS}Quoted message: {msg}") 62 | return msg 63 | 64 | 65 | 66 | 67 | def isPhoto(url): 68 | imgExts = ["png", "jpg", "jpeg", "webp"] 69 | if any(ext in url for ext in imgExts): 70 | return True 71 | else: 72 | return False 73 | 74 | def isVideo(url): 75 | vidExts = ["mp4", "MP4", "mkv"] 76 | if any(ext in url for ext in vidExts): 77 | return True 78 | else: 79 | return False 80 | 81 | def isDoc(url): 82 | docExts = ["zip", "pdf", "gif"] 83 | if any(ext in url for ext in docExts): 84 | return True 85 | else: 86 | return False 87 | 88 | def matchChannel(channel, list): 89 | found=False 90 | for ch in list: 91 | res = ch.find(channel) 92 | if str(res) != "-1": 93 | found=True 94 | return found 95 | 96 | 97 | def sendMsg(url): 98 | attempts = 0 99 | while True: 100 | if attempts < 5: 101 | try: 102 | print(f"[+] Sending Message to Telegram ...") 103 | resp = requests.post(url) 104 | if resp.status_code == 200: 105 | print(f"{colorSchemes.SUCCESS}[+] Message sent!\n") 106 | break 107 | elif resp.status_code != 200: 108 | raise OSError 109 | except OSError: 110 | attempts += 1 111 | print(f"{colorSchemes.FAILURE}[-] Sending failed!\n[+] Trying again ... (Attempt {attempts})") 112 | continue 113 | except KeyboardInterrupt: 114 | print("\n[+] Please wait untill all messages in queue are sent!\n") 115 | else: 116 | print(f"{colorSchemes.FAILURE}[-] Message was not sent in 5 attempts. \n[-] Please check your network.") 117 | break 118 | 119 | 120 | 121 | if config.PROXY: 122 | if config.AUTHENTICATION: 123 | if config.USERNAME != None and config.PASSWORD != None: 124 | socks.set_default_proxy(socks.SOCKS5, config.SOCKS5_SERVER, config.SOCKS5_PORT, username=config.USERNAME, password=config.PASSWORD) 125 | print(f"\n[+] Proxy enabled with authentication set!\n[+] Proxy Server: {config.SOCKS5_SERVER}:{config.SOCKS5_PORT}") 126 | else: 127 | print(f"{colorSchemes.FAILURE}[-] Proxy authentication enabled but username/password not set.") 128 | quit() 129 | elif not config.AUTHENTICATION: 130 | socks.set_default_proxy(socks.SOCKS5, config.SOCKS5_SERVER, config.SOCKS5_PORT) 131 | print(f"{colorSchemes.WARNING}[+] Proxy enabled without authentication!\n[+] Proxy Server: {config.SOCKS5_SERVER}:{config.SOCKS5_PORT}") 132 | socket.socket = socks.socksocket 133 | print(f"{colorSchemes.WARNING}[+] Please wait for at least 30 seconds before first message.") 134 | 135 | 136 | 137 | 138 | 139 | @bot.event 140 | async def on_message(message): 141 | try: 142 | serverName = message.guild.name 143 | serversList = config.serversList.keys() 144 | channelName = message.channel.name 145 | except AttributeError: 146 | pass 147 | #print(f"Server: {serverName}, Channel: {channelName}") 148 | if serverName in serversList: 149 | channelsList = config.serversList[serverName] 150 | if matchChannel(channelName, channelsList): 151 | print(f"\n-------------------------------------------\n[+] Channel: {channelName}") 152 | if message.content: 153 | if message.mentions: 154 | # print(f"\n----------------\nUser Mentioned\n----------------") 155 | message.content = replaceMentions(message.mentions, message.content, channel=False) 156 | if message.channel_mentions: 157 | # print(f"\n----------------\nChannel Mentioned\n----------------") 158 | message.content = replaceMentions(message.channel_mentions, message.content, channel=True) 159 | toSend = f"{message.guild}/{message.channel}/{message.author.name}: {message.content}" 160 | print(f"[+] Message: {toSend}") 161 | toSend = removeTags(toSend) 162 | url = f"{baseUrl}/sendMessage?text={toSend}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 163 | sendMsg(url) 164 | 165 | if message.attachments: 166 | attachmentUrl = message.attachments[0].url 167 | if isPhoto(attachmentUrl): 168 | url = f"{baseUrl}/sendPhoto?photo={attachmentUrl}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 169 | sendMsg(url) 170 | elif isVideo(attachmentUrl): 171 | url = f"{baseUrl}/sendVideo?video={attachmentUrl}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 172 | sendMsg(url) 173 | elif isDoc(attachmentUrl): 174 | url = f"{baseUrl}/sendDocument?document={attachmentUrl}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 175 | sendMsg(url) 176 | 177 | if message.embeds: 178 | embed = message.embeds[0].to_dict() 179 | print(embed) 180 | if str(embed['type']) == "rich": 181 | if 'title' in embed.keys() and 'description' in embed.keys(): 182 | toSend = f"{message.guild}/{message.channel}/{message.author.name}: {embed['title']}\n{embed['description']}" 183 | toSend = removeTags(toSend) 184 | elif 'title' in embed.keys(): 185 | toSend = f"{message.guild}/{message.channel}/{message.author.name}: {embed['title']}" 186 | toSend = removeTags(toSend) 187 | elif 'description' in embed.keys(): 188 | toSend = f"{message.guild}/{message.channel}/{message.author.name}: {embed['description']}" 189 | toSend = removeTags(toSend) 190 | url = f"{baseUrl}/sendMessage?text={toSend}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 191 | sendMsg(url) 192 | # print(embed) 193 | elif str(embed['type']) == "link": 194 | toSend = f"{embed['title']}\n{embed['description']}\n{embed['url']}" 195 | toSend = removeTags(toSend) 196 | url = f"{baseUrl}/sendMessage?text={toSend}&chat_id={config.TELEGRAM_RECEIVER_CHAT_ID}" 197 | sendMsg(url) 198 | 199 | 200 | #Run the bot using the user token 201 | try: 202 | bot.run(config.USER_DISCORD_TOKEN, bot=False) 203 | except RuntimeError: 204 | print("\n\nPlease Wait ...\nShutting down the bot ... \n") 205 | quit() 206 | except errors.HTTPException: 207 | print(f"{colorSchemes.FAILURE}Invalid discord token or network down!") 208 | quit() 209 | except errors.LoginFailure: 210 | print(f"{colorSchemes.FAILURE}Login failed to discord. May be bad token or network down!") 211 | quit() 212 | except clientExcps.ClientConnectionError: 213 | print(f"{colorSchemes.FAILURE}[-] Proxy seems to be down or network problem.") 214 | quit() 215 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | discord 2 | pysocks 3 | requests 4 | requests[socks] 5 | python-box 6 | colorama 7 | -------------------------------------------------------------------------------- /sample-conf.py: -------------------------------------------------------------------------------- 1 | 2 | # The Discord user token. It is a bit hard to obtain. You can follow the online tutorial here to 3 | # obtain your user token for discord. Tutorial: https://www.youtube.com/watch?v=tI1lzqzLQCs&feature=emb_logo 4 | USER_DISCORD_TOKEN = 'NzE0MDcxMjvo9E7dw' 5 | 6 | # Go to your telegram account. 7 | # In the left upper corner in the search box search fot BotFather 8 | # Click on the bot father and then continue below. 9 | # Send /newbot to BotFather and it will ask you to name your bot. 10 | # After naming the bot it will ask you to set the user name for bot. This would be unique. 11 | # Now after the username is set BotFather will give you your bot token paste it here below. 12 | # Altenatively, Follow this (https://core.telegram.org/bots#6-botfather) to create your bot on telegram. It's super easy. 13 | 14 | TELEGRAM_BOT_TOKEN = '11057250j9lpNg' 15 | 16 | 17 | 18 | # Chat id is the id for the group or channel you want to receive messages at. 19 | # To get this open your browser and paste the following url in the addressbar replacing group or channel name and telegram bot token. 20 | # https://api.telegram.org/bot/sendMessage?text=%22Hello%22&chat_id= 21 | # In the response you will receive a json object containing all the info about the channel. 22 | # Find the channel chat id under the chat. Copy and paste here. 23 | # Alternatively you can use get_id.py script from telegram-msg-forwarder folder. But for that to work you will have to setup the forwarder first. 24 | 25 | TELEGRAM_RECEIVER_CHAT_ID = -1001499013531 #"telegram_channel_chat_id_here" 26 | 27 | 28 | 29 | 30 | 31 | # Configure the channels and server here to from where you want to receive the messages. 32 | 33 | serversList = { 34 | "botter server": ["help", "rules", "members", "general", "instructions"] 35 | } 36 | 37 | 38 | 39 | #SOCKS5 proxy settings 40 | # Set PROXY to False to disable the proxy settings 41 | 42 | PROXY = True 43 | SOCKS5_SERVER = 'socks.com' 44 | SOCKS5_PORT = 1080 45 | 46 | # If proxy requires authentication then set AUTHETICATIN to True to enable. 47 | AUTHENTICATION = False 48 | USERNAME = 'yf4zjrt' 49 | PASSWORD = 'nymh9x' 50 | 51 | 52 | --------------------------------------------------------------------------------