constitution spam
This commit is contained in:
parent
4da87fc1ee
commit
53c8710003
@ -7,4 +7,5 @@ RUN pip install -r base.requirements.txt
|
|||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
COPY v6d3losyash v6d3losyash
|
COPY v6d3losyash v6d3losyash
|
||||||
|
COPY constitution constitution
|
||||||
CMD ["python3", "-m", "v6d3losyash.run-bot"]
|
CMD ["python3", "-m", "v6d3losyash.run-bot"]
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 74dcbf9fb6f0abb13eb4f7827f6a38d6bfd4d8ec
|
Subproject commit e09f773881751bde0b1daba4d626d681026c9c55
|
@ -1,12 +1,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import re
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import Union, Optional
|
from pathlib import Path
|
||||||
|
from typing import Optional, Union
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from ptvp35 import KVJson, Db
|
|
||||||
|
from ptvp35 import Db, KVJson
|
||||||
from v6d1tokens.client import request_token
|
from v6d1tokens.client import request_token
|
||||||
from v6d2ctx.serve import serve
|
from v6d2ctx.serve import serve
|
||||||
|
|
||||||
from v6d3losyash import config
|
from v6d3losyash import config
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
@ -36,7 +38,63 @@ def escape(s: str):
|
|||||||
return res.getvalue()
|
return res.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
class Spam:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.spammed = False
|
||||||
|
self.root = Path(__file__).parent / '../constitution'
|
||||||
|
|
||||||
|
def format_segment(self, segment: str) -> str:
|
||||||
|
segment = re.sub(
|
||||||
|
r'\[[\d.xX]*?\]',
|
||||||
|
lambda m: f'\u001b[0;1;36m{m[0]}\u001b[0m',
|
||||||
|
segment,
|
||||||
|
)
|
||||||
|
segment = re.sub(
|
||||||
|
r'\#[\w-]*',
|
||||||
|
lambda m: f'\u001b[0;34m{m[0]}\u001b[0m',
|
||||||
|
segment,
|
||||||
|
)
|
||||||
|
segment = re.sub(
|
||||||
|
r'\:\:',
|
||||||
|
lambda m: f'\u001b[0;31;41m{m[0]}\u001b[0m',
|
||||||
|
segment,
|
||||||
|
)
|
||||||
|
segment = re.sub(
|
||||||
|
r'\@(\[.*?\])',
|
||||||
|
lambda m: f'\u001b[0;33m{m[1]}\u001b[0m',
|
||||||
|
segment,
|
||||||
|
)
|
||||||
|
segment = re.sub(
|
||||||
|
r'\{([\d;]*)\:(.*?)\}',
|
||||||
|
lambda m: f'\u001b[0;{m[1]}m{m[2]}\u001b[0m',
|
||||||
|
segment,
|
||||||
|
)
|
||||||
|
return segment
|
||||||
|
|
||||||
|
def ru_segments(self) -> list[str]:
|
||||||
|
return list(map(self.format_segment, (self.root / 'ru.md').read_text().split('=' * 80)))
|
||||||
|
|
||||||
|
async def spam(self) -> None:
|
||||||
|
if self.spammed:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
print('spamming')
|
||||||
|
guild = await client.fetch_guild(config.guild)
|
||||||
|
channel = await guild.fetch_channel(1056432869834240080)
|
||||||
|
assert isinstance(channel, discord.abc.Messageable)
|
||||||
|
segments = await asyncio.to_thread(self.ru_segments)
|
||||||
|
for segment in segments:
|
||||||
|
await channel.send(segment.strip())
|
||||||
|
except:
|
||||||
|
from traceback import print_exc
|
||||||
|
print_exc()
|
||||||
|
finally:
|
||||||
|
print('spammed')
|
||||||
|
self.spammed = True
|
||||||
|
|
||||||
|
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
|
spam = Spam()
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
@ -45,8 +103,10 @@ async def on_ready():
|
|||||||
await client.change_presence(activity=discord.Game(
|
await client.change_presence(activity=discord.Game(
|
||||||
name='феноменально',
|
name='феноменально',
|
||||||
))
|
))
|
||||||
|
task = asyncio.create_task(spam.spam())
|
||||||
async with lock:
|
async with lock:
|
||||||
await state.reload()
|
await state.reload()
|
||||||
|
await task
|
||||||
|
|
||||||
|
|
||||||
class SimpleEmoji:
|
class SimpleEmoji:
|
||||||
|
Loading…
Reference in New Issue
Block a user