update python-telegram-bot API
This commit is contained in:
parent
94ab4bed13
commit
1875ba2f7b
3 changed files with 16 additions and 10 deletions
|
@ -41,7 +41,7 @@ You can use the content of the *mastodon-bot* directory to create your own Masto
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
Copyright 2003-2018 Davide Alberani <da@erlug.linux.it>
|
Copyright 2003-2021 Davide Alberani <da@erlug.linux.it>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -9,6 +9,8 @@ RUN \
|
||||||
git clone https://github.com/alberanid/fortunes-spam.git
|
git clone https://github.com/alberanid/fortunes-spam.git
|
||||||
COPY fortunes-spam-bot.py /fortunes-spam
|
COPY fortunes-spam-bot.py /fortunes-spam
|
||||||
|
|
||||||
|
VOLUME /fortunes
|
||||||
|
|
||||||
WORKDIR /fortunes-spam
|
WORKDIR /fortunes-spam
|
||||||
|
|
||||||
ENTRYPOINT ["python3", "fortunes-spam-bot.py"]
|
ENTRYPOINT ["python3", "fortunes-spam-bot.py"]
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
Build it with: docker build -t fortunes-spam-bot .
|
Build it with: docker build -t fortunes-spam-bot .
|
||||||
Run it with something like: docker run -ti --rm -e SPAMBOT_TOKEN=your-telegram-token fortunes-spam-bot
|
Run it with something like: docker run -ti --rm -e SPAMBOT_TOKEN=your-telegram-token fortunes-spam-bot
|
||||||
|
|
||||||
Copyright 2018 Davide Alberani <da@erlug.linux.it> Apache 2.0 license
|
Copyright 2018-2021 Davide Alberani <da@erlug.linux.it> Apache 2.0 license
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -17,8 +17,12 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
EXTERNAL_VOL = '/fortunes'
|
||||||
|
|
||||||
def getSpam(section):
|
def getSpam(section):
|
||||||
|
extPath = os.path.join(EXTERNAL_VOL, section)
|
||||||
|
if os.path.isfile(extPath):
|
||||||
|
section = extPath
|
||||||
cmd = ['fortune', '-o', section]
|
cmd = ['fortune', '-o', section]
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
|
@ -35,22 +39,22 @@ def getSpam(section):
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
||||||
def serve(section, bot, update):
|
def serve(section, update, context):
|
||||||
spam = getSpam(section)
|
spam = getSpam(section)
|
||||||
logging.info('%s wants some spam; serving:\n%s' % (update.message.from_user.name, spam))
|
logging.info('%s wants some spam; serving:\n%s' % (update.effective_user.username, spam))
|
||||||
update.message.reply_text(spam)
|
update.message.reply_text(spam)
|
||||||
|
|
||||||
|
|
||||||
def en(bot, update):
|
def en(update, context):
|
||||||
return serve('spam-o', bot, update)
|
return serve('spam-o', update, context)
|
||||||
|
|
||||||
|
|
||||||
def it(bot, update):
|
def it(update, context):
|
||||||
return serve('spam-ita-o', bot, update)
|
return serve('spam-ita-o', update, context)
|
||||||
|
|
||||||
|
|
||||||
def about(bot, update):
|
def about(update, context):
|
||||||
logging.info('%s required more info' % update.message.from_user.name)
|
logging.info('%s required more info' % update.effective_user.username)
|
||||||
update.message.reply_text('See https://github.com/alberanid/fortunes-spam')
|
update.message.reply_text('See https://github.com/alberanid/fortunes-spam')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue