✨ Support auto install extra pypi packages. (#158)
* 支持自动安装额外的 pypi 扩展包
This commit is contained in:
parent
defdfd7ad2
commit
12320e2a59
1
.gitignore
vendored
1
.gitignore
vendored
@ -127,6 +127,7 @@ dump.rdb
|
|||||||
keyword.list
|
keyword.list
|
||||||
requirements2.txt
|
requirements2.txt
|
||||||
languages/custom.yml
|
languages/custom.yml
|
||||||
|
unknown_errors.txt
|
||||||
|
|
||||||
# Spyder project settings
|
# Spyder project settings
|
||||||
.spyderproject
|
.spyderproject
|
||||||
|
@ -6,13 +6,7 @@ from concurrent.futures import CancelledError
|
|||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
from sentry_sdk.integrations.redis import RedisIntegration
|
from sentry_sdk.integrations.redis import RedisIntegration
|
||||||
|
|
||||||
python36 = True
|
from asyncio import CancelledError as CancelError
|
||||||
try:
|
|
||||||
from asyncio.exceptions import CancelledError as CancelError
|
|
||||||
|
|
||||||
python36 = False
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
from subprocess import run, PIPE
|
from subprocess import run, PIPE
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import time
|
from time import time
|
||||||
@ -279,7 +273,8 @@ def before_send(event, hint):
|
|||||||
AlreadyInConversationError, ConnectedError, KeyboardInterrupt,
|
AlreadyInConversationError, ConnectedError, KeyboardInterrupt,
|
||||||
OSError, AuthKeyDuplicatedError, ResponseError, SlowModeWaitError,
|
OSError, AuthKeyDuplicatedError, ResponseError, SlowModeWaitError,
|
||||||
PeerFloodError, MessageEditTimeExpiredError, PeerIdInvalidError,
|
PeerFloodError, MessageEditTimeExpiredError, PeerIdInvalidError,
|
||||||
AuthKeyUnregisteredError, UserBannedInChannelError, AuthKeyError)):
|
AuthKeyUnregisteredError, UserBannedInChannelError, AuthKeyError,
|
||||||
|
CancelError)):
|
||||||
return
|
return
|
||||||
elif exc_info and isinstance(exc_info[1], UserDeactivatedBanError):
|
elif exc_info and isinstance(exc_info[1], UserDeactivatedBanError):
|
||||||
# The user has been deleted/deactivated
|
# The user has been deleted/deactivated
|
||||||
@ -288,9 +283,6 @@ def before_send(event, hint):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
exit(1)
|
exit(1)
|
||||||
if not python36:
|
|
||||||
if exc_info and isinstance(exc_info[1], CancelError):
|
|
||||||
return
|
|
||||||
if time() <= report_time + 30:
|
if time() <= report_time + 30:
|
||||||
report_time = time()
|
report_time = time()
|
||||||
return
|
return
|
||||||
@ -303,7 +295,7 @@ report_time = time()
|
|||||||
start_time = datetime.utcnow()
|
start_time = datetime.utcnow()
|
||||||
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode()
|
git_hash = run("git rev-parse HEAD", stdout=PIPE, shell=True).stdout.decode()
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
"https://ae2b937dba4a4f948f13ae1c902b30a3@o416616.ingest.sentry.io/5312335",
|
"https://88b676b38216473db3eb3dd5e1da0133@o416616.ingest.sentry.io/5312335",
|
||||||
traces_sample_rate=1.0,
|
traces_sample_rate=1.0,
|
||||||
release=git_hash,
|
release=git_hash,
|
||||||
before_send=before_send,
|
before_send=before_send,
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
""" Libraries for python modules. """
|
""" Libraries for python modules. """
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from importlib.util import find_spec
|
||||||
|
from sys import executable
|
||||||
|
|
||||||
from os import remove
|
from os import remove
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
from emoji import get_emoji_regexp
|
from emoji import get_emoji_regexp
|
||||||
from random import choice
|
from random import choice
|
||||||
@ -214,6 +218,18 @@ def clear_emojis(target: str) -> str:
|
|||||||
return get_emoji_regexp().sub(u'', target)
|
return get_emoji_regexp().sub(u'', target)
|
||||||
|
|
||||||
|
|
||||||
|
def pip_install(package: str, version: Optional[str] = "", alias: Optional[str] = "") -> bool:
|
||||||
|
""" Auto install extra pypi packages """
|
||||||
|
if not alias:
|
||||||
|
# when import name is not provided, use package name
|
||||||
|
alias = package
|
||||||
|
if find_spec(alias) is None:
|
||||||
|
subprocess.call([executable, "-m", "pip", "install", f"{package}{version}"])
|
||||||
|
if find_spec(package) is None:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def admin_check(event):
|
async def admin_check(event):
|
||||||
if event.is_private:
|
if event.is_private:
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user