initial commit
This commit is contained in:
commit
94750f2447
215
.gitignore
vendored
Normal file
215
.gitignore
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
# 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
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__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/
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
/data/
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
51
.idea/inspectionProfiles/Project_Default.xml
Normal file
51
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myValues">
|
||||
<value>
|
||||
<list size="11">
|
||||
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
||||
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
||||
<item index="2" class="java.lang.String" itemvalue="comment" />
|
||||
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
||||
<item index="4" class="java.lang.String" itemvalue="embed" />
|
||||
<item index="5" class="java.lang.String" itemvalue="script" />
|
||||
<item index="6" class="java.lang.String" itemvalue="markdown" />
|
||||
<item index="7" class="java.lang.String" itemvalue="sv3i" />
|
||||
<item index="8" class="java.lang.String" itemvalue="sv3o" />
|
||||
<item index="9" class="java.lang.String" itemvalue="sv3a" />
|
||||
<item index="10" class="java.lang.String" itemvalue="sv3c" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myCustomValuesEnabled" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="nacl" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="PySide2.QtWidgets.clicked.connect" />
|
||||
<option value="PySide2.QtWidgets.valueChanged.connect" />
|
||||
<option value="PySide2.QtWidgets.textChanged.connect" />
|
||||
<option value="PySide2.QtCore.Signal.emit" />
|
||||
<option value="PySide2.QtCore.Signal.connect" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (v6d3losyash)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/v6d3losyash.iml" filepath="$PROJECT_DIR$/.idea/v6d3losyash.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
.idea/v6d3losyash.iml
Normal file
10
.idea/v6d3losyash.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?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>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM python:3.9
|
||||
WORKDIR /v6
|
||||
ENV v6root=/v6data
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
COPY v6d3losyash v6d3losyash
|
||||
CMD ["python3", "-m", "v6d3losyash.run-bot"]
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
aiohttp
|
||||
discord.py~=1.7.3
|
||||
git+https://gitea.ongoteam.net/PTV/v6d0auth.git
|
||||
git+https://gitea.ongoteam.net/PTV/v6d1tokens.git
|
0
v6d3losyash/__init__.py
Normal file
0
v6d3losyash/__init__.py
Normal file
44
v6d3losyash/app.py
Normal file
44
v6d3losyash/app.py
Normal file
@ -0,0 +1,44 @@
|
||||
import time
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
import discord
|
||||
from aiohttp import web
|
||||
from nacl.exceptions import BadSignatureError
|
||||
from v6d0auth import certs
|
||||
|
||||
|
||||
def define_routes(routes: web.RouteTableDef, client: discord.Client):
|
||||
@routes.get('/')
|
||||
async def home(_request: web.Request):
|
||||
return web.Response(body='v6d3losyash\n')
|
||||
|
||||
@routes.post('/stop')
|
||||
async def stop(request: web.Request):
|
||||
try:
|
||||
assert abs(float(certs.verify(await request.read())) - time.time()) < 1
|
||||
except ValueError:
|
||||
raise web.HTTPBadRequest
|
||||
except BadSignatureError:
|
||||
raise web.HTTPUnauthorized
|
||||
except AssertionError:
|
||||
raise web.HTTPRequestTimeout
|
||||
else:
|
||||
await client.change_presence(status=discord.Status.offline)
|
||||
await client.close()
|
||||
raise web.HTTPOk
|
||||
|
||||
|
||||
def app_routes(client: discord.Client) -> web.RouteTableDef:
|
||||
routes = web.RouteTableDef()
|
||||
define_routes(routes, client)
|
||||
return routes
|
||||
|
||||
|
||||
def app_with_routes(routes: web.RouteTableDef):
|
||||
app = web.Application()
|
||||
app.add_routes(routes)
|
||||
return app
|
||||
|
||||
|
||||
def get_app(client: discord.Client) -> web.Application:
|
||||
return app_with_routes(app_routes(client))
|
7
v6d3losyash/config.py
Normal file
7
v6d3losyash/config.py
Normal file
@ -0,0 +1,7 @@
|
||||
import os
|
||||
|
||||
guild = int(os.getenv('v6guild', 541241763042689025))
|
||||
emoji = int(os.getenv('v6emoji', 586669134406877270))
|
||||
role = int(os.getenv('v6role', 643896112977018880))
|
||||
message = int(os.getenv('v6message', 825385619097518110))
|
||||
channel = int(os.getenv('v6channel', 876814972968116224))
|
87
v6d3losyash/run-bot.py
Normal file
87
v6d3losyash/run-bot.py
Normal file
@ -0,0 +1,87 @@
|
||||
import asyncio
|
||||
from io import StringIO
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
import discord
|
||||
from v6d0auth.run_app import start_app
|
||||
from v6d1tokens.client import request_token
|
||||
|
||||
from v6d3losyash import config
|
||||
from v6d3losyash.app import get_app
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
token = loop.run_until_complete(request_token('losyash'))
|
||||
client = discord.Client(
|
||||
intents=discord.Intents(
|
||||
members=True,
|
||||
guilds=True,
|
||||
emojis=True,
|
||||
reactions=True,
|
||||
invites=True,
|
||||
bans=True,
|
||||
),
|
||||
)
|
||||
ESCAPED = '`_*\'"\\'
|
||||
|
||||
|
||||
def escape(s: str):
|
||||
res = StringIO()
|
||||
for c in s:
|
||||
if c in ESCAPED:
|
||||
c = '\\' + c
|
||||
res.write(c)
|
||||
return res.getvalue()
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print("ready")
|
||||
await client.change_presence(activity=discord.Game(
|
||||
name='феноменально',
|
||||
))
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_raw_reaction_add(payload: discord.RawReactionActionEvent):
|
||||
emoji: discord.Emoji = payload.emoji
|
||||
if emoji.id != config.emoji:
|
||||
return
|
||||
if payload.message_id != config.message:
|
||||
return
|
||||
guild: discord.Guild = client.get_guild(config.guild)
|
||||
member: discord.Member = guild.get_member(payload.user_id)
|
||||
role = guild.get_role(config.role)
|
||||
if role in member.roles:
|
||||
return
|
||||
await member.add_roles(role, reason='феноменально')
|
||||
|
||||
channel: discord.TextChannel = guild.get_channel(config.channel)
|
||||
await channel.send(f'{escape(str(member))} <:Jesus:586669134406877270>')
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_member_join(member: discord.Member):
|
||||
guild: discord.Guild = member.guild
|
||||
if guild.id != config.guild:
|
||||
return
|
||||
channel: discord.TextChannel = guild.get_channel(config.channel)
|
||||
await channel.send(f'{escape(str(member))} joined')
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_member_remove(member: discord.Member):
|
||||
guild: discord.Guild = member.guild
|
||||
if guild.id != config.guild:
|
||||
return
|
||||
channel: discord.TextChannel = guild.get_channel(config.channel)
|
||||
await channel.send(f'{escape(str(member))} left')
|
||||
|
||||
|
||||
async def main():
|
||||
await start_app(get_app(client))
|
||||
await client.login(token)
|
||||
await client.connect()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop.run_until_complete(main())
|
18
v6d3losyash/stop-bot.py
Normal file
18
v6d3losyash/stop-bot.py
Normal file
@ -0,0 +1,18 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
import aiohttp
|
||||
from v6d0auth import certs
|
||||
from v6d0auth.config import host, port
|
||||
|
||||
|
||||
async def main():
|
||||
request = certs.sign(str(time.time()).encode())
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# noinspection HttpUrlsUsage
|
||||
async with session.post(f'http://{host}:{port}/stop', data=request) as response:
|
||||
print(response.status)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
Loading…
Reference in New Issue
Block a user