This repository has been archived by the owner on May 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
71 lines (58 loc) · 2.45 KB
/
demo.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import discord
from modules.botModule import *
from tinydb import TinyDB, Query
import shlex
import time
import math
import reactionscroll
class ReactionTest(BotModule):
name = 'reactiontest'
description = 'Testing reaction based scrolling'
help_text = '`!reactiontest` to trigger a demo.'
trigger_string = 'reactiontest'
module_version = '1.0.0'
listen_for_reaction = True
# Instead of using TinyDB, since scubot can't work with reactions persistently a list should be used
message_returns = []
async def contains_returns(self, message):
for x in self.message_returns:
if message.id == x[0].id:
return True
return False
async def find_pos(self, message):
for x in self.message_returns:
if message.id == x[0].id:
return x[1]
async def update_pos(self, message, ty):
for x in self.message_returns:
if message.id == x[0].id:
if ty == 'next':
x[1] += 1
if ty == 'prev':
x[1] -= 1
async def parse_command(self, message, client):
self.module_db.purge()
for x in range(1, 16):
self.module_db.insert({'foo': x})
self.scroll = reactionscroll.Scrollable(limit=4, color=0xc0fefe, table=self.module_db, title="Demo", inline=True)
self.scroll.refresh(field='foo')
message_return = await client.send_message(message.channel, embed=self.scroll.initial_embed())
self.message_returns.append([message_return, 0])
await client.add_reaction(message_return, "⏪")
await client.add_reaction(message_return, "⏩") # Ugh
# Now we hand off to the reaction command
async def on_reaction_add(self, reaction, client, user):
if not await self.contains_returns(reaction.message):
return 0
pos = await self.find_pos(reaction.message)
react_text = reaction.emoji
if type(reaction.emoji) is not str:
react_text = reaction.emoji.name
if react_text == "⏩":
embed = self.scroll.next(current_pos=pos)
await client.edit_message(reaction.message, embed=embed)
await self.update_pos(reaction.message, 'next')
if react_text == "⏪":
embed = self.scroll.previous(current_pos=pos)
await client.edit_message(reaction.message, embed=embed)
await self.update_pos(reaction.message, 'prev')