Skip to content

Commit

Permalink
0.6.2, different refinements and help handle in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gpchelkin committed Jul 3, 2017
1 parent fcba4a2 commit 34de090
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
11 changes: 11 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
History
=======

0.6.2 (2017-07-04)
------------------

* Help message in groups now redirects to PM

0.6.1 (2017-07-03)
------------------

* Async run of download/send command
* Link command

0.6.0 (2017-07-02)
------------------

Expand Down
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ Optional
- ``USE_WEBHOOK``: use webhook for bot updates: ``1``, use polling
(default): ``0``, `more
info <https://core.telegram.org/bots/api#getting-updates>`__
- ``PORT``: Heroku sets this automatically for web dynos if you are
using webhook
- ``APP_URL``: Heroku App URL like
- ``APP_URL``: app URL like
``https://<appname>.herokuapp.com/``, required for webhook
- ``PORT``: port for webhook to listen to; Heroku sets this automatically
for web dynos
- ``BOTAN_TOKEN``: `Botan.io <http://botan.io/>`__
`token <http://appmetrica.yandex.com/>`__
- ``NO_CLUTTER_CHAT_IDS``: Comma-separated chat IDs with no replying
Expand All @@ -117,6 +117,8 @@ Optional
(user's home directory)
- ``SYSLOG_ADDRESS``: Syslog server, for example ``logsX.papertrailapp.com:ABCDE``
- ``HOSTNAME``: Hostname to show up in Syslog messages
- ``GOOGL_API_KEY``: `Goo.gl URL shortener <https://goo.gl>`__
`API key <https://developers.google.com/url-shortener/v1/getting_started#APIKey>`__

Telegram Settings
^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion scdlbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# version as tuple for simple comparisons
VERSION = (0, 6, 0)
VERSION = (0, 6, 2)
# string created from tuple to avoid inconsistency
__version__ = ".".join([str(x) for x in VERSION])
12 changes: 6 additions & 6 deletions scdlbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
SYSLOG_ADDRESS = os.getenv('SYSLOG_ADDRESS', '')
if SYSLOG_ADDRESS:
syslog_hostname, syslog_udp_port = SYSLOG_ADDRESS.split(":")
syslog_udp_port = int(syslog_udp_port)
syslog_handler = SysLogHandler(address=(syslog_hostname, syslog_udp_port))
syslog_handler = SysLogHandler(address=(syslog_hostname, int(syslog_udp_port)))
logging_handlers.append(syslog_handler)

logging.basicConfig(format='%(asctime)s {} %(name)s: %(message)s'.format(os.getenv("HOSTNAME", "unknown_host")),
logging.basicConfig(format='%(asctime)s {} %(name)s: %(message)s'.format(os.getenv("HOSTNAME", "test-host")),
datefmt='%b %d %H:%M:%S',
level=logging.DEBUG, handlers=logging_handlers)
level=logging.DEBUG,
handlers=logging_handlers)

logger = logging.getLogger(__name__)

Expand All @@ -32,14 +32,14 @@ def main():
dl_dir = os.path.expanduser(os.getenv('DL_DIR', '~'))
use_webhook = bool(int(os.getenv('USE_WEBHOOK', '0')))
app_url = os.getenv('APP_URL', '')
app_port = int(os.getenv('PORT', '5000'))
webhook_port = int(os.getenv('PORT', '5000'))
bin_path = os.getenv('BIN_PATH', '')
cert_file = os.getenv('CERT_FILE', '')
google_shortener_api_key = os.getenv('GOOGL_API_KEY', '') # https://developers.google.com/url-shortener/v1/getting_started#APIKey
scdlbot = SCDLBot(tg_bot_token, botan_token, google_shortener_api_key, bin_path,
sc_auth_token, store_chat_id,
no_clutter_chat_ids, dl_dir)
scdlbot.run(use_webhook, app_url, app_port, cert_file)
scdlbot.run(use_webhook, app_url, webhook_port, cert_file)


if __name__ == '__main__':
Expand Down
26 changes: 15 additions & 11 deletions scdlbot/scdlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from urllib.parse import urljoin
from urllib.request import URLopener
from uuid import uuid4
from time import sleep

import mutagen.id3
import pkg_resources
import youtube_dl
Expand Down Expand Up @@ -97,14 +97,14 @@ def __init__(self, tg_bot_token, botan_token, google_shortener_api_key, bin_path

dispatcher.add_error_handler(self.error_callback)

self.bot_username = "@scdlbot" # self.updater.bot.get_me().username
self.RANT_TEXT = "[PLEASE PRESS HERE TO READ HELP IN MY PM](t.me/" + bot_username + "?start=1)"
self.bot_username = self.updater.bot.get_me().username
self.RANT_TEXT = "[PRESS HERE TO READ HELP IN PM](t.me/" + self.bot_username + "?start=1)"

def run(self, use_webhook=False, app_url=None, app_port=None, cert_file=None):
def run(self, use_webhook=False, app_url=None, webhook_port=None, cert_file=None):
if use_webhook:
url_path = self.tg_bot_token.replace(":", "")
self.updater.start_webhook(listen="0.0.0.0",
port=app_port,
port=webhook_port,
url_path=url_path)
self.updater.bot.set_webhook(url=urljoin(app_url, url_path))
# ... certificate=open(cert_file, 'rb')
Expand Down Expand Up @@ -164,10 +164,11 @@ def rant_and_cleanup(self, bot, chat_id, rant_text):
self.rant_msg_ids[chat_id].append(rant_msg.message_id)

def help_command_callback(self, bot, update, event_name="help"):
chat_id = update.message.chat_id
logger.debug(event_name)
self.botan.track(update.message, event_name) if self.botan else None
if update.message.chat.type == "private":
bot.send_message(chat_id=update.message.chat_id, text=self.HELP_TEXT,
bot.send_message(chat_id=chat_id, text=self.HELP_TEXT,
parse_mode='Markdown', disable_web_page_preview=True)
else:
self.rant_and_cleanup(bot, chat_id, self.RANT_TEXT)
Expand All @@ -178,11 +179,11 @@ def clutter_command_callback(self, bot, update):
self.botan.track(update.message, event_name) if self.botan else None
if update.message.chat_id in self.NO_CLUTTER_CHAT_IDS:
self.NO_CLUTTER_CHAT_IDS.remove(update.message.chat_id)
bot.send_message(chat_id=update.message.chat_id, text="Chat will be cluttered with replies",
bot.send_message(chat_id=update.message.chat_id, text="Chat will now be cluttered with replies",
parse_mode='Markdown', disable_web_page_preview=True)
else:
self.NO_CLUTTER_CHAT_IDS.append(update.message.chat_id)
bot.send_message(chat_id=update.message.chat_id, text="Chat will not be cluttered with replies",
bot.send_message(chat_id=update.message.chat_id, text="Chat will now NOT be cluttered with replies",
parse_mode='Markdown', disable_web_page_preview=True)

def inline_query_callback(self, bot, update):
Expand Down Expand Up @@ -280,10 +281,13 @@ def message_callback(self, bot, update):

def youtube_dl_get_direct_urls(self, url):
try:
direct_urls = self.youtube_dl("--get-url", url)
ret_code, direct_urls, std_err = self.youtube_dl["--get-url", url].run()
if "returning it as such" in std_err:
return None
else:
return direct_urls
except:
direct_urls = None
return direct_urls
return None

def prepare_urls(self, text, get_direct_urls=False):
urls = find_all_links(text, default_scheme="http")
Expand Down
21 changes: 10 additions & 11 deletions scdlbot/texts/help.tg.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
*I download and send audios of videos/tracks/sets/albums in MP3 128 kbps with tags and artwork. Files over 50 MB are split into parts due to bot-sent file size limit. Supported sites:*
I download and send audios of videos/tracks/sets/albums in MP3 128 kbps with tags and artwork. Files over 50 MB are split into parts due to bot-sent file size limit. Supported links:
*• SoundCloud*: tracks/playlists/pages with private widgets
*• Bandcamp*: tracks/albums
*• Bandcamp*: tracks/albums/custom links
*• YouTube*: videos/playlists
*• Mixcloud, Vimeo and pretty much* [everything from the list](https://rg3.github.io/youtube-dl/supportedsites.html)
*• Mixcloud, Vimeo and* [everything from this list](https://rg3.github.io/youtube-dl/supportedsites.html) (no VK music)

*Usage:*
• Send a message with links to the chat and I will download them instantly in private or ask you in groups. [Privacy mode](https://core.telegram.org/bots#privacy-mode) is _disabled_ so I parse all group messages for links. Forwarded messages work too. For example:
`Check it out! https://m.soundcloud.com/richarddjames/umil-25-01 and also https://shitmat.bandcamp.com/track/amen-babylon-2016-mix`
• Use `/dl <link(-s)>` command to download instantly in groups.
• Use `/link <link(-s)>` command to get URL for downloading locally.
• Use `/dl <links>` to download instantly in groups.
• Use `/link <links>` to just get URL for downloading.

🤖 @gpchelkin //[🐝👍.WS](http://xn--lo8h6c.ws/)
🖼️ @lowonbudget //[👩‍🎨🎨️](https://www.behance.net/lowonbudget)
🖤 @electrocircle //[⚡⚫.РФ](http://Электрокружок.РФ)
[🌟GitHub](https://github.com/gpchelkin/scdlbot) // [💻Issues](https://github.com/gpchelkin/scdlbot/issues)

Not mine: @vkm\_bot @scloud\_bot @GetMusicBot
*Credits // Emoji-links:*
[🌟 @GitHub](https://github.com/gpchelkin/scdlbot) // [⌨️⚠](https://github.com/gpchelkin/scdlbot/issues)
👨🏻‍💻 @gpchelkin // [🐝👍](http://xn--lo8h6c.ws/)
👩🏻‍🎨 @lowonbudget // [🎨🖼️](https://www.behance.net/lowonbudget)
🎶 @electrocircle // [⚡⚫](http://Электрокружок.РФ)

0 comments on commit 34de090

Please sign in to comment.