mirror of
https://github.com/dizedev/vk_lp.git
synced 2026-09-17 05:09:00 +00:00
Merge remote-tracking branch 'github/master' into dize
# Conflicts: # config.py # routes/__init__.py # routes/delete_msg.py # routes/info_bot.py # routes/rewards.py
This commit is contained in:
+255
@@ -0,0 +1,255 @@
|
|||||||
|
### VisualStudioCode template
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Built Visual Studio Code Extensions
|
||||||
|
*.vsix
|
||||||
|
|
||||||
|
### Python template
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
.pdm.toml
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
### PyCharm+all template
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
Generated
-3
@@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
Generated
-10
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="ASK" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
-6
@@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
||||||
Generated
-4
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (UserVKBot)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/UserVKBot.iml" filepath="$PROJECT_DIR$/.idea/UserVKBot.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
from vkbottle.user import UserLabeler, Message, User
|
from vkbottle.user import UserLabeler, Message, User
|
||||||
|
|
||||||
|
TOKEN = 'vk1.a.4nNdLuOJin9tn71J-cKGu6MKCR2rNHkdRPn4lbW28CS9aL0Q-rhG3ZQi6UQnV9ClpBrNp2obRUltWREoSuwz2Km7OXGlBaP3jt9KsEeut4N3OvHWoTUuqNEtiRrgz2koSrPXLEJZ8i974KD2CgXWqmX4IsSC3kCMDK_aS1xetU3S38-Z1JFyNZu5Tl8yUGopptCjEqA9jF8CjznWv1gC2A'
|
||||||
|
|
||||||
bl = UserLabeler()
|
bl = UserLabeler()
|
||||||
|
|
||||||
user = User(token=TOKEN)
|
user = User(token=TOKEN)
|
||||||
|
|
||||||
|
TOKEN = "test"
|
||||||
prefix_bot = "хуй"
|
prefix_bot = "хуй"
|
||||||
prefix_dd = "дд"
|
prefix_dd = "дд"
|
||||||
|
|
||||||
|
|||||||
+13
-14
@@ -1,23 +1,22 @@
|
|||||||
from vkbottle.dispatch.rules import ABCRule
|
|
||||||
from vkbottle.user import Message
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from vkbottle.dispatch.rules import ABCRule
|
||||||
|
from vkbottle.user import Message
|
||||||
|
|
||||||
|
|
||||||
|
def load_trusted_ids():
|
||||||
|
try:
|
||||||
|
with open("./user_ids.json", "r") as json_file:
|
||||||
|
data = json.load(json_file)
|
||||||
|
return data
|
||||||
|
except FileNotFoundError:
|
||||||
|
# Если файл не существует, вернуть пустой список
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class Permission(ABCRule[Message]):
|
class Permission(ABCRule[Message]):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.trusted_ids = self.load_trusted_ids()
|
self.trusted_ids = load_trusted_ids()
|
||||||
|
|
||||||
def load_trusted_ids(self):
|
|
||||||
try:
|
|
||||||
with open("./user_ids.json", "r") as json_file:
|
|
||||||
data = json.load(json_file)
|
|
||||||
return data
|
|
||||||
except FileNotFoundError:
|
|
||||||
# Если файл не существует, вернуть пустой список
|
|
||||||
return []
|
|
||||||
|
|
||||||
async def check(self, event: Message) -> bool:
|
async def check(self, event: Message) -> bool:
|
||||||
return event.from_id in self.trusted_ids
|
return event.from_id in self.trusted_ids
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from . import config, models, requests
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
DB_CONNECT_URL = f"postgresql+asyncpg://{config.DB_LOGIN}:{config.DB_PASSWORD}@{config.DB_HOST}/{config.DB_NAME}"
|
||||||
|
engine = create_async_engine(DB_CONNECT_URL)
|
||||||
|
async_session = async_sessionmaker(engine)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from sqlalchemy import (BigInteger, Column, Identity, Text)
|
||||||
|
from sqlalchemy.orm import DeclarativeBase
|
||||||
|
|
||||||
|
|
||||||
|
class Base(DeclarativeBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UsersTokens(Base):
|
||||||
|
__tablename__ = "users_tokens"
|
||||||
|
|
||||||
|
id = Column("id", BigInteger, Identity(start=1, increment=1, minvalue=1, cycle=False, cache=1), nullable=False,
|
||||||
|
primary_key=True)
|
||||||
|
vkid = Column("vkid", BigInteger, nullable=False, unique=True)
|
||||||
|
token = Column("token", Text, nullable=False)
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
|
import db
|
||||||
|
|
||||||
|
|
||||||
|
async def execute_statement(statement) -> None:
|
||||||
|
"""
|
||||||
|
Возвращает результат выполнения statement
|
||||||
|
:param statement:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
async with db.config.async_session() as session:
|
||||||
|
await session.execute(statement)
|
||||||
|
await session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(e)
|
||||||
|
# return None
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_token(user_id: int) -> Optional[db.models.UsersTokens]:
|
||||||
|
"""
|
||||||
|
Возвращает токен пользователя
|
||||||
|
:param user_id: VKID
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
async with db.config.async_session() as session:
|
||||||
|
result = await session.execute(select(db.models.UsersTokens).where(db.models.UsersTokens.vkid == user_id))
|
||||||
|
return result.scalars().one_or_none()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(e)
|
||||||
|
return None
|
||||||
@@ -1,13 +1,33 @@
|
|||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
from config import user
|
|
||||||
from routes import labelers
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from vkbottle.user import User
|
||||||
|
|
||||||
|
import config
|
||||||
|
import db
|
||||||
|
|
||||||
|
|
||||||
logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")
|
logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")
|
||||||
|
|
||||||
for custom_labeler in labelers:
|
|
||||||
user.labeler.load(custom_labeler)
|
async def main():
|
||||||
|
from routes import labelers
|
||||||
|
|
||||||
|
user_info = await db.requests.get_user_token(304398797)
|
||||||
|
if not user_info:
|
||||||
|
logger.error("user don't have a token in db!")
|
||||||
|
return
|
||||||
|
|
||||||
|
config.user = User(token=user_info.token)
|
||||||
|
|
||||||
|
for custom_labeler in labelers:
|
||||||
|
config.user.labeler.load(custom_labeler)
|
||||||
|
|
||||||
|
loop.create_task(config.user.run_polling())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
user.run_forever()
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.create_task(main())
|
||||||
|
loop.run_forever()
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
gitpython==3.1.40
|
||||||
|
loguru==0.7.2
|
||||||
|
pytz==2023.3.post1
|
||||||
|
vkbottle==4.3.12
|
||||||
|
SQLAlchemy~=2.0.22
|
||||||
|
asyncpg
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from vkbottle.user import Message
|
|
||||||
from config import bl, prefix_bot, edit_message
|
from vkbottle.user import Message, UserLabeler
|
||||||
|
|
||||||
|
from config import prefix_bot, edit_message
|
||||||
from custom_rules.permission import Permission
|
from custom_rules.permission import Permission
|
||||||
|
|
||||||
|
bl = UserLabeler()
|
||||||
|
|
||||||
|
|
||||||
@bl.message(
|
@bl.message(
|
||||||
Permission(),
|
Permission(),
|
||||||
text=[prefix_bot + " игра"],
|
text=[prefix_bot + " игра"],
|
||||||
)
|
)
|
||||||
async def game(message: Message):
|
async def game(message: Message):
|
||||||
loader = (
|
loader = (
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
rewards_list = [
|
rewards = {
|
||||||
"Первооткрыватель 🎓\n",
|
"discoverer": "Первооткрыватель",
|
||||||
"Создатель ⭐\n",
|
"creator": "Создатель",
|
||||||
"Администратор 👨🏻💼\n",
|
"admin": "Администратор",
|
||||||
"Модератоор 🛡️\n",
|
"moderator": "Moderator",
|
||||||
"Иследователь 🔎\n",
|
"researcher": "Исследователь",
|
||||||
"Спонсор 💸\n",
|
"sponsor": "Спонсор"
|
||||||
]
|
}
|
||||||
|
|
||||||
|
next_line_symbol = "\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user