v6d2ctx
This commit is contained in:
parent
1364e693d6
commit
075dbf7cdf
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.10 (v6d3vote)" 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/v6d3vote.iml" filepath="$PROJECT_DIR$/.idea/v6d3vote.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
.idea/v6d3vote.iml
Normal file
10
.idea/v6d3vote.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>
|
@ -1,4 +1,4 @@
|
||||
aiohttp~=3.7.4.post0
|
||||
discord.py
|
||||
git+https://gitea.ongoteam.net/PTV/v6d0auth.git
|
||||
git+https://gitea.ongoteam.net/PTV/v6d1tokens.git
|
||||
discord.py~=1.7.3
|
||||
git+https://gitea.ongoteam.net/PTV/v6d1tokens.git@2dca5338ecec2042f731ff2855225417f66e1372
|
||||
git+https://gitea.ongoteam.net/PTV/v6d2ctx.git@087aa39918a147ad9df7de35e6484ccb3efdc6c9
|
||||
|
@ -1,102 +0,0 @@
|
||||
import asyncio
|
||||
import time
|
||||
from io import StringIO
|
||||
from typing import Union, Optional, Callable, Awaitable
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
import discord
|
||||
|
||||
usertype = Union[discord.abc.User, discord.user.BaseUser, discord.Member, discord.User]
|
||||
|
||||
|
||||
class Context:
|
||||
def __init__(self, message: discord.Message):
|
||||
self.message: discord.Message = message
|
||||
self.channel: discord.abc.Messageable = message.channel
|
||||
self.dm_or_text: Union[discord.DMChannel, discord.TextChannel] = message.channel
|
||||
self.author: usertype = message.author
|
||||
self.content: str = message.content
|
||||
self.member: Optional[discord.Member] = message.author if isinstance(message.author, discord.Member) else None
|
||||
self.guild: Optional[discord.Guild] = None if self.member is None else self.member.guild
|
||||
|
||||
async def reply(self, content=None, **kwargs) -> discord.Message:
|
||||
return await self.message.reply(content, mention_author=False, **kwargs)
|
||||
|
||||
async def long(self, s: str):
|
||||
resio = StringIO(s)
|
||||
res = ''
|
||||
for line in resio:
|
||||
if len(res) + len(line) < 2000:
|
||||
res += line
|
||||
else:
|
||||
await self.reply(res)
|
||||
res = line
|
||||
if res:
|
||||
await self.reply(res)
|
||||
|
||||
|
||||
ESCAPED = '`_*\'"\\'
|
||||
|
||||
|
||||
def escape(s: str):
|
||||
res = StringIO()
|
||||
for c in s:
|
||||
if c in ESCAPED:
|
||||
c = '\\' + c
|
||||
res.write(c)
|
||||
return res.getvalue()
|
||||
|
||||
|
||||
buckets: dict[str, dict[str, Callable[[Context, list[str]], Awaitable[None]]]] = {}
|
||||
|
||||
|
||||
def at(bucket: str, name: str):
|
||||
def wrap(f: Callable[[Context, list[str]], Awaitable[None]]):
|
||||
buckets.setdefault(bucket, {})[name] = f
|
||||
|
||||
return f
|
||||
|
||||
return wrap
|
||||
|
||||
|
||||
class Explicit(Exception):
|
||||
def __init__(self, msg: str):
|
||||
self.msg = msg
|
||||
|
||||
|
||||
class Implicit(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def of(bucket: str, name: str) -> Callable[[Context, list[str]], Awaitable[None]]:
|
||||
try:
|
||||
return buckets[bucket][name]
|
||||
except KeyError:
|
||||
raise Implicit
|
||||
|
||||
|
||||
benchmarks: dict[str, dict[str, float]] = {}
|
||||
_t = time.perf_counter()
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, benchmark: str):
|
||||
self.benchmark = benchmark
|
||||
|
||||
def __enter__(self):
|
||||
self.t = time.perf_counter()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
d = (time.perf_counter() - self.t)
|
||||
benchmarks.setdefault(self.benchmark, {'integral': 0.0, 'max': 0.0})
|
||||
benchmarks[self.benchmark]['integral'] += d
|
||||
benchmarks[self.benchmark]['max'] = max(benchmarks[self.benchmark]['max'], d)
|
||||
|
||||
|
||||
async def monitor():
|
||||
while True:
|
||||
await asyncio.sleep(10)
|
||||
dt = time.perf_counter() - _t
|
||||
print('Benchmarks:')
|
||||
for benchmark, metrics in benchmarks.items():
|
||||
print(benchmark, '=', metrics['integral'] / max(dt, .00001), ':', metrics['max'])
|
@ -8,9 +8,9 @@ import discord
|
||||
from ptvp35 import Db, KVJson
|
||||
from v6d0auth.config import root
|
||||
from v6d1tokens.client import request_token
|
||||
from v6d2ctx.context import Context, of, at, Implicit, monitor, Explicit
|
||||
|
||||
from v6d3vote.config import prefix
|
||||
from v6d3vote.context import Context, of, at, Implicit, monitor, Explicit
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
Loading…
Reference in New Issue
Block a user