fix
This commit is contained in:
parent
5147a56672
commit
865b642ac9
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
python-telegram-bot==22.0
|
||||
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from telegram.ext import Updater, CommandHandler, filters
|
||||
from telegram import Update
|
||||
from telegram.ext import Application, CommandHandler, filters
|
||||
import os
|
||||
from random import randrange
|
||||
import sys
|
||||
@ -8,7 +9,8 @@ import sys
|
||||
SAVED_PATH = '/var/lib/seshsecretary/saved.txt'
|
||||
CHATIDS_PATH = '/var/lib/seshsecretary/chatids.txt'
|
||||
|
||||
def _list(update, context):
|
||||
|
||||
async def _list(update, context):
|
||||
chat_id = update.effective_chat.id
|
||||
|
||||
if not check_chat_id(chat_id):
|
||||
@ -19,11 +21,11 @@ def _list(update, context):
|
||||
for line in f:
|
||||
response += line.split()[0] + "\n"
|
||||
if response == "":
|
||||
context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
|
||||
await context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN')
|
||||
else:
|
||||
context.bot.send_message(chat_id, response, 'MARKDOWN')
|
||||
await context.bot.send_message(chat_id, response, 'MARKDOWN')
|
||||
|
||||
def random(update, context):
|
||||
async def random(update, context):
|
||||
chat_id = update.effective_chat.id
|
||||
|
||||
if not check_chat_id(chat_id):
|
||||
@ -34,9 +36,9 @@ def random(update, context):
|
||||
message = lines[randrange(len(lines))]
|
||||
message_id = message.split()[1]
|
||||
from_chat_id = message.split()[2]
|
||||
context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||
await context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||
|
||||
def get(update, context):
|
||||
async def get(update, context):
|
||||
chat_id = update.effective_chat.id
|
||||
|
||||
if not check_chat_id(chat_id):
|
||||
@ -52,12 +54,12 @@ def get(update, context):
|
||||
break
|
||||
|
||||
if message_id == "":
|
||||
update.message.reply_text(
|
||||
await update.message.reply_text(
|
||||
"{} findes ik!".format(name))
|
||||
else:
|
||||
context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||
await context.bot.forward_message(chat_id, from_chat_id, message_id)
|
||||
|
||||
def save(update, context):
|
||||
async def save(update, context):
|
||||
chat_id = update.effective_chat.id
|
||||
|
||||
if not check_chat_id(chat_id):
|
||||
@ -74,9 +76,9 @@ def save(update, context):
|
||||
if cont:
|
||||
with open(SAVED_PATH, "a") as f:
|
||||
f.write(name + " " + str(message_id) + " " + str(chat_id) + "\n")
|
||||
update.message.reply_text(name + " er gemt!")
|
||||
await update.message.reply_text(name + " er gemt!")
|
||||
else:
|
||||
update.message.reply_text(name + " findes allerede :(")
|
||||
await update.message.reply_text(name + " findes allerede :(")
|
||||
|
||||
def main():
|
||||
if not os.path.isfile(SAVED_PATH):
|
||||
@ -88,15 +90,14 @@ def main():
|
||||
if token is None:
|
||||
sys.exit("Missing environment variable: SESHSECRETARY_TOKEN")
|
||||
|
||||
updater = Updater(token, use_context=True)
|
||||
application = Application.builder().token(token).build()
|
||||
|
||||
updater.dispatcher.add_handler(CommandHandler("list", _list))
|
||||
updater.dispatcher.add_handler(CommandHandler("get", get))
|
||||
updater.dispatcher.add_handler(CommandHandler("random", random))
|
||||
updater.dispatcher.add_handler(CommandHandler("save", save, filters.REPLY))
|
||||
application.add_handler(CommandHandler("list", _list))
|
||||
application.add_handler(CommandHandler("get", get))
|
||||
application.add_handler(CommandHandler("random", random))
|
||||
application.add_handler(CommandHandler("save", save, filters.REPLY))
|
||||
|
||||
updater.start_polling()
|
||||
updater.idle()
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
||||
def check_chat_id(chatid):
|
||||
with open(CHATIDS_PATH) as f:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user