-
Notifications
You must be signed in to change notification settings - Fork 0
/
backlog.py
52 lines (40 loc) · 1.53 KB
/
backlog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# backlog.py
from responder import Responder
RESPONDER_ID = 'backlog'
CHANNEL_ID = 1085672769716494356
def check(message):
if message.channel.id != CHANNEL_ID:
return False # wrong server
return True
async def refresh(channel):
total = 0
unreacted = 0
async for m in channel.history(limit=None):
total += 1
if not m.reactions:
unreacted += 1
await channel.edit(topic=f'Remaining: {unreacted}/{total} ({unreacted / total * 100:.1f}% listened)')
def load(core):
register_responder = core.exports.get('responder/register')
register_command = core.exports.get('command/register')
register_hook = core.exports.get('register_hook')
async def updatebacklog(message, args):
if message.channel.id != CHANNEL_ID:
return
await message.delete()
await refresh(message.channel)
if register_command():
register_command()('updatebacklog', updatebacklog, [])
print('registered wordle commands')
backlog_responder = Responder(check, lambda message: refresh(message.channel))
backlog_responder.id = RESPONDER_ID
if register_responder():
register_responder()(backlog_responder, priority=True)
print('registered backlog responder')
async def react_hook(message, reaction):
if message.channel.id != CHANNEL_ID:
return
await refresh(message)
if register_hook():
register_hook()('member_join', 'wordleserver', react_hook)
print('registered backlog reaction hook')