mirror of
https://github.com/Steffo99/greed.git
synced 2024-12-04 11:24:19 +00:00
Reformat code using PyCharm
This commit is contained in:
parent
6a49756394
commit
177f5b3507
12 changed files with 173 additions and 157 deletions
|
@ -1,24 +1,24 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Run greed" type="PythonConfigurationType" factoryName="Python">
|
<configuration default="false" name="Run greed" type="PythonConfigurationType" factoryName="Python">
|
||||||
<module name="greed" />
|
<module name="greed"/>
|
||||||
<option name="INTERPRETER_OPTIONS" value="" />
|
<option name="INTERPRETER_OPTIONS" value=""/>
|
||||||
<option name="PARENT_ENVS" value="true" />
|
<option name="PARENT_ENVS" value="true"/>
|
||||||
<envs>
|
<envs>
|
||||||
<env name="PYTHONUNBUFFERED" value="1" />
|
<env name="PYTHONUNBUFFERED" value="1"/>
|
||||||
</envs>
|
</envs>
|
||||||
<option name="SDK_HOME" value="" />
|
<option name="SDK_HOME" value=""/>
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$"/>
|
||||||
<option name="IS_MODULE_SDK" value="true" />
|
<option name="IS_MODULE_SDK" value="true"/>
|
||||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
<option name="ADD_CONTENT_ROOTS" value="true"/>
|
||||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
<option name="ADD_SOURCE_ROOTS" value="true"/>
|
||||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py"/>
|
||||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/core.py" />
|
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/core.py"/>
|
||||||
<option name="PARAMETERS" value="" />
|
<option name="PARAMETERS" value=""/>
|
||||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
<option name="SHOW_COMMAND_LINE" value="false"/>
|
||||||
<option name="EMULATE_TERMINAL" value="false" />
|
<option name="EMULATE_TERMINAL" value="false"/>
|
||||||
<option name="MODULE_MODE" value="false" />
|
<option name="MODULE_MODE" value="false"/>
|
||||||
<option name="REDIRECT_INPUT" value="false" />
|
<option name="REDIRECT_INPUT" value="false"/>
|
||||||
<option name="INPUT_FILE" value="" />
|
<option name="INPUT_FILE" value=""/>
|
||||||
<method v="2" />
|
<method v="2"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
|
@ -2,99 +2,99 @@
|
||||||
|
|
||||||
# Language parameters
|
# Language parameters
|
||||||
[Language]
|
[Language]
|
||||||
# Available languages:
|
# Available languages:
|
||||||
# it - Italian, by https://github.com/Steffo99
|
# it - Italian, by https://github.com/Steffo99
|
||||||
# en - English, by https://github.com/DarrenWestwood
|
# en - English, by https://github.com/DarrenWestwood
|
||||||
# uk - Ukrainian, by https://github.com/pzhuk
|
# uk - Ukrainian, by https://github.com/pzhuk
|
||||||
# ru - Russian, by https://github.com/pzhuk
|
# ru - Russian, by https://github.com/pzhuk
|
||||||
# zh_cn - Simplified Chinese, by https://github.com/zhihuiyuze
|
# zh_cn - Simplified Chinese, by https://github.com/zhihuiyuze
|
||||||
# he - Hebrew, by https://github.com/netanelkoli
|
# he - Hebrew, by https://github.com/netanelkoli
|
||||||
# The lanugages that messages can be displayed in
|
# The lanugages that messages can be displayed in
|
||||||
enabled_languages = ["it", "en", "uk", "ru", "zh_cn", "he"]
|
enabled_languages = ["it", "en", "uk", "ru", "zh_cn", "he"]
|
||||||
# The default language to be set for users whose language cannot be autodetected or whose language is not enabled
|
# The default language to be set for users whose language cannot be autodetected or whose language is not enabled
|
||||||
default_language = "it"
|
default_language = "it"
|
||||||
# The language to fallback to if a string is missing in a specific language
|
# The language to fallback to if a string is missing in a specific language
|
||||||
fallback_language = "en"
|
fallback_language = "en"
|
||||||
|
|
||||||
|
|
||||||
# Database parameters
|
# Database parameters
|
||||||
[Database]
|
[Database]
|
||||||
# The database engine you want to use.
|
# The database engine you want to use.
|
||||||
# Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
|
# Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
|
||||||
engine = "sqlite:///database.sqlite"
|
engine = "sqlite:///database.sqlite"
|
||||||
|
|
||||||
|
|
||||||
# Telegram bot parameters
|
# Telegram bot parameters
|
||||||
[Telegram]
|
[Telegram]
|
||||||
# Your bot token goes here. Get one from https://t.me/BotFather!
|
# Your bot token goes here. Get one from https://t.me/BotFather!
|
||||||
token = "123456789:YOUR_TOKEN_GOES_HERE_______________"
|
token = "123456789:YOUR_TOKEN_GOES_HERE_______________"
|
||||||
# Time in seconds before a conversation (thread) with no new messages expires
|
# Time in seconds before a conversation (thread) with no new messages expires
|
||||||
# A lower value reduces memory usage, but can be inconvenient for the users
|
# A lower value reduces memory usage, but can be inconvenient for the users
|
||||||
conversation_timeout = 7200
|
conversation_timeout = 7200
|
||||||
# Time to wait before sending another update request if there are no messages
|
# Time to wait before sending another update request if there are no messages
|
||||||
long_polling_timeout = 30
|
long_polling_timeout = 30
|
||||||
# Time in seconds before retrying a request if it times out
|
# Time in seconds before retrying a request if it times out
|
||||||
timed_out_pause = 1
|
timed_out_pause = 1
|
||||||
# Time in seconds before retrying a request that returned an error
|
# Time in seconds before retrying a request that returned an error
|
||||||
error_pause = 5
|
error_pause = 5
|
||||||
|
|
||||||
|
|
||||||
# General payment settings
|
# General payment settings
|
||||||
[Payments]
|
[Payments]
|
||||||
# ISO currency code
|
# ISO currency code
|
||||||
currency = "EUR"
|
currency = "EUR"
|
||||||
# Currency exp parameter. You can find that on https://core.telegram.org/bots/payments/currencies.json.
|
# Currency exp parameter. You can find that on https://core.telegram.org/bots/payments/currencies.json.
|
||||||
# It has a value of 2 in most currencies (EUR, USD, GBP...)
|
# It has a value of 2 in most currencies (EUR, USD, GBP...)
|
||||||
currency_exp = 2
|
currency_exp = 2
|
||||||
# Currency symbol which is show to the client users when displaying prices and transaction values
|
# Currency symbol which is show to the client users when displaying prices and transaction values
|
||||||
# If not defined here, default language specific currency symbol from strings would be used
|
# If not defined here, default language specific currency symbol from strings would be used
|
||||||
currency_symbol = "€"
|
currency_symbol = "€"
|
||||||
|
|
||||||
|
|
||||||
# Credit card payment settings
|
# Credit card payment settings
|
||||||
[Payments.CreditCard]
|
[Payments.CreditCard]
|
||||||
# Telegram Payments provider token obtainable at https://t.me/BotFather in the bot's Payments menu
|
# Telegram Payments provider token obtainable at https://t.me/BotFather in the bot's Payments menu
|
||||||
# If empty, credit card payments are disabled.
|
# If empty, credit card payments are disabled.
|
||||||
# credit_card_token =
|
# credit_card_token =
|
||||||
credit_card_token = "123456789:YOUR_TOKEN_HERE_"
|
credit_card_token = "123456789:YOUR_TOKEN_HERE_"
|
||||||
# Minimum wallet payment accepted (in miniumum currency units, $1.00 = 100 units)
|
# Minimum wallet payment accepted (in miniumum currency units, $1.00 = 100 units)
|
||||||
min_amount = 1000
|
min_amount = 1000
|
||||||
# Maximum wallet payment accepted (in miniumum currency units, $1.00 = 100 units)
|
# Maximum wallet payment accepted (in miniumum currency units, $1.00 = 100 units)
|
||||||
max_amount = 10000
|
max_amount = 10000
|
||||||
# The preset selections that can be made when adding credit to the wallet with a credit card
|
# The preset selections that can be made when adding credit to the wallet with a credit card
|
||||||
# Presets are pipe-separated |, and should never be outside the bounds provided by the min_amount and max_amount options
|
# Presets are pipe-separated |, and should never be outside the bounds provided by the min_amount and max_amount options
|
||||||
payment_presets = [10.00, 25.00, 50.00, 100.00]
|
payment_presets = [10.00, 25.00, 50.00, 100.00]
|
||||||
# Make the user pay a extra fee when adding credit to the wallet with a credit card
|
# Make the user pay a extra fee when adding credit to the wallet with a credit card
|
||||||
# The formula for determining the total cost is:
|
# The formula for determining the total cost is:
|
||||||
# cost = added_funds + added_funds * fee_percentage / 100 + fee_fixed
|
# cost = added_funds + added_funds * fee_percentage / 100 + fee_fixed
|
||||||
# Set these values to 0 to disable the feature.
|
# Set these values to 0 to disable the feature.
|
||||||
fee_percentage = 2.9
|
fee_percentage = 2.9
|
||||||
fee_fixed = 30
|
fee_fixed = 30
|
||||||
# "Shipping" information
|
# "Shipping" information
|
||||||
# Telegram can ask for extra information when charging the user for a credit card transaction
|
# Telegram can ask for extra information when charging the user for a credit card transaction
|
||||||
# Set to yes the data you want to be required
|
# Set to yes the data you want to be required
|
||||||
# This data will be stored in the database
|
# This data will be stored in the database
|
||||||
name_required = true
|
name_required = true
|
||||||
email_required = true
|
email_required = true
|
||||||
phone_required = true
|
phone_required = true
|
||||||
|
|
||||||
|
|
||||||
# Bot appearance settings
|
# Bot appearance settings
|
||||||
[Appearance]
|
[Appearance]
|
||||||
# Display the full order information to the customers instead of the shortened version
|
# Display the full order information to the customers instead of the shortened version
|
||||||
# The full order information includes the order number and the timestamp of the order placement
|
# The full order information includes the order number and the timestamp of the order placement
|
||||||
full_order_info = false
|
full_order_info = false
|
||||||
# Allow balance refill during the order checkout in case of unsufficient balance
|
# Allow balance refill during the order checkout in case of unsufficient balance
|
||||||
refill_on_checkout = true
|
refill_on_checkout = true
|
||||||
# Display welcome message (conversation_after_start) when the user sends /start
|
# Display welcome message (conversation_after_start) when the user sends /start
|
||||||
display_welcome_message = true
|
display_welcome_message = true
|
||||||
|
|
||||||
|
|
||||||
# Logging settings
|
# Logging settings
|
||||||
[Logging]
|
[Logging]
|
||||||
# The output format for the messages printed to the console
|
# The output format for the messages printed to the console
|
||||||
# See https://docs.python.org/3/library/logging.html#logrecord-attributes for information about the {}-attributes
|
# See https://docs.python.org/3/library/logging.html#logrecord-attributes for information about the {}-attributes
|
||||||
format = "{asctime} | {threadName} | {name} | {message}"
|
format = "{asctime} | {threadName} | {name} | {message}"
|
||||||
# Logging level: ignore all log entries with a level lower than the specified one
|
# Logging level: ignore all log entries with a level lower than the specified one
|
||||||
# Valid options are FATAL, ERROR, WARNING, INFO, and DEBUG
|
# Valid options are FATAL, ERROR, WARNING, INFO, and DEBUG
|
||||||
level = "INFO"
|
level = "INFO"
|
||||||
|
|
23
core.py
23
core.py
|
@ -1,16 +1,18 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import telegram
|
|
||||||
import worker
|
|
||||||
import nuconfig
|
|
||||||
import threading
|
import threading
|
||||||
import localization
|
|
||||||
import logging
|
|
||||||
import duckbot
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import sqlalchemy.orm
|
|
||||||
import sqlalchemy.ext.declarative as sed
|
import sqlalchemy.ext.declarative as sed
|
||||||
|
import sqlalchemy.orm
|
||||||
|
import telegram
|
||||||
|
|
||||||
import database
|
import database
|
||||||
|
import duckbot
|
||||||
|
import localization
|
||||||
|
import nuconfig
|
||||||
|
import worker
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import coloredlogs
|
import coloredlogs
|
||||||
|
@ -38,7 +40,7 @@ def main():
|
||||||
log.debug("config/config.toml does not exist.")
|
log.debug("config/config.toml does not exist.")
|
||||||
|
|
||||||
with open("config/template_config.toml", encoding="utf8") as template_cfg_file, \
|
with open("config/template_config.toml", encoding="utf8") as template_cfg_file, \
|
||||||
open("config/config.toml", "w", encoding="utf8") as user_cfg_file:
|
open("config/config.toml", "w", encoding="utf8") as user_cfg_file:
|
||||||
# Copy the template file to the config file
|
# Copy the template file to the config file
|
||||||
user_cfg_file.write(template_cfg_file.read())
|
user_cfg_file.write(template_cfg_file.read())
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ def main():
|
||||||
|
|
||||||
# Compare the template config with the user-made one
|
# Compare the template config with the user-made one
|
||||||
with open("config/template_config.toml", encoding="utf8") as template_cfg_file, \
|
with open("config/template_config.toml", encoding="utf8") as template_cfg_file, \
|
||||||
open("config/config.toml", encoding="utf8") as user_cfg_file:
|
open("config/config.toml", encoding="utf8") as user_cfg_file:
|
||||||
template_cfg = nuconfig.NuConfig(template_cfg_file)
|
template_cfg = nuconfig.NuConfig(template_cfg_file)
|
||||||
user_cfg = nuconfig.NuConfig(user_cfg_file)
|
user_cfg = nuconfig.NuConfig(user_cfg_file)
|
||||||
if not template_cfg.cmplog(user_cfg):
|
if not template_cfg.cmplog(user_cfg):
|
||||||
|
@ -173,7 +175,8 @@ def main():
|
||||||
receiving_worker = chat_workers.get(update.callback_query.from_user.id)
|
receiving_worker = chat_workers.get(update.callback_query.from_user.id)
|
||||||
# Ensure a worker exists for the chat
|
# Ensure a worker exists for the chat
|
||||||
if receiving_worker is None:
|
if receiving_worker is None:
|
||||||
log.debug(f"Received a callback query in a chat without worker: {update.callback_query.from_user.id}")
|
log.debug(
|
||||||
|
f"Received a callback query in a chat without worker: {update.callback_query.from_user.id}")
|
||||||
# Suggest that the user restarts the chat with /start
|
# Suggest that the user restarts the chat with /start
|
||||||
bot.send_message(update.callback_query.from_user.id, default_loc.get("error_no_worker_for_chat"))
|
bot.send_message(update.callback_query.from_user.id, default_loc.get("error_no_worker_for_chat"))
|
||||||
# Skip the update
|
# Skip the update
|
||||||
|
|
20
database.py
20
database.py
|
@ -1,22 +1,24 @@
|
||||||
import typing
|
|
||||||
from sqlalchemy import create_engine, Column, ForeignKey, UniqueConstraint
|
|
||||||
from sqlalchemy import Integer, BigInteger, String, Text, LargeBinary, DateTime, Boolean
|
|
||||||
from sqlalchemy.orm import relationship, backref
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base, DeferredReflection
|
|
||||||
import telegram
|
|
||||||
import requests
|
|
||||||
import utils
|
|
||||||
import logging
|
import logging
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import telegram
|
||||||
|
from sqlalchemy import Column, ForeignKey, UniqueConstraint
|
||||||
|
from sqlalchemy import Integer, BigInteger, String, Text, LargeBinary, DateTime, Boolean
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base, DeferredReflection
|
||||||
|
from sqlalchemy.orm import relationship, backref
|
||||||
|
|
||||||
|
import utils
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
import worker
|
import worker
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Create a base class to define all the database subclasses
|
# Create a base class to define all the database subclasses
|
||||||
TableDeclarativeBase = declarative_base()
|
TableDeclarativeBase = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
# Define all the database tables using the sqlalchemy declarative base
|
# Define all the database tables using the sqlalchemy declarative base
|
||||||
class User(DeferredReflection, TableDeclarativeBase):
|
class User(DeferredReflection, TableDeclarativeBase):
|
||||||
"""A Telegram user who used the bot at least once."""
|
"""A Telegram user who used the bot at least once."""
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import nuconfig
|
|
||||||
import telegram.error
|
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import sys
|
|
||||||
|
import telegram.error
|
||||||
|
|
||||||
|
import nuconfig
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
from typing import *
|
|
||||||
import importlib
|
import importlib
|
||||||
import types
|
|
||||||
import logging
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
import types
|
||||||
|
from typing import *
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class IgnoreDict(dict):
|
class IgnoreDict(dict):
|
||||||
"""A dictionary that if passed to format_map, ignores the missing replacement fields."""
|
"""A dictionary that if passed to format_map, ignores the missing replacement fields."""
|
||||||
|
|
||||||
def __missing__(self, key):
|
def __missing__(self, key):
|
||||||
return "{" + key + "}"
|
return "{" + key + "}"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from typing import *
|
|
||||||
import toml
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import *
|
||||||
|
|
||||||
|
import toml
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
CompareReport = Dict[str, Union[str, List[str], "Missing"]]
|
CompareReport = Dict[str, Union[str, List[str], "Missing"]]
|
||||||
|
|
|
@ -110,7 +110,7 @@ conversation_live_orders_start = "You are in <b>Live Orders</b> mode\n" \
|
||||||
|
|
||||||
# Live orders mode: stop receiving messages
|
# Live orders mode: stop receiving messages
|
||||||
conversation_live_orders_stop = "<i>Press the Stop button below this message to stop the" \
|
conversation_live_orders_stop = "<i>Press the Stop button below this message to stop the" \
|
||||||
" feed.</i>"
|
" feed.</i>"
|
||||||
|
|
||||||
# Conversation: help menu has been opened
|
# Conversation: help menu has been opened
|
||||||
conversation_open_help_menu = "What kind of help do you need?"
|
conversation_open_help_menu = "What kind of help do you need?"
|
||||||
|
|
|
@ -71,8 +71,8 @@ conversation_open_user_menu = "Что бы Вы хотели сделать?\n"
|
||||||
conversation_open_admin_menu = "Вы 💼 <b>Менеджер</b> этого магазина!\n" \
|
conversation_open_admin_menu = "Вы 💼 <b>Менеджер</b> этого магазина!\n" \
|
||||||
"Что бы Вы хотели сделать?\n" \
|
"Что бы Вы хотели сделать?\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
"<i>Выберите опцию из вариантов на клавиатуре.\n" \
|
"<i>Выберите опцию из вариантов на клавиатуре.\n" \
|
||||||
"Если клавиатуры не видно - её можно активировать кнопкой с квардатами внизу</i>."
|
"Если клавиатуры не видно - её можно активировать кнопкой с квардатами внизу</i>."
|
||||||
|
|
||||||
# Conversation: select a payment method
|
# Conversation: select a payment method
|
||||||
conversation_payment_method = "Как бы Вы хотели пополнить ваш кошелек?"
|
conversation_payment_method = "Как бы Вы хотели пополнить ваш кошелек?"
|
||||||
|
@ -104,7 +104,7 @@ conversation_live_orders_start = "Вы в режиме <b>Новые заказ
|
||||||
"Все новые заказы появятся в этом чате в режиме реального времени," \
|
"Все новые заказы появятся в этом чате в режиме реального времени," \
|
||||||
" и их можно отметить ✅ Выполнено" \
|
" и их можно отметить ✅ Выполнено" \
|
||||||
" или ✴️ Возвращено в случае возврата денег." \
|
" или ✴️ Возвращено в случае возврата денег." \
|
||||||
|
\
|
||||||
# Live orders mode: stop receiving messages
|
# Live orders mode: stop receiving messages
|
||||||
conversation_live_orders_stop = "<i>Нажмите Стоп в этом чате, чтобы остановить этот режим.</i>"
|
conversation_live_orders_stop = "<i>Нажмите Стоп в этом чате, чтобы остановить этот режим.</i>"
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,8 @@ conversation_open_user_menu = "Щоб ви хотіли зробити?\n" \
|
||||||
conversation_open_admin_menu = "Ви є 💼 <b>Менеджером</b> цього магазину!\n" \
|
conversation_open_admin_menu = "Ви є 💼 <b>Менеджером</b> цього магазину!\n" \
|
||||||
"Що б ви хотіли зробити?\n" \
|
"Що б ви хотіли зробити?\n" \
|
||||||
"\n" \
|
"\n" \
|
||||||
"<i>Виберіть опцію з варіантів на клавіатурі.\n" \
|
"<i>Виберіть опцію з варіантів на клавіатурі.\n" \
|
||||||
"Якщо клавіатури не видно - її можна активувати кнопкою з чотирма квадратами внизу</i>."
|
"Якщо клавіатури не видно - її можна активувати кнопкою з чотирма квадратами внизу</i>."
|
||||||
|
|
||||||
# Conversation: select a payment method
|
# Conversation: select a payment method
|
||||||
conversation_payment_method = "Як би Ви хотіли поповнити гаманець?"
|
conversation_payment_method = "Як би Ви хотіли поповнити гаманець?"
|
||||||
|
|
|
@ -52,7 +52,7 @@ transactions_page = "Page <b>{page}</b>:\n" \
|
||||||
# transactions.csv caption
|
# transactions.csv caption
|
||||||
csv_caption = "生成了一个📄.csv文件,其中包含bot的数据库中多所有事物\n" \
|
csv_caption = "生成了一个📄.csv文件,其中包含bot的数据库中多所有事物\n" \
|
||||||
"您可以使用其他程序(例如LibreOffice Calc)打开此文件并进行处理数据" \
|
"您可以使用其他程序(例如LibreOffice Calc)打开此文件并进行处理数据" \
|
||||||
|
\
|
||||||
# Conversation: 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 = "您好!\n" \
|
conversation_after_start = "您好!\n" \
|
||||||
"欢迎使用greed系统!\n" \
|
"欢迎使用greed系统!\n" \
|
||||||
|
|
59
worker.py
59
worker.py
|
@ -1,26 +1,29 @@
|
||||||
import threading
|
|
||||||
from typing import *
|
|
||||||
import uuid
|
|
||||||
import datetime
|
import datetime
|
||||||
import telegram
|
|
||||||
import nuconfig
|
|
||||||
import sys
|
|
||||||
import queue as queuem
|
|
||||||
import database as db
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
import traceback
|
|
||||||
from html import escape
|
|
||||||
import requests
|
|
||||||
import logging
|
import logging
|
||||||
import localization
|
import os
|
||||||
|
import queue as queuem
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import traceback
|
||||||
|
import uuid
|
||||||
|
from html import escape
|
||||||
|
from typing import *
|
||||||
|
|
||||||
|
import requests
|
||||||
import sqlalchemy.orm
|
import sqlalchemy.orm
|
||||||
|
import telegram
|
||||||
|
|
||||||
|
import database as db
|
||||||
|
import localization
|
||||||
|
import nuconfig
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class StopSignal:
|
class StopSignal:
|
||||||
"""A data class that should be sent to the worker when the conversation has to be stopped abnormally."""
|
"""A data class that should be sent to the worker when the conversation has to be stopped abnormally."""
|
||||||
|
|
||||||
def __init__(self, reason: str = ""):
|
def __init__(self, reason: str = ""):
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
|
|
||||||
|
@ -662,8 +665,8 @@ class Worker(threading.Thread):
|
||||||
if self.cfg["Payments"]["CreditCard"]["credit_card_token"] != "" \
|
if self.cfg["Payments"]["CreditCard"]["credit_card_token"] != "" \
|
||||||
and self.cfg["Appearance"]["refill_on_checkout"] == 'yes' \
|
and self.cfg["Appearance"]["refill_on_checkout"] == 'yes' \
|
||||||
and self.Price(self.cfg["Payments"]["CreditCard"]["min_amount"]) <= \
|
and self.Price(self.cfg["Payments"]["CreditCard"]["min_amount"]) <= \
|
||||||
credit_required <= \
|
credit_required <= \
|
||||||
self.Price(self.cfg["Payments"]["CreditCard"]["max_amount"]):
|
self.Price(self.cfg["Payments"]["CreditCard"]["max_amount"]):
|
||||||
self.__make_payment(self.Price(credit_required))
|
self.__make_payment(self.Price(credit_required))
|
||||||
# If afer requested payment credit is still insufficient (either payment failure or cancel)
|
# If afer requested payment credit is still insufficient (either payment failure or cancel)
|
||||||
if self.user.credit < self.__get_cart_value(cart):
|
if self.user.credit < self.__get_cart_value(cart):
|
||||||
|
@ -759,8 +762,9 @@ class Worker(threading.Thread):
|
||||||
self.bot.send_message(self.chat.id, self.loc.get("conversation_payment_method"),
|
self.bot.send_message(self.chat.id, self.loc.get("conversation_payment_method"),
|
||||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
||||||
# Wait for a reply from the user
|
# Wait for a reply from the user
|
||||||
selection = self.__wait_for_specific_message([self.loc.get("menu_cash"), self.loc.get("menu_credit_card"), self.loc.get("menu_cancel")],
|
selection = self.__wait_for_specific_message(
|
||||||
cancellable=True)
|
[self.loc.get("menu_cash"), self.loc.get("menu_credit_card"), self.loc.get("menu_cancel")],
|
||||||
|
cancellable=True)
|
||||||
# If the user has selected the Cash option...
|
# If the user has selected the Cash option...
|
||||||
if selection == self.loc.get("menu_cash"):
|
if selection == self.loc.get("menu_cash"):
|
||||||
# Go to the pay with cash function
|
# Go to the pay with cash function
|
||||||
|
@ -790,7 +794,8 @@ class Worker(threading.Thread):
|
||||||
self.bot.send_message(self.chat.id, self.loc.get("payment_cc_amount"),
|
self.bot.send_message(self.chat.id, self.loc.get("payment_cc_amount"),
|
||||||
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
reply_markup=telegram.ReplyKeyboardMarkup(keyboard, one_time_keyboard=True))
|
||||||
# Wait until a valid amount is sent
|
# Wait until a valid amount is sent
|
||||||
selection = self.__wait_for_regex(r"([0-9]+(?:[.,][0-9]+)?|" + self.loc.get("menu_cancel") + r")", cancellable=True)
|
selection = self.__wait_for_regex(r"([0-9]+(?:[.,][0-9]+)?|" + self.loc.get("menu_cancel") + r")",
|
||||||
|
cancellable=True)
|
||||||
# If the user cancelled the action
|
# If the user cancelled the action
|
||||||
if isinstance(selection, CancelSignal):
|
if isinstance(selection, CancelSignal):
|
||||||
# Exit the loop
|
# Exit the loop
|
||||||
|
@ -801,11 +806,13 @@ class Worker(threading.Thread):
|
||||||
# Ensure the amount is within the range
|
# Ensure the amount is within the range
|
||||||
if value > self.Price(self.cfg["Payments"]["CreditCard"]["max_amount"]):
|
if value > self.Price(self.cfg["Payments"]["CreditCard"]["max_amount"]):
|
||||||
self.bot.send_message(self.chat.id,
|
self.bot.send_message(self.chat.id,
|
||||||
self.loc.get("error_payment_amount_over_max", max_amount=self.Price(self.cfg["Credit Card"]["max_amount"])))
|
self.loc.get("error_payment_amount_over_max",
|
||||||
|
max_amount=self.Price(self.cfg["Credit Card"]["max_amount"])))
|
||||||
continue
|
continue
|
||||||
elif value < self.Price(self.cfg["Payments"]["CreditCard"]["min_amount"]):
|
elif value < self.Price(self.cfg["Payments"]["CreditCard"]["min_amount"]):
|
||||||
self.bot.send_message(self.chat.id,
|
self.bot.send_message(self.chat.id,
|
||||||
self.loc.get("error_payment_amount_under_min", min_amount=self.Price(self.cfg["Credit Card"]["min_amount"])))
|
self.loc.get("error_payment_amount_under_min",
|
||||||
|
min_amount=self.Price(self.cfg["Credit Card"]["min_amount"])))
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
# If the user cancelled the action...
|
# If the user cancelled the action...
|
||||||
|
@ -1019,8 +1026,8 @@ class Worker(threading.Thread):
|
||||||
if product:
|
if product:
|
||||||
self.bot.send_message(self.chat.id,
|
self.bot.send_message(self.chat.id,
|
||||||
self.loc.get("edit_current_value",
|
self.loc.get("edit_current_value",
|
||||||
value=(str(self.Price(product.price))
|
value=(str(self.Price(product.price))
|
||||||
if product.price is not None else 'Non in vendita')),
|
if product.price is not None else 'Non in vendita')),
|
||||||
reply_markup=cancel)
|
reply_markup=cancel)
|
||||||
# Wait for an answer
|
# Wait for an answer
|
||||||
price = self.__wait_for_regex(r"([0-9]+(?:[.,][0-9]{1,2})?|[Xx])",
|
price = self.__wait_for_regex(r"([0-9]+(?:[.,][0-9]{1,2})?|[Xx])",
|
||||||
|
@ -1162,7 +1169,8 @@ class Worker(threading.Thread):
|
||||||
message_id=update.message.message_id)
|
message_id=update.message.message_id)
|
||||||
# Notify the user of the completition
|
# Notify the user of the completition
|
||||||
self.bot.send_message(order.user_id,
|
self.bot.send_message(order.user_id,
|
||||||
self.loc.get("notification_order_completed", order=order.text(w=self, session=self.session, user=True)))
|
self.loc.get("notification_order_completed",
|
||||||
|
order=order.text(w=self, session=self.session, user=True)))
|
||||||
# If the user pressed the refund order button, refund the order...
|
# If the user pressed the refund order button, refund the order...
|
||||||
elif update.data == "order_refund":
|
elif update.data == "order_refund":
|
||||||
# Ask for a refund reason
|
# Ask for a refund reason
|
||||||
|
@ -1302,7 +1310,8 @@ class Worker(threading.Thread):
|
||||||
telegram.InlineKeyboardButton(self.loc.get("menu_next"), callback_data="cmd_next")
|
telegram.InlineKeyboardButton(self.loc.get("menu_next"), callback_data="cmd_next")
|
||||||
)
|
)
|
||||||
# Add a Done button
|
# Add a Done button
|
||||||
inline_keyboard_list.append([telegram.InlineKeyboardButton(self.loc.get("menu_done"), callback_data="cmd_done")])
|
inline_keyboard_list.append(
|
||||||
|
[telegram.InlineKeyboardButton(self.loc.get("menu_done"), callback_data="cmd_done")])
|
||||||
# Create the inline keyboard markup
|
# Create the inline keyboard markup
|
||||||
inline_keyboard = telegram.InlineKeyboardMarkup(inline_keyboard_list)
|
inline_keyboard = telegram.InlineKeyboardMarkup(inline_keyboard_list)
|
||||||
# Create the message text
|
# Create the message text
|
||||||
|
|
Loading…
Reference in a new issue