mirror of
https://github.com/Rongronggg9/SlashBot.git
synced 2025-02-06 17:23:28 +08:00
feat: use SystemRandom as RNG
This commit is contained in:
parent
ead8fb2c47
commit
f11132c2ae
28
SlashBot.py
28
SlashBot.py
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from itertools import product as _product
|
from itertools import product as _product
|
||||||
from random import choice
|
from random import Random, SystemRandom
|
||||||
|
|
||||||
Filters = filters.Filters
|
Filters = filters.Filters
|
||||||
|
|
||||||
@ -63,14 +63,6 @@ VEGETABLE = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Docker env
|
|
||||||
TOKENS = re.compile(r'[^a-zA-Z\-_\d:]+').split(os.environ.get('TOKEN', ''))
|
|
||||||
if not TOKENS:
|
|
||||||
raise ValueError('no any valid token found')
|
|
||||||
|
|
||||||
TELEGRAM_PROXY = os.environ.get('PROXY', '')
|
|
||||||
REQUEST_PROXIES = {'all': TELEGRAM_PROXY} if TELEGRAM_PROXY else None
|
|
||||||
|
|
||||||
_logger.remove()
|
_logger.remove()
|
||||||
_logger.add(sys.stderr,
|
_logger.add(sys.stderr,
|
||||||
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green>"
|
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green>"
|
||||||
@ -79,6 +71,20 @@ _logger.add(sys.stderr,
|
|||||||
"|<level>{message}</level>",
|
"|<level>{message}</level>",
|
||||||
level="DEBUG")
|
level="DEBUG")
|
||||||
|
|
||||||
|
try:
|
||||||
|
random = SystemRandom()
|
||||||
|
except NotImplementedError:
|
||||||
|
random = Random()
|
||||||
|
_logger.warning('SystemRandom is not available, using Random instead')
|
||||||
|
|
||||||
|
# Docker env
|
||||||
|
TOKENS = re.compile(r'[^a-zA-Z\-_\d:]+').split(os.environ.get('TOKEN', ''))
|
||||||
|
if not TOKENS:
|
||||||
|
raise ValueError('no any valid token found')
|
||||||
|
|
||||||
|
TELEGRAM_PROXY = os.environ.get('PROXY', '')
|
||||||
|
REQUEST_PROXIES = {'all': TELEGRAM_PROXY} if TELEGRAM_PROXY else None
|
||||||
|
|
||||||
_updaters: list[Updater] = []
|
_updaters: list[Updater] = []
|
||||||
|
|
||||||
|
|
||||||
@ -238,7 +244,7 @@ def pin(update: telegram.Update, ctx: telegram.ext.CallbackContext):
|
|||||||
msg = update.effective_message
|
msg = update.effective_message
|
||||||
msg_to_pin = msg.reply_to_message
|
msg_to_pin = msg.reply_to_message
|
||||||
if not msg_to_pin:
|
if not msg_to_pin:
|
||||||
vegetable = f'{choice(VEGETABLE["reject"])} (Reply to a message to use the command)'
|
vegetable = f'{random.choice(VEGETABLE["reject"])} (Reply to a message to use the command)'
|
||||||
msg.reply_text(vegetable)
|
msg.reply_text(vegetable)
|
||||||
logger.warning(vegetable)
|
logger.warning(vegetable)
|
||||||
return
|
return
|
||||||
@ -248,7 +254,7 @@ def pin(update: telegram.Update, ctx: telegram.ext.CallbackContext):
|
|||||||
msg_to_pin.pin(disable_notification=True)
|
msg_to_pin.pin(disable_notification=True)
|
||||||
logger.info(f'Pinned {msg_to_pin.text}')
|
logger.info(f'Pinned {msg_to_pin.text}')
|
||||||
except telegram.error.BadRequest as e:
|
except telegram.error.BadRequest as e:
|
||||||
vegetable = f'{choice(VEGETABLE["permission_denied"])} ({e})'
|
vegetable = f'{random.choice(VEGETABLE["permission_denied"])} ({e})'
|
||||||
msg_to_pin.reply_text(vegetable)
|
msg_to_pin.reply_text(vegetable)
|
||||||
logger.warning(vegetable)
|
logger.warning(vegetable)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user