mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 14:04:18 +00:00
Configuration updates
This commit is contained in:
parent
88eed550d2
commit
055f3b72c1
3 changed files with 47 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
||||||
# greed
|
# greed
|
||||||
A customizable Telegram shop bot, developed for the High School oral exam
|
A customizable Telegram shop bot, developed as a project for the final exam.
|
||||||
|
|
||||||
![](https://img.shields.io/badge/version-alpha-blue.svg)
|
![](https://img.shields.io/badge/version-alpha-blue.svg)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# Config file parameters
|
# Config file parameters
|
||||||
[Config]
|
[Config]
|
||||||
; Config file version. DO NOT EDIT THIS!
|
; Config file version. DO NOT EDIT THIS!
|
||||||
version = 12
|
version = 13
|
||||||
; Set this to no when you are done editing the file
|
; Set this to no when you are done editing the file
|
||||||
is_template = yes
|
is_template = yes
|
||||||
|
|
||||||
|
@ -13,50 +13,60 @@ is_template = yes
|
||||||
[Telegram]
|
[Telegram]
|
||||||
; Your bot token goes here. Get one from @BotFather!
|
; Your bot token goes here. Get one from @BotFather!
|
||||||
token = 123456789:YOUR_TOKEN_GOES_HERE_______________
|
token = 123456789:YOUR_TOKEN_GOES_HERE_______________
|
||||||
; Time in seconds before a conversation 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 getUpdates request
|
; 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
|
||||||
|
timed_out_pause = 1
|
||||||
|
; Time in seconds before retrying a request that returned an error
|
||||||
|
error_pause = 5
|
||||||
|
|
||||||
# Database parameters
|
# Database parameters
|
||||||
[Database]
|
[Database]
|
||||||
; The database engine you want to use. Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
|
; The database engine you want to use.
|
||||||
|
; Refer to http://docs.sqlalchemy.org/en/latest/core/engines.html for the possible settings.
|
||||||
engine = sqlite://
|
engine = sqlite://
|
||||||
|
|
||||||
# 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...)
|
||||||
currency_exp = 2
|
currency_exp = 2
|
||||||
|
|
||||||
# Credit card payment settings
|
# Credit card payment settings
|
||||||
[Credit Card]
|
[Credit Card]
|
||||||
# Provider token: get the token at @BotFather
|
; Provider token: get the token by linking the payment provider with @BotFather
|
||||||
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
|
||||||
# Make the user pay a fee when loading the wallet with a credit card
|
; Make the user pay a extra fee when adding credit to the wallet with a credit card
|
||||||
# Credit card fee percentage (set to 0.0 to disable)
|
; The formula for determining the total cost is:
|
||||||
|
; cost = added_funds + added_funds * fee_percentage / 100 + fee_fixed
|
||||||
|
; Set these values to 0 to disable the feature.
|
||||||
fee_percentage = 2.9
|
fee_percentage = 2.9
|
||||||
# Credit card fee fixed (in miniumum currency units, $1.00 = 100 units) (set to 0 to disable)
|
|
||||||
fee_fixed = 30
|
fee_fixed = 30
|
||||||
# Require the name of the user
|
; "Shipping" information
|
||||||
|
; 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
|
||||||
|
; This data will be stored in the database
|
||||||
name_required = yes
|
name_required = yes
|
||||||
# Require the email of the user
|
|
||||||
email_required = yes
|
email_required = yes
|
||||||
# Require the phone number of the user
|
|
||||||
phone_required = yes
|
phone_required = yes
|
||||||
|
|
||||||
# Bot appearance settings
|
# Bot appearance settings
|
||||||
[Appearance]
|
[Appearance]
|
||||||
# Show the full order info to the customers
|
; 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
|
||||||
full_order_info = no
|
full_order_info = no
|
||||||
|
|
||||||
# Exception reporting settings
|
# Exception reporting settings
|
||||||
[Error Reporting]
|
[Error Reporting]
|
||||||
# Optional sentry token: get the token at https://sentry.io/
|
; Optional sentry token: get the token at https://sentry.io/ or ask @Steffo for one
|
||||||
|
; Needed to automatically report bugs found by the users in the code.
|
||||||
sentry_token = https://00000000000000000000000000000000:00000000000000000000000000000000@sentry.io/0000000
|
sentry_token = https://00000000000000000000000000000000:00000000000000000000000000000000@sentry.io/0000000
|
29
utils.py
29
utils.py
|
@ -19,6 +19,8 @@ else:
|
||||||
|
|
||||||
|
|
||||||
class Price:
|
class Price:
|
||||||
|
"""The base class for the prices in greed.
|
||||||
|
Its int value is in minimum units, while its float and str values are in decimal format.int("""
|
||||||
def __init__(self, value: typing.Union[int, float, str, "Price"]=0):
|
def __init__(self, value: typing.Union[int, float, str, "Price"]=0):
|
||||||
if isinstance(value, int):
|
if isinstance(value, int):
|
||||||
# Keep the value as it is
|
# Keep the value as it is
|
||||||
|
@ -121,26 +123,31 @@ def catch_telegram_errors(func):
|
||||||
break
|
break
|
||||||
# Telegram API didn't answer in time
|
# Telegram API didn't answer in time
|
||||||
except telegram.error.TimedOut:
|
except telegram.error.TimedOut:
|
||||||
print(f"Timed out while calling {func.__name__}(), retrying in 1 sec...")
|
print(f"Timed out while calling {func.__name__}(),"
|
||||||
time.sleep(1)
|
f" retrying in {config['Telegram']['timed_out_pause']} secs...")
|
||||||
|
time.sleep(int(config["Telegram"]["timed_out_pause"]))
|
||||||
# Telegram is not reachable
|
# Telegram is not reachable
|
||||||
except telegram.error.NetworkError:
|
except telegram.error.NetworkError:
|
||||||
print(f"Network error while calling {func.__name__}(), retrying in 5 secs...")
|
print(f"Network error while calling {func.__name__}(),"
|
||||||
time.sleep(5)
|
f" retrying in {config['Telegram']['error_pause']} secs...")
|
||||||
|
time.sleep(int(config["Telegram"]["error_pause"]))
|
||||||
# Unknown error
|
# Unknown error
|
||||||
except telegram.error.TelegramError as error:
|
except telegram.error.TelegramError as error:
|
||||||
if error.message.lower() in ["bad gateway", "invalid server response"]:
|
if error.message.lower() in ["bad gateway", "invalid server response"]:
|
||||||
print(f"Bad Gateway while calling {func.__name__}(), retrying in 5 secs...")
|
print(f"Bad Gateway while calling {func.__name__}(),"
|
||||||
time.sleep(5)
|
f" retrying in {config['Telegram']['error_pause']} secs...")
|
||||||
|
time.sleep(int(config["Telegram"]["error_pause"]))
|
||||||
elif error.message.lower() == "timed out":
|
elif error.message.lower() == "timed out":
|
||||||
print(f"Timed out while calling {func.__name__}(), retrying in 1 sec...")
|
print(f"Timed out while calling {func.__name__}(),"
|
||||||
time.sleep(1)
|
f" retrying in {config['Telegram']['timed_out_pause']} secs...")
|
||||||
|
time.sleep(int(config["Telegram"]["timed_out_pause"]))
|
||||||
else:
|
else:
|
||||||
print(f"Telegram error while calling {func.__name__}(), retrying in 5 secs...")
|
print(f"Telegram error while calling {func.__name__}(),"
|
||||||
|
f" retrying in {config['Telegram']['error_pause']} secs...")
|
||||||
# Send the error to the Sentry server
|
# Send the error to the Sentry server
|
||||||
if sentry_client is not None:
|
if sentry_client is not None:
|
||||||
sentry_client.captureException(exc_info=sys.exc_info())
|
sentry_client.captureException(exc_info=sys.exc_info())
|
||||||
time.sleep(5)
|
time.sleep(int(config["Telegram"]["error_pause"]))
|
||||||
return result_func
|
return result_func
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,4 +210,4 @@ class DuckBot:
|
||||||
def send_document(self, *args, **kwargs):
|
def send_document(self, *args, **kwargs):
|
||||||
return self.bot.send_document(*args, **kwargs)
|
return self.bot.send_document(*args, **kwargs)
|
||||||
|
|
||||||
# TODO: add more methods
|
# More methods can be added here
|
||||||
|
|
Loading…
Reference in a new issue