@@ -13,7 +13,7 @@ class ChannelApi(token: String)(implicit mat: ActorMaterializer) extends Discord
13
13
import ChannelApi ._
14
14
15
15
override def pipeHttpApiRequest : Receive = {
16
- case Message (channelId , content) => tellChannelRequestBundle(channelId, content)
16
+ case msg @ Message (_ , content) => tellChannelRequestBundle(msg, MessagePayload ( content) )
17
17
case bundle : ChannelRequestBundle => pipeChannelRequest(bundle)
18
18
}
19
19
@@ -27,17 +27,17 @@ class ChannelApi(token: String)(implicit mat: ActorMaterializer) extends Discord
27
27
.pipeTo(self)
28
28
}
29
29
30
- private def tellChannelRequestBundle (channelId : String , content : String ): Unit = {
31
- val (method, uri) = createMessageEndpoint(channelId)
32
- val channelEntity = MessagePayload (content)
33
- self ! ChannelRequestBundle (channelId, method, uri, channelEntity)
30
+ private def tellChannelRequestBundle (msg : Message , payload : ChannelPayload ) = {
31
+ val (method, uri) = getEndpoint(msg)
32
+ self ! ChannelRequestBundle (msg.channelId, method, uri, payload)
34
33
}
35
34
}
36
35
37
36
object ChannelApi {
38
37
import DiscordApi ._
39
38
40
- case class Message (channelId : String , content : String )
39
+ trait ChannelRequest
40
+ case class Message (channelId : String , content : String ) extends ChannelRequest
41
41
42
42
sealed trait ChannelPayload
43
43
case class MessagePayload (content : String ) extends ChannelPayload
@@ -56,6 +56,11 @@ object ChannelApi {
56
56
}
57
57
}
58
58
59
+ private def getEndpoint (req : ChannelRequest ) = {
60
+ req match {
61
+ case Message (id, _) => (HttpMethods .POST , s " $baseUrl/channels/ $id/messages " )
62
+ }
63
+ }
59
64
private def createMessageEndpoint (channelId : String ): (HttpMethod , String ) =
60
65
(HttpMethods .POST , s " $baseUrl/channels/ $channelId/messages " )
61
66
0 commit comments