-
Notifications
You must be signed in to change notification settings - Fork 1
/
JnaExampleActor.kt
76 lines (67 loc) · 2.56 KB
/
JnaExampleActor.kt
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
72
73
74
75
76
/*
* Copyright (c) 2019 Arnaud 'Bluexin' Solé
*
* This file is part of drpc4k.
*
* drpc4k is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* drpc4k is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with drpc4k. If not, see <http://www.gnu.org/licenses/>.
*/
import be.bluexin.drpc4k.jna.DiscordRichPresence
import be.bluexin.drpc4k.jna.RPCInputMessage
import be.bluexin.drpc4k.jna.RPCOutputMessage
import be.bluexin.drpc4k.jna.rpcActor
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import mu.KotlinLogging
import kotlin.random.Random
private val logger = KotlinLogging.logger { }
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
fun main(args: Array<String>) = runBlocking {
if (args.isEmpty()) {
logger.error("Missing Client ID")
return@runBlocking
}
val rpcOutput = Channel<RPCOutputMessage>(capacity = Channel.UNLIMITED)
val rpcInput = rpcActor(rpcOutput)
val presence = DiscordRichPresence {
details = "Raid: Kill Migas"
state = "Recruiting"
partyId = "Awesome Party ID"
partySize = Random.nextInt(20) + 1
partyMax = 24
setDuration(1200L)
smallImageKey = "ia_sakura_water"
largeImageKey = "ia_sakura_water"
smallImageText = "OwO smol"
largeImageText = "OwO big"
joinSecret = "anawesomesecret"
spectateSecret = "anawesomesecret2"
}
launch {
for (msg in rpcOutput) with(msg) {
when (this) {
is RPCOutputMessage.Ready -> with(user) { logger.info("Logged in as $username#$discriminator") }
is RPCOutputMessage.Disconnected -> logger.warn("Disconnected: #$errorCode (${message.takeIf { message.isNotEmpty() }
?: "No message provided"})")
is RPCOutputMessage.Errored -> logger.error("Error: #$errorCode (${message.takeIf { message.isNotEmpty() }
?: "No message provided"})")
}
}
}
rpcInput.send(RPCInputMessage.Connect(args[0]))
rpcInput.send(RPCInputMessage.UpdatePresence(presence))
delay(10000)
rpcInput.close()
delay(500)
}