-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
render.py
68 lines (57 loc) · 2.23 KB
/
render.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
import textwrap
from discord.ext.commands import Context
from discord.message import Message
from enum import Enum
from objection_engine.beans.comment import Comment
from typing import List
class State(Enum):
QUEUED = 0
INPROGRESS = 1
FAILED = 2
RENDERED = 3
UPLOADING = 4
DONE = 5
class Render:
def __init__(self, state: State, discordContext: Context, feedbackMessage: Message, messages: List[Comment], music: str):
self.state = state
self.discordContext = discordContext
self.feedbackMessage = feedbackMessage
self.messages = messages
self.outputFilename = f"{str(discordContext.message.id)}.mp4"
self.music_code = music
def getStateString(self):
if self.state == State.QUEUED:
return "Queued"
if self.state == State.INPROGRESS:
return "In progress"
if self.state == State.FAILED:
return "Failed"
if self.state == State.RENDERED:
return "Rendered"
if self.state == State.UPLOADING:
return "Uploading"
if self.state == State.DONE:
return "Done"
def getState(self):
return self.state
def getContext(self):
return self.discordContext
def getFeedbackMessage(self):
return self.feedbackMessage
def getMessages(self):
return self.messages
def getOutputFilename(self):
return self.outputFilename
def setState(self, state: State):
self.state = state
async def updateFeedback(self, newContent: str):
try:
newContent = textwrap.dedent(newContent).strip("\n")
# Feedback messages will only be updated if their content is different to the new Content, to avoid spamming Discord's API
if self.feedbackMessage.content != newContent:
await self.feedbackMessage.edit(content=newContent)
# If it's unable to edit/get the feedback message, it will raise an exception and that means that it no longer exists
except Exception as exception:
# If it doesn't exists, we will repost it.
print(f"Error: {exception}")
self.feedbackMessage = await self.discordContext.send(content=newContent)