Add InteractionMessage and InteractionMessageAccessor abstractions
Closed this issue · 0 comments
alikindsys commented
InteractionMessage:
implspec:
concept: interface delegation
class InteractionMessage "imsg" : delegate(DiscordMessage)
val Interaction owner
override DiscordMessage.Edit():
intr.Modify
override DiscordMessage.Delete():
intr.Remove
async waitDelete()
async waitEdit()
async waitReaction{Toggle|Add|Remove}(pred?)
event OnEdit
event OnDelete
event OnReaction{Toggle|Add|Remove}
class Interaction:
async InteractionMessage SendMessage()
async InteractionMessage GetUserResponse()
void Dispatch() {
foreach(message) if(message.wants(event)) message.Dispatch(event)
}
example usages:
intr.Origin.OnReactToggle += async (e) => ...
// instead of
intr.OnOriginReactToggle += ...
var imsg = await intr.SendMessageAsync();
imsg.AddReaction(":trash:");
imsg.OnReactionToggle += async (e) => {
if (e.Emoji != ":trash:") return;
ismg.Delete();
}
InteractionMessageAccessor:
implspec:
class InteractionMessageAccessor:
val Interaction owner
event On...
...
async Wait...
...
void Dispatch(EventArgs)
class ListInteractionAccessor : InteractionMessageAccessor:
mode = User | Bot | All
List<InteractionMessage> Get();
SingleAccessor First, Last
class SingleInteractionAccessor : InteractionMessageAccessor:
val ListAccessor parent
mode = First | Last
InteractionMessage Get();
class Interaction:
ListAccessor BotMessages
ListAccessor UserMessages
ListAccessor AllMessages
SingleAccessor Origin = UserMessages.First
SingleAccessor LatestMessage = AllMessages.Last
void Interaction.Dispatch {
...
foreach (accessor) if (accessor.wants(event)) accessor.Dispatch(event)
}
example usages:
intr.UserMessages.Last.OnReactionAdd += ...
// NOT the same as
var imsg = ... // get latest user message
imsg.OnReactionAdd += ...