mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-21 21:44:19 +00:00
Unfinished stuff
This commit is contained in:
parent
12da94eea2
commit
d552b88166
3 changed files with 51 additions and 24 deletions
|
@ -194,9 +194,9 @@ class Admin(TableDeclarativeBase):
|
||||||
user_id = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
|
user_id = Column(BigInteger, ForeignKey("users.user_id"), primary_key=True)
|
||||||
user = relationship("User")
|
user = relationship("User")
|
||||||
# Permissions
|
# Permissions
|
||||||
edit_products = Column(Boolean, default=True)
|
edit_products = Column(Boolean, default=False)
|
||||||
receive_orders = Column(Boolean, default=True)
|
receive_orders = Column(Boolean, default=False)
|
||||||
create_transactions = Column(Boolean, default=True)
|
create_transactions = Column(Boolean, default=False)
|
||||||
display_on_help = Column(Boolean, default=False)
|
display_on_help = Column(Boolean, default=False)
|
||||||
is_owner = Column(Boolean, default=False)
|
is_owner = Column(Boolean, default=False)
|
||||||
# Live mode enabled
|
# Live mode enabled
|
||||||
|
|
18
strings.py
18
strings.py
|
@ -210,6 +210,12 @@ emoji_completed = "✅"
|
||||||
# Emoji: refunded order
|
# Emoji: refunded order
|
||||||
emoji_refunded = "✴️"
|
emoji_refunded = "✴️"
|
||||||
|
|
||||||
|
# Emoji: yes
|
||||||
|
emoji_yes = "✅"
|
||||||
|
|
||||||
|
# Emoji: no
|
||||||
|
emoji_no = "🚫"
|
||||||
|
|
||||||
# Text: unprocessed order
|
# Text: unprocessed order
|
||||||
text_not_processed = "in sospeso"
|
text_not_processed = "in sospeso"
|
||||||
|
|
||||||
|
@ -257,6 +263,18 @@ ask_credit = "Di quanto vuoi modificare il credito del cliente?\n" \
|
||||||
"Metti un segno </i><code>+</code><i> se vuoi aggiungere credito all'account del cliente," \
|
"Metti un segno </i><code>+</code><i> se vuoi aggiungere credito all'account del cliente," \
|
||||||
" oppure un segno </i><code>-</code><i> se vuoi dedurlo.</i>"
|
" oppure un segno </i><code>-</code><i> se vuoi dedurlo.</i>"
|
||||||
|
|
||||||
|
# Edit admin: can edit products?
|
||||||
|
ask_edit_products = "Vuoi che l'amministratore sia autorizzato a modificare la configurazione dei prodotti?"
|
||||||
|
|
||||||
|
# Edit admin: can receive orders?
|
||||||
|
ask_receive_orders = "Vuoi che l'amministratore sia autorizzato a ricevere e gestire gli ordini?"
|
||||||
|
|
||||||
|
# Edit admin: can create transactions?
|
||||||
|
ask_create_transactions = "Vuoi che l'amministratore sia autorizzato a creare nuove transazioni?"
|
||||||
|
|
||||||
|
# Edit admin: should be displayed on help
|
||||||
|
ask_display_on_help = "Vuoi che l'amministratore venga visualizzato nella sezione Contatta il negozio?"
|
||||||
|
|
||||||
# Thread has started downloading an image and might be unresponsive
|
# Thread has started downloading an image and might be unresponsive
|
||||||
downloading_image = "Sto scaricando la tua foto!\n" \
|
downloading_image = "Sto scaricando la tua foto!\n" \
|
||||||
"Potrei metterci un po'... Abbi pazienza!\n" \
|
"Potrei metterci un po'... Abbi pazienza!\n" \
|
||||||
|
|
51
worker.py
51
worker.py
|
@ -250,6 +250,34 @@ class ChatWorker(threading.Thread):
|
||||||
# Return the callbackquery
|
# Return the callbackquery
|
||||||
return update.callback_query
|
return update.callback_query
|
||||||
|
|
||||||
|
def __user_select(self) -> typing.Union[db.User, CancelSignal]:
|
||||||
|
"""Select an user from the ones in the database."""
|
||||||
|
# Find all the users in the database
|
||||||
|
users = self.session.query(db.User).order_by(db.User.user_id).all()
|
||||||
|
# Create a list containing all the keyboard button strings
|
||||||
|
keyboard_buttons = [[strings.menu_cancel]]
|
||||||
|
# Add to the list all the users
|
||||||
|
for user in users:
|
||||||
|
keyboard_buttons.append([user.identifiable_str()])
|
||||||
|
# Create the keyboard
|
||||||
|
keyboard = telegram.ReplyKeyboardMarkup(keyboard_buttons, one_time_keyboard=True)
|
||||||
|
# Keep asking until a result is returned
|
||||||
|
while True:
|
||||||
|
# Send the keyboard
|
||||||
|
self.bot.send_message(self.chat.id, strings.conversation_admin_select_user, reply_markup=keyboard)
|
||||||
|
# Wait for a reply
|
||||||
|
reply = self.__wait_for_regex("user_([0-9]+)", cancellable=True)
|
||||||
|
# Allow the cancellation of the operation
|
||||||
|
if reply == strings.menu_cancel:
|
||||||
|
return CancelSignal()
|
||||||
|
# Find the user in the database
|
||||||
|
user = self.session.query(db.User).filter_by(user_id=int(reply)).one_or_none()
|
||||||
|
# Ensure the user exists
|
||||||
|
if not user:
|
||||||
|
self.bot.send_message(self.chat.id, strings.error_user_does_not_exist)
|
||||||
|
continue
|
||||||
|
return user
|
||||||
|
|
||||||
def __user_menu(self):
|
def __user_menu(self):
|
||||||
"""Function called from the run method when the user is not an administrator.
|
"""Function called from the run method when the user is not an administrator.
|
||||||
Normal bot actions should be placed here."""
|
Normal bot actions should be placed here."""
|
||||||
|
@ -924,27 +952,8 @@ class ChatWorker(threading.Thread):
|
||||||
|
|
||||||
def __create_transaction(self):
|
def __create_transaction(self):
|
||||||
"""Edit manually the credit of an user."""
|
"""Edit manually the credit of an user."""
|
||||||
# Find all the users in the database
|
# Make the admin select an user
|
||||||
users = self.session.query(db.User).order_by(db.User.user_id).all()
|
user = self.__user_select()
|
||||||
# Create a list containing all the keyboard button strings
|
|
||||||
keyboard_buttons = [[strings.menu_cancel]]
|
|
||||||
# Add to the list all the users
|
|
||||||
for user in users:
|
|
||||||
keyboard_buttons.append([user.identifiable_str()])
|
|
||||||
# Create the keyboard
|
|
||||||
keyboard = telegram.ReplyKeyboardMarkup(keyboard_buttons, one_time_keyboard=True)
|
|
||||||
# Send the keyboard
|
|
||||||
self.bot.send_message(self.chat.id, strings.conversation_admin_select_user, reply_markup=keyboard)
|
|
||||||
# Wait for a reply
|
|
||||||
reply = self.__wait_for_regex("user_([0-9]+)", cancellable=True)
|
|
||||||
# Allow the cancellation of the operation
|
|
||||||
if reply == strings.menu_cancel:
|
|
||||||
return
|
|
||||||
# Find the user in the database
|
|
||||||
user = self.session.query(db.User).filter_by(user_id=int(reply)).one_or_none()
|
|
||||||
# Ensure the user exists
|
|
||||||
if not user:
|
|
||||||
self.bot.send_message(self.chat.id, strings.error_user_does_not_exist)
|
|
||||||
# Create an inline keyboard with a single cancel button
|
# Create an inline keyboard with a single cancel button
|
||||||
cancel = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton(strings.menu_cancel,
|
cancel = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton(strings.menu_cancel,
|
||||||
callback_data="cmd_cancel")]])
|
callback_data="cmd_cancel")]])
|
||||||
|
|
Loading…
Reference in a new issue