1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-25 15:24:17 +00:00

Add "Add Credit" menu

This commit is contained in:
Steffo 2017-12-26 18:15:30 +01:00
parent 782e036be3
commit 2720d96c57
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
5 changed files with 74 additions and 11 deletions

View file

@ -3,7 +3,7 @@
# Config file parameters
[Config]
; Config file version. DO NOT EDIT THIS!
version = 4
version = 5
; Set this to no when you are done editing the file
is_template = yes
@ -21,3 +21,10 @@ long_polling_timeout = 30
[Database]
; The database engine you want to use. Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
engine = sqlite://
# Enabled payment methods
# To disable, leave the row empty
[Payment Methods]
# Cash payment is always enabled
# Credit card: get the token at @BotFather
credit_card_token = 123456789:YOUR_TOKEN_HERE_

View file

@ -94,7 +94,7 @@ def main():
# Ensure a worker exists for the chat and is alive
if receiving_worker is None or not receiving_worker.is_alive():
# Suggest that the user restarts the chat with /start
bot.send_message(update.message.chat.id, strings.error_no_worker_for_chat, telegram.ReplyKeyboardRemove())
bot.send_message(update.message.chat.id, strings.error_no_worker_for_chat, reply_markup=telegram.ReplyKeyboardRemove())
# Skip the update
continue
# Forward the update to the worker

View file

@ -128,6 +128,12 @@ class Transaction(TableDeclarativeBase):
return f"<Transaction {self.transaction_id} - User {self.user_id} {str(self)}>"
# TODO
# class Order(TableDeclarativeBase):
# """A product order."""
# pass
class Admin(TableDeclarativeBase):
"""A greed administrator with his permissions."""

View file

@ -11,16 +11,19 @@ currency_format_string = "{symbol} {value}"
# Quantity of a product in stock
in_stock_format_string = "{quantity} disponibili"
# Answer: the start command was sent and the bot should welcome the user
# Conversation: the start command was sent and the bot should welcome the user
conversation_after_start = "Ciao!\n" \
"Benvenuto su greed!"
# Answer: to send an inline keyboard you need to send a message with it
# Conversation: to send an inline keyboard you need to send a message with it
conversation_open_user_menu = "Allora, {username}, cosa vorresti fare?"
# Answer: the same message as above but when the first has already been sent
# Conversation: the same message as above but when the first has already been sent
conversation_open_user_menu_multiple = "Hai bisogno di qualcos'altro?"
# Conversation: select a payment method
conversation_payment_method = "Come vuoi aggiungere fondi al tuo portafoglio?"
# Notification: the conversation has expired
conversation_expired = "🕐 Il bot non ha ricevuto messaggi per un po' di tempo, quindi ha chiuso la conversazione.\n" \
"Per riavviarne una nuova, invia il comando /start."
@ -33,11 +36,24 @@ menu_order = "🛍 Ordina"
menu_order_status = "❓ Stato ordini"
# User menu: add credit
menu_add_credit = "💵 Ricarica"
menu_add_credit = "💵 Aggiungi fondi"
# User menu: bot info
menu_bot_info = " Informazioni sul bot"
# User menu: cash
menu_cash = "💵 In contanti"
# User menu: credit card
menu_credit_card = "💳 Con una carta di credito"
# User menu: cancel
menu_cancel = "🔙 Annulla"
# Payment: cash payment info
payment_cash = "Puoi pagare in contanti alla sede fisica del negozio.\n" \
"Il gestore provvederà ad aggiungere credito al tuo account appena gli avrai consegnato i soldi."
# Info: informazioni sul bot
bot_info = 'Questo bot utilizza <a href="https://github.com/Steffo99/greed">greed</a>,' \
' un framework di @Steffo per i pagamenti su Telegram rilasciato sotto la' \

View file

@ -106,7 +106,6 @@ class ChatWorker(threading.Thread):
self.bot.send_message(self.chat.id, strings.conversation_open_user_menu.format(username=str(self.user)),
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
# Wait for a reply from the user
# TODO: change this
selection = self.__wait_for_specific_message([strings.menu_order, strings.menu_order_status,
strings.menu_add_credit, strings.menu_bot_info])
# If the user has selected the Order option...
@ -133,6 +132,41 @@ class ChatWorker(threading.Thread):
raise NotImplementedError()
def __add_credit_menu(self):
"""Add more credit to the account."""
# TODO: a loop might be needed here
# Create a payment methods keyboard
keyboard = list()
# Add the supported payment methods to the keyboard
# Cash
keyboard.append([telegram.KeyboardButton(strings.menu_cash)])
# Telegram Payments
if configloader.config["Payment Methods"]["credit_card_token"] != "":
keyboard.append([telegram.KeyboardButton(strings.menu_credit_card)])
# Keyboard: go back to the previous menu
keyboard.append([telegram.KeyboardButton(strings.menu_cancel)])
# Send the keyboard to the user
self.bot.send_message(self.chat.id, strings.conversation_payment_method,
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
# Wait for a reply from the user
selection = self.__wait_for_specific_message([strings.menu_cash, strings.menu_credit_card, strings.menu_cancel])
# If the user has selected the Cash option...
if selection == strings.menu_cash:
# Go to the pay with cash function
self.__add_credit_cash()
# If the user has selected the Credit Card option...
elif selection == strings.menu_credit_card:
# Go to the pay with credit card function
self.__add_credit_cc()
# If the user has selected the Cancel option...
elif selection == strings.menu_add_credit:
# Send him back to the previous menu
return
def __add_credit_cash(self):
"""Tell the user how to pay with cash at this shop"""
self.bot.send_message(self.chat.id, strings.payment_cash)
def __add_credit_cc(self):
raise NotImplementedError()
def __bot_info(self):
@ -142,12 +176,12 @@ class ChatWorker(threading.Thread):
def __admin_menu(self):
"""Function called from the run method when the user is an administrator.
Administrative bot actions should be placed here."""
self.bot.send_message(self.chat.id, "Sei un Amministralol")
raise NotImplementedError()
def __graceful_stop(self):
"""Handle the graceful stop of the thread."""
# Notify the user that the session has expired
self.bot.send_message(self.chat.id, strings.conversation_expired)
# Notify the user that the session has expired and remove the keyboard
self.bot.send_message(self.chat.id, strings.conversation_expired, reply_markup=telegram.ReplyKeyboardRemove())
# Close the database session
# End the process
sys.exit(0)