pull/16/merge
Abin Paul Zachariah 2018-08-12 20:20:13 +00:00 committed by GitHub
commit 3955ada724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 889 additions and 3 deletions

2
Procfile Normal file
View File

@ -0,0 +1,2 @@
worker: python3 -m stdborg

View File

@ -6,6 +6,12 @@ Pluggable [``asyncio``](https://docs.python.org/3/library/asyncio.html)
## installing
#### The Easy Way
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
#### The Legacy Way
Simply clone the repository and run the main file:
```sh
git clone https://github.com/uniborg/uniborg.git

33
app.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "UniBorg",
"description": "Modular UserBot powered by @TelethonChat!",
"keywords": [
"telegram",
"userbot",
"plugin",
"modular"
],
"repository": "https://github.com/uniborg/uniborg",
"env": {
"ENV": {
"description": "Setting this to ANYTHING will enable env variables. But, you need to understand the code to know what to set here!",
"value": "ANYTHING"
},
"OPEN_WEATHER_MAP_APPID": {
"description": "Get your own APPID from https://api.openweathermap.org/data/2.5/weather",
"value": "",
"required": false
},
"SCREEN_SHOT_LAYER_ACCESS_KEY": {
"description": "Get your own ACCESS_KEY from http://api.screenshotlayer.com/api/capture",
"value": "",
"required": false
},
"PRIVATE_GROUP_BOT_API_ID": {
"description": "Send .get_id in any group to fill this value. AFK mode (and other sensitive plugins) will not work without this!",
"value": "",
"required": false
}
},
"addons": []
}

View File

@ -1 +1,9 @@
regex
urbandict
requests
Pillow
hachoir
cryptg
cfscrape
beautifulsoup4

104
stdplugins/afk.py Normal file
View File

@ -0,0 +1,104 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
import time
global ISAFK
ISAFK=False
global AFKREASON
AFKREASON="No Reason"
global USERS
USERS={}
global COUNT_MSG
COUNT_MSG=0
global PRIVATE_GROUP_BOT_API_ID
PRIVATE_GROUP_BOT_API_ID = os.environ.get("PRIVATE_GROUP_BOT_API_ID")
@borg.on(events.NewMessage(incoming=True))
async def _(event):
global PRIVATE_GROUP_BOT_API_ID
if not PRIVATE_GROUP_BOT_API_ID:
await event.edit("This functionality will not work")
return
PRIVATE_GROUP_BOT_API_ID = int(PRIVATE_GROUP_BOT_API_ID)
global COUNT_MSG
global USERS
global ISAFK
global AFKREASON
if event.message.mentioned or event.is_private:
if ISAFK:
if event.sender:
if event.sender.username not in USERS:
USERS.update({event.sender.username:1})
COUNT_MSG=COUNT_MSG+1
await event.reply("Sorry! My boss in AFK due to ```"+AFKREASON+"```Would ping him to look into the message soon😉.Meanwhile you can play around with his AI. **This message shall be self destructed in 5 seconds**")
time.sleep(5)
i=1
async for message in borg.iter_messages(event.chat_id,from_user='me'):
if i>1:
break
i=i+1
await message.delete()
else:
USERS.update({event.chat_id:1})
COUNT_MSG=COUNT_MSG+1
await event.reply("Sorry! My boss in AFK due to ```"+AFKREASON+"```Would ping him to look into the message soon😉. Meanwhile you can play around with his AI. **This message shall be self destructed in 5 seconds**")
time.sleep(5)
i=1
async for message in borg.iter_messages(event.chat_id,from_user='me'):
if i>1:
break
i=i+1
await message.delete()
@borg.on(events.NewMessage(outgoing=True, pattern=r'.iamafk (.*)'))
async def _(event):
global PRIVATE_GROUP_BOT_API_ID
if not PRIVATE_GROUP_BOT_API_ID:
await event.edit("This functionality will not work")
return
PRIVATE_GROUP_BOT_API_ID = int(PRIVATE_GROUP_BOT_API_ID)
if event.fwd_from:
return
string = event.pattern_match.group(1)
global ISAFK
global AFKREASON
ISAFK = True
await event.edit("I am now AFK!")
if string != "":
AFKREASON = string
@borg.on(events.NewMessage(outgoing=True, pattern='.notafk'))
async def _(event):
global PRIVATE_GROUP_BOT_API_ID
if not PRIVATE_GROUP_BOT_API_ID:
await event.edit("This functionality will not work")
return
PRIVATE_GROUP_BOT_API_ID = int(PRIVATE_GROUP_BOT_API_ID)
global ISAFK
global COUNT_MSG
global USERS
global AFKREASON
ISAFK=False
await event.edit("I have returned from AFK mode.")
await event.respond("```You had recieved "+str(COUNT_MSG)+" messages while you were away. Check log for more details. This auto-generated message shall be self destructed in 2 seconds.```")
time.sleep(2)
i=1
async for message in borg.iter_messages(event.chat_id,from_user='me'):
if i>1:
break
i=i+1
await message.delete()
await borg.send_message(PRIVATE_GROUP_BOT_API_ID, "You had recieved "+str(COUNT_MSG)+" messages from "+str(len(USERS))+" chats while you were away")
for i in USERS:
await borg.send_message(PRIVATE_GROUP_BOT_API_ID,str(i)+" sent you "+"```"+str(USERS[i])+" messages```")
COUNT_MSG=0
USERS={}
AFKREASON="No reason"

View File

@ -10,7 +10,7 @@ async def _(event):
if event.fwd_from:
return
await event.delete()
mentions = "@all"
mentions = "@tagall"
chat = await event.get_input_chat()
async for x in borg.iter_participants(chat, 100):
mentions += f"[\u2063](tg://user?id={x.id})"

View File

@ -0,0 +1,19 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import random, re
@borg.on(events.NewMessage(pattern=r".decide", outgoing=True))
async def _(event):
if event.fwd_from:
return
r = random.randint(1, 100)
if r % 3 == 1:
await event.edit("Yes")
elif r % 3 == 2:
await event.edit("No")
else:
await event.edit("¯\_(ツ)_/¯")

16
stdplugins/delmsg.py Normal file
View File

@ -0,0 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=".delmsg", outgoing=True))
async def _(event):
if event.fwd_from:
return
i = 1
async for message in borg.iter_messages(event.chat_id, from_user="me"):
i = i + 1
await message.delete()
await event.delete()

29
stdplugins/exec.py Normal file
View File

@ -0,0 +1,29 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import subprocess
from telethon.errors import MessageEmptyError
@borg.on(events.NewMessage(pattern=r"\.exec (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
input_str = event.pattern_match.group(1)
input_command = input_str.split(" ")
try:
t_response = subprocess.check_output(input_command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
await event.edit("process returned {}\n output: {}".format(exc.returncode, exc.output))
else:
x_reponse = t_response.decode("UTF-8")
final_output = "**EXEC**: {} \n\n **OUTPUT**: \n{} \n".format(input_str, x_reponse)
try:
await event.edit(final_output)
except MessageEmptyError as exc:
await event.edit("✅ Exited correctly.")

19
stdplugins/get_admin.py Normal file
View File

@ -0,0 +1,19 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from telethon.tl.types import ChannelParticipantsAdmins
@borg.on(events.NewMessage(pattern=".get_admin", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.delete()
mentions = "**Admins in this Chat**: \n"
chat = await event.get_input_chat()
async for x in borg.iter_participants(chat, filter=ChannelParticipantsAdmins):
mentions += f"\n[{x.first_name}](tg://user?id={x.id})"
await borg.send_message(
chat, mentions, reply_to=event.message.reply_to_msg_id)

13
stdplugins/get_id.py Normal file
View File

@ -0,0 +1,13 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=r".get_id", outgoing=True))
async def _(event):
if event.fwd_from:
return
chat = await event.get_input_chat()
await event.edit("The current chat's ID is `{}`!".format(str(event.chat_id)))

124
stdplugins/get_telegraph.py Normal file
View File

@ -0,0 +1,124 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
from datetime import datetime
import requests
import mimetypes
current_date_time = "./../DOWNLOADS/"
@borg.on(events.NewMessage(pattern=r".telegraph media", outgoing=True))
async def _(event):
if event.fwd_from:
return
if not os.path.isdir(current_date_time):
os.makedirs(current_date_time)
if event.reply_to_msg_id:
start = datetime.now()
downloaded_file_name = await borg.download_media(
await event.get_reply_message(),
current_date_time
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Downloaded to {} in {} seconds.".format(downloaded_file_name, ms))
try:
start = datetime.now()
media_urls = upload_file(downloaded_file_name)
except TelegraphException as e:
await event.edit("ERROR: " + str(e))
os.remove(downloaded_file_name)
else:
end = datetime.now()
ms = (end - start).seconds
os.remove(downloaded_file_name)
await event.edit("Uploaded to {} in {} seconds.".format(media_urls[0], ms))
else:
await event.edit("Reply to a message to get a permanent telegra.ph link. (Inspired by @ControllerBot)")
""" The below lines copied from https://github.com/python273/telegraph/blob/master/telegraph/upload.py
"""
def upload_file(f):
""" Upload file to Telegra.ph's servers. Returns a list of links.
Allowed only .jpg, .jpeg, .png, .gif and .mp4 files.
:param f: filename or file-like object.
:type f: file, str or list
"""
with FilesOpener(f) as files:
response = requests.post(
'http://telegra.ph/upload',
files=files
).json()
if isinstance(response, list):
error = response[0].get('error')
else:
error = response.get('error')
if error:
raise TelegraphException(error)
return ["https://telegra.ph" + i['src'] for i in response]
class FilesOpener(object):
def __init__(self, paths, key_format='file{}'):
if not isinstance(paths, list):
paths = [paths]
self.paths = paths
self.key_format = key_format
self.opened_files = []
def __enter__(self):
return self.open_files()
def __exit__(self, type, value, traceback):
self.close_files()
def open_files(self):
self.close_files()
files = []
for x, file_or_name in enumerate(self.paths):
name = ''
if isinstance(file_or_name, tuple) and len(file_or_name) >= 2:
name = file_or_name[1]
file_or_name = file_or_name[0]
if hasattr(file_or_name, 'read'):
f = file_or_name
if hasattr(f, 'name'):
filename = f.name
else:
filename = name
else:
filename = file_or_name
f = open(filename, 'rb')
self.opened_files.append(f)
mimetype = mimetypes.MimeTypes().guess_type(filename)[0]
files.append(
(self.key_format.format(x), ('file{}'.format(x), f, mimetype))
)
return files
def close_files(self):
for f in self.opened_files:
f.close()
self.opened_files = []
class TelegraphException(Exception):
pass

11
stdplugins/help.py Normal file
View File

@ -0,0 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=r".helpme", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit('UserBot Powered by https://github.com/uniborg/uniborg')

24
stdplugins/json.py Normal file
View File

@ -0,0 +1,24 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from telethon.errors import MessageTooLongError
@borg.on(events.NewMessage(pattern=r"\.json", outgoing=True))
async def _(event):
if event.fwd_from:
return
if event.reply_to_msg_id:
previous_message = await event.get_reply_message()
try:
await event.edit(previous_message.stringify())
except MessageTooLongError as e:
await event.delete()
else:
try:
await event.edit(event.stringify())
except MessageTooLongError as e:
await event.delete()

42
stdplugins/kickdas.py Normal file
View File

@ -0,0 +1,42 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChannelBannedRights
from datetime import datetime, timedelta
from telethon.errors import UserAdminInvalidError
@borg.on(events.NewMessage(pattern=".kickdas", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Getting Participant Lists. This might take some time ...")
p = await borg.get_participants(event.chat_id, aggressive=True)
await event.edit("Searching through {} users for deleted accounts ...".format(len(p)))
c = 0
d = 0
e = []
for i in p:
#
# Note that it's "reversed". You must set to ``True`` the permissions
# you want to REMOVE, and leave as ``None`` those you want to KEEP.
rights = ChannelBannedRights(
until_date=None,
view_messages=True
)
if i.deleted:
d = d + 1
try:
await borg(EditBannedRequest(event.chat_id, i, rights))
c = c + 1
except UserAdminInvalidError as exc:
await event.edit("I need admin priveleges to perform this action!")
break
except:
e.append("ERROR")
await event.edit("Found {} Deleted Accounts. Kicked {} / {} users".format(d, c, len(p)))

View File

@ -0,0 +1,6 @@
# https://t.me/SnowballFight/257378
from telethon import events
from telethon.events import StopPropagation
@borg.on(events.NewMessage(chats=['@PublicTestGroup', '@SnowballFight', '@BotTalk']))
async def _(event):
raise StopPropagation

View File

@ -0,0 +1,22 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
import requests
import json
APP_ID = os.environ.get("OPEN_WEATHER_MAP_APPID")
@borg.on(events.NewMessage(pattern=r".weather (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
sample_url = "https://api.openweathermap.org/data/2.5/weather?q={}&APPID={}"
input_str = event.pattern_match.group(1)
response_api = requests.get(sample_url.format(input_str, APP_ID)).json()
if response_api["cod"] == 200:
await event.edit(input_str + "\n `" + json.dumps(response_api["main"]) + "`\n")
else:
await event.edit(response_api["message"])

16
stdplugins/ping.py Normal file
View File

@ -0,0 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
from datetime import datetime
@borg.on(events.NewMessage(pattern=r".ping", outgoing=True))
async def _(event):
if event.fwd_from:
return
start = datetime.now()
await event.edit('Pong!')
end = datetime.now()
ms = (end - start).microseconds / 1000
await event.edit('Pong!\n%sms' % (ms))

20
stdplugins/purge.py Normal file
View File

@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=".purge", outgoing=True))
async def _(event):
if event.fwd_from:
return
i = 1
msgs = []
async for message in borg.iter_messages(event.chat_id, min_id=event.reply_to_msg_id, from_user="me"):
i = i + 1
msgs.append(message)
if len(msgs) <= 100:
await borg.delete_messages(event.chat_id, msgs)
msgs = []
await event.delete()

View File

@ -0,0 +1,34 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
import requests
ACCESS_KEY = os.environ.get("SCREEN_SHOT_LAYER_ACCESS_KEY")
@borg.on(events.NewMessage(pattern=r".screencapture (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
sample_url = "https://api.screenshotlayer.com/api/capture?access_key={}&url={}"
input_str = event.pattern_match.group(1)
response_api = requests.get(sample_url.format(ACCESS_KEY, input_str), stream=True)
temp_file_name = "screenshotlayer.png"
with open(temp_file_name, "wb") as fd:
for chunk in response_api.iter_content(chunk_size=128):
fd.write(chunk)
try:
await borg.send_file(
event.chat_id,
temp_file_name,
caption=input_str,
force_document=True,
reply_to=event.message.reply_to_msg_id
)
await event.delete()
except:
await event.edit(response_api.text)
os.remove(temp_file_name)

View File

@ -7,7 +7,7 @@ from telethon.tl import types, functions
HEADER = "[[sed]]\n"
KNOWN_RE_BOTS = re.compile(
r'(regex|moku|BananaButler_|rgx|l4mR)bot',
r'(regex|moku|BananaButler_|rgx|l4mR|kochu|BanhammerMarie_)bot',
flags=re.IGNORECASE
)
@ -91,6 +91,7 @@ async def on_regex(event):
return
if not event.is_private and\
await group_has_sedbot(await event.get_input_chat()):
await event.edit("This group has a sed bot. Ignoring this message!")
return
chat_id = utils.get_peer_id(await event.get_input_chat())
@ -104,6 +105,6 @@ async def on_regex(event):
)
last_msgs[chat_id].appendleft(out)
elif s is not None:
await event.reply(s)
await event.edit(s)
raise events.StopPropagation

13
stdplugins/shrug_emoji.py Normal file
View File

@ -0,0 +1,13 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
@borg.on(events.NewMessage(pattern=r".shrug", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("¯\_(ツ)_/¯")

151
stdplugins/torrentz.py Normal file
View File

@ -0,0 +1,151 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
import requests
from datetime import datetime
import cfscrape # https://github.com/Anorov/cloudflare-scrape
from bs4 import BeautifulSoup
import urllib.parse
@borg.on(events.NewMessage(pattern=r".torrentz (.*) (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
start = datetime.now()
await event.edit("Processing ...")
input_type = event.pattern_match.group(1)
input_str = event.pattern_match.group(2)
search_results = []
if input_type == "torrentz2.eu":
search_results = Scrapper.SearchTorrentz(input_str)
elif input_type == "idop.se":
search_results = Scrapper.SearchIdopeSe(input_str)
output_str = ""
i = 0
for result in search_results:
if i > 5:
break
url = "`" + result["hash"] + "`"
message_text = " 👉🏻 " + result["title"] + ": " + url + " \r\n"
message_text += " FILE SIZE: " + result["size"] + "\r\n"
# message_text += " Uploaded " + result["date"] + "\r\n"
message_text += " SEEDS: " + result["seeds"] + " PEERS: " + result["peers"] + " \r\n"
message_text += "===\r\n"
output_str += message_text
i = i + 1
end = datetime.now()
ms = (end - start).seconds
await event.edit("Scrapped {} for {} in {} seconds. Obtained Results: \n {}".format(input_type, input_str, ms, output_str))
@borg.on(events.NewMessage(pattern=r".torrentz hash (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
start = datetime.now()
await event.edit("Processing ...")
input_str = event.pattern_match.group(1)
magnetic_link = Scrapper.GetMagneticLink(input_str)
end = datetime.now()
ms = (end - start).seconds
output_str = "Obtained Magnetic Link `{}` for the Info Hash: {} in {} seconds.".format(magnetic_link, input_str, ms)
await event.edit(output_str)
class Scrapper:
def SearchIdopeSe(search_query):
r = []
url = "https://idope.top/search/{}/".format(search_query)
raw_html = requests.get(url).content
soup = BeautifulSoup(raw_html, "html.parser")
results = soup.find_all("div", {"class": "resultdiv"})
for item in results:
""" The content scrapped on 12.08.2018 22:00:45
"""
title = item.find_all("div", {"class":"resultdivtopname"})[0].get_text().strip()
hash = item.find_all("div", {"class":"resultdivbottonseed"})[0].get_text().strip()
age = item.find_all("div", {"class":"resultdivbottontime"})[0].get_text().strip()
size = item.find_all("div", {"class":"resultdivbottonlength"})[0].get_text().strip()
r.append({
"title": title,
"hash": hash,
"age": age,
"size": size,
"seeds": "NA",
"peers": "NA"
})
return r
def SearchTorrentz(search_query):
r = []
url = "https://torrentz2.eu/searchA?safe=1&f=" + search_query + ""
scraper = cfscrape.create_scraper() # returns a CloudflareScraper instance
raw_html = scraper.get(url).content
# print(raw_html)
soup = BeautifulSoup(raw_html, "html.parser")
results = soup.find_all("div", {"class": "results"})[0]
for item in results.find_all("dl"):
# print(item)
"""The content scrapped on 23.06.2018 15:40:35
"""
dt = item.find_all("dt")[0]
dd = item.find_all("dd")[0]
#
try:
link_and_text = dt.find_all("a")[0]
link = link_and_text.get("href")[1:]
title = link_and_text.get_text()
span_elements = dd.find_all("span")
date = span_elements[1].get_text()
size = span_elements[2].get_text()
seeds = span_elements[3].get_text()
peers = span_elements[4].get_text()
#
r.append({
"title": title,
"hash": link,
"date": date,
"size": size,
"seeds": seeds,
"peers": peers
})
except:
pass
return r
def GetMagneticLink(info_hash):
name = "SpEcTorrentBot"
trackers = [
"udp://tracker.openbittorrent.com:80",
"udp://opentor.org:2710",
"udp://tracker.ccc.de:80",
"udp://tracker.blackunicorn.xyz:6969",
"udp://tracker.coppersurfer.tk:6969",
"udp://tracker.leechers-paradise.org:6969",
"udp://tracker.openbittorrent.com:80",
"udp://tracker.publicbt.com:80",
"udp://tracker.istole.it:80",
"udp://tracker.btzoo.eu:80/announce",
"http://opensharing.org:2710/announce",
"udp://open.demonii.com:1337/announce",
"http://announce.torrentsmd.com:8080/announce.php",
"http://announce.torrentsmd.com:6969/announce",
"http://bt.careland.com.cn:6969/announce",
"http://i.bandito.org/announce",
"http://bttrack.9you.com/announce",
];
data = ""
data += "magnet:"
data += "?xt=urn:btih:"
data += info_hash
data += "&dn="
data += urllib.parse.quote_plus(name)
data += ""
for tracker in trackers:
data += "&tr="
data += urllib.parse.quote_plus(tracker)
return data

39
stdplugins/tts.py Normal file
View File

@ -0,0 +1,39 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import requests
import os
from datetime import datetime
current_date_time = "./../DOWNLOADS/"
@borg.on(events.NewMessage(pattern=r".tts (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
input_str = event.pattern_match.group(1)
start = datetime.now()
tts_url = "https://tts.baidu.com/text2audio?lan={}&ie=UTF-8&text={}"
lan, text = input_str.split("|")
input_url = tts_url.format(lan.strip(), text.strip())
response = requests.get(input_url, stream=True)
required_file_name = current_date_time + "voice.ogg"
with open(required_file_name, "wb") as fd:
for chunk in response.iter_content(chunk_size=128):
fd.write(chunk)
await borg.send_file(
event.chat_id,
required_file_name,
reply_to=event.message.id,
allow_cache=False,
voice_note=True
)
os.remove(required_file_name)
end = datetime.now()
ms = (end - start).seconds
output_str = "Processed {} ({}) in {} seconds!"
await event.edit(output_str.format(text, lan, ms))

103
stdplugins/uploadownload.py Normal file
View File

@ -0,0 +1,103 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import os
import requests
from datetime import datetime
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
from telethon.tl.types import DocumentAttributeVideo
current_date_time = "./../DOWNLOADS/"
@borg.on(events.NewMessage(pattern=r".download (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
input_str = event.pattern_match.group(1)
if not os.path.isdir(current_date_time):
os.makedirs(current_date_time)
if event.reply_to_msg_id:
start = datetime.now()
downloaded_file_name = await borg.download_media(
await event.get_reply_message(),
current_date_time
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Downloaded to {} in {} seconds.".format(downloaded_file_name, ms))
elif input_str:
url, file_name = input_str.split("|")
await event.edit("Processing ...")
required_file_name = current_date_time + "" + file_name
start = datetime.now()
r = requests.get(url, stream=True)
with open(required_file_name, "wb") as fd:
for chunk in r.iter_content(chunk_size=128):
fd.write(chunk)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Downloaded to {} in {} seconds.".format(required_file_name, ms))
else:
await event.edit("Reply to a message to download to my local server.")
@borg.on(events.NewMessage(pattern=r".upload (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
input_str = event.pattern_match.group(1)
if os.path.exists(input_str):
start = datetime.now()
await borg.send_file(
event.chat_id,
input_str,
force_document=True,
allow_cache=False,
reply_to=event.message.id
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Uploaded in {} seconds.".format(ms))
else:
await event.edit("404: File Not Found")
@borg.on(events.NewMessage(pattern=r".uploadasstream (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
input_str = event.pattern_match.group(1)
if os.path.exists(input_str):
start = datetime.now()
metadata = extractMetadata(createParser(input_str))
await borg.send_file(
event.chat_id,
input_str,
caption=input_str,
force_document=False,
allow_cache=False,
reply_to=event.message.id,
attributes=[
DocumentAttributeVideo(
duration=metadata.get("duration").seconds,
w=metadata.get("width"),
h=metadata.get("height"),
round_message=False,
supports_streaming=True
)
]
)
end = datetime.now()
ms = (end - start).seconds
await event.edit("Uploaded in {} seconds.".format(ms))
else:
await event.edit("404: File Not Found")

View File

@ -0,0 +1,31 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from telethon import events
import urbandict
@borg.on(events.NewMessage(pattern="^.ud (.*)", outgoing=True))
async def _(event):
if event.fwd_from:
return
await event.edit("processing...")
str = event.pattern_match.group(1)
try:
mean = urbandict.define(str)
if len(mean) > 0:
await event.edit(
'Text: **' +
str +
'**\n\nMeaning: **' +
mean[0]['def'] +
'**\n\n' +
'Example: \n__' +
mean[0]['example'] +
'__'
)
else:
await event.edit("No result found for **" + str + "**")
except:
await event.edit("No result found for **" + str + "**")