Upgrade for v20.x of telegram bot module

This commit is contained in:
Gürkan 2023-06-26 22:34:51 +02:00
parent 6cbbd71543
commit 9033a5d188
2 changed files with 19 additions and 36 deletions

View File

@ -6,15 +6,16 @@ import logging
from uuid import uuid4
from os import getenv
from telegram.ext import (
Updater,
Application,
CommandHandler,
MessageHandler,
Filters,
filters,
InlineQueryHandler,
)
from telegram import InlineQueryResultArticle, InputTextMessageContent
from kufur import kufur
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@ -24,21 +25,17 @@ logging.basicConfig(
logger = logging.getLogger(__name__)
def start(bot, update):
bot.message.reply_text(
async def start(update, context):
await context.bot.send_message(chat_id=update.message.chat_id, text=(
"Hoşgeldin. Bu bot tüm mesajlarına küfürle karşılık verir."
)
))
def echo(bot, update):
bot.message.reply_text(kufur())
async def echo(update, context):
await context.bot.send_message(chat_id=update.effective_chat.id, text=kufur())
def error(bot, update, error):
logger.warn('Update "%s" caused error "%s"' % (update, error))
def inline_caps(update, context):
async def inline_caps(update, context):
query = update.inline_query.query
if not query:
query = str(uuid4())
@ -53,38 +50,24 @@ def inline_caps(update, context):
)
)
)
update.inline_query.answer(results, cache_time=2)
await context.bot.answer_inline_query(update.inline_query.id, results)
def main():
# Create the EventHandler and pass it your bot's token.
updater = Updater(
getenv('TELEGRAM_TOKEN'),
use_context=True
)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp = Application.builder().token(getenv('TELEGRAM_TOKEN')).build() # type: ignore
# on different commands - answer in Telegram
dp.add_handler(CommandHandler("start", start))
start_handler = CommandHandler("start", start)
dp.add_handler(start_handler)
# inline_caps_handler = InlineQueryHandler(inline_caps)
dp.add_handler(InlineQueryHandler(inline_caps))
inline_caps_handler = InlineQueryHandler(inline_caps)
dp.add_handler(inline_caps_handler)
# on noncommand i.e message - echo the message on Telegram
dp.add_handler(MessageHandler(Filters.text, echo))
# log all errors
dp.add_error_handler(error)
echo_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), echo)
dp.add_handler(echo_handler)
# Start the Bot
updater.start_polling()
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
dp.run_polling()
if __name__ == '__main__':

View File

@ -6,7 +6,7 @@ from sysconfig import get_paths
setup(
name='kufur-generator',
version='1.0',
version='1.1',
description='Turkce kufur ureteci',
author='seqizz',
include_package_data=True,