updated apis
This commit is contained in:
parent
075dbf7cdf
commit
3f84fe60ec
1
example.sh
Normal file
1
example.sh
Normal file
@ -0,0 +1 @@
|
||||
docker run -v v6d3vote:/v6data --env v6ca=da5261eb5232b4b08452f25099b53b59d2e308b86aaf9c4204f0aa92569044d7 --env v6caurl=http://172.18.0.2:5900 --env v6taurl=http://172.18.0.3:5910 --name v6d3vote -m 500mb --cpus 0,5 --network v6d v6d3vote
|
@ -1,4 +1,4 @@
|
||||
aiohttp~=3.7.4.post0
|
||||
discord.py~=1.7.3
|
||||
git+https://gitea.ongoteam.net/PTV/v6d1tokens.git@2dca5338ecec2042f731ff2855225417f66e1372
|
||||
git+https://gitea.ongoteam.net/PTV/v6d2ctx.git@087aa39918a147ad9df7de35e6484ccb3efdc6c9
|
||||
git+https://gitea.ongoteam.net/PTV/v6d1tokens.git@8b525ee05be22891a1c18d5e96153807f79930be
|
||||
git+https://gitea.ongoteam.net/PTV/v6d2ctx.git@57919e65069e62fc31666adebd6c107be067b724
|
||||
|
@ -1,3 +1,7 @@
|
||||
import os
|
||||
|
||||
from v6d0auth.config import root
|
||||
|
||||
prefix = os.getenv('v6prefix', '??')
|
||||
myroot = root / 'v6d3vote'
|
||||
myroot.mkdir(exist_ok=True)
|
||||
|
@ -1,20 +1,20 @@
|
||||
import asyncio
|
||||
import os
|
||||
import shlex
|
||||
from typing import Optional
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
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 v6d2ctx.context import Context, at, monitor, Explicit
|
||||
from v6d2ctx.handle_content import handle_content
|
||||
from v6d2ctx.lock_for import lock_for
|
||||
from v6d2ctx.serve import serve
|
||||
|
||||
from v6d3vote.config import prefix
|
||||
from v6d3vote.config import prefix, myroot
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
token = loop.run_until_complete(request_token('vote'))
|
||||
token = loop.run_until_complete(request_token('vote', 'token'))
|
||||
client = discord.Client(
|
||||
intents=discord.Intents(
|
||||
members=True,
|
||||
@ -26,8 +26,6 @@ client = discord.Client(
|
||||
reactions=True
|
||||
),
|
||||
)
|
||||
myroot = root / 'v6d3vote'
|
||||
myroot.mkdir(exist_ok=True)
|
||||
vote_db = Db(myroot / 'vote.db', kvrequest_type=KVJson)
|
||||
|
||||
|
||||
@ -39,10 +37,6 @@ async def on_ready():
|
||||
))
|
||||
|
||||
|
||||
async def handle_command(ctx: Context, name: str, args: list[str]) -> None:
|
||||
await of('commands', name)(ctx, args)
|
||||
|
||||
|
||||
@at('commands', 'help')
|
||||
async def help_(ctx: Context, args: list[str]) -> None:
|
||||
match args:
|
||||
@ -100,7 +94,7 @@ class Poll:
|
||||
@classmethod
|
||||
async def create(cls, ctx: Context, options: list[tuple[str, discord.Emoji | str]], title: str):
|
||||
message: discord.Message = await ctx.reply('creating poll...')
|
||||
async with lock_for(message):
|
||||
async with lock_for(message, 'failed to create poll'):
|
||||
poll = Poll(
|
||||
message,
|
||||
{},
|
||||
@ -148,7 +142,7 @@ class Poll:
|
||||
message: discord.Message = await channel.fetch_message(rrae.message_id)
|
||||
if message.author != client.user:
|
||||
return
|
||||
async with lock_for(message):
|
||||
async with lock_for(message, 'no message'):
|
||||
poll = await cls.load(message)
|
||||
if poll is None:
|
||||
return
|
||||
@ -168,18 +162,6 @@ class Poll:
|
||||
await self.message.remove_reaction(other_reaction.emoji, member)
|
||||
|
||||
|
||||
locks: dict[discord.Message, asyncio.Lock] = {}
|
||||
|
||||
|
||||
def lock_for(message: discord.Message) -> asyncio.Lock:
|
||||
if message is None:
|
||||
raise Explicit('not in a guild')
|
||||
if message in locks:
|
||||
return locks[message]
|
||||
else:
|
||||
return locks.setdefault(message, asyncio.Lock())
|
||||
|
||||
|
||||
async def poll_options(args: list[str]) -> list[tuple[str, discord.Emoji | str]]:
|
||||
options: list[tuple[str, discord.Emoji | str]] = []
|
||||
while args:
|
||||
@ -208,30 +190,9 @@ async def create_poll(ctx: Context, args: list[str]) -> None:
|
||||
await Poll.create(ctx, await poll_options(args), title)
|
||||
|
||||
|
||||
async def handle_args(message: discord.Message, args: list[str]):
|
||||
match args:
|
||||
case []:
|
||||
return
|
||||
case [command_name, *command_args]:
|
||||
ctx = Context(message)
|
||||
try:
|
||||
await handle_command(ctx, command_name, command_args)
|
||||
except Implicit:
|
||||
pass
|
||||
except Explicit as e:
|
||||
await ctx.reply(e.msg)
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_message(message: discord.Message) -> None:
|
||||
if message.author.bot:
|
||||
return
|
||||
content: str = message.content
|
||||
if not content.startswith(prefix):
|
||||
return
|
||||
content = content.removeprefix(prefix)
|
||||
args = shlex.split(content)
|
||||
await handle_args(message, args)
|
||||
await handle_content(message, message.content, prefix)
|
||||
|
||||
|
||||
@client.event
|
||||
@ -253,4 +214,4 @@ async def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop.run_until_complete(main())
|
||||
serve(main(), client, loop)
|
||||
|
Loading…
Reference in New Issue
Block a user