Skip to content

Commit

Permalink
✨ Adds proper docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Streamer272 committed Feb 5, 2024
1 parent 344b088 commit 84584d4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 37 deletions.
22 changes: 22 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
/.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### VS Code ###
.vscode/

### ENV ###
src/main/resources/.env
.env
creds/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ out/
### ENV ###
src/main/resources/.env
.env
automod.json
creds/gcloud.json
creds/discord
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM gradle:jdk17 AS build
FROM gradle:jdk17

WORKDIR /app
COPY --chown=gradle:gradle . .

RUN gradle build
ENV GOOGLE_APPLICATION_CREDENTIALS=/app/automod.json

CMD ["gradle", "run"]
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# automod

## Build with
### Build the image

```
docker build . --tag automod:latest
docker compose build
```

## Run with
### Run the image

```
docker run --rm --name automod automod:latest
docker compose -p automod up -d
```

Make sure you put `gcloud.json` service account and `discord` bot token in creds folder before running!
Empty file added creds/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.8"
services:
bot:
build: .
restart: unless-stopped

environment:
DISCORD_TOKEN: /app/creds/discord
SERVICE_ACCOUNT: /app/creds/gcloud.json
PING_INTERVAL: 10
ITERATION_COUNT: 10
volumes:
- ./creds:/app/creds
64 changes: 34 additions & 30 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ suspend fun main() {
val dotenv = Dotenv.configure().ignoreIfMissing().load()
val logger = KotlinLogging.logger("main")

val token = dotenv.get("TOKEN") ?: throw Exception("Token not found")
val serviceAccountPath = dotenv.get("SERVICE_ACCOUNT") ?: throw Exception("Service account not found")
val tokenPath = dotenv["DISCORD_TOKEN"] ?: throw Exception("Token not found")
val token = File(tokenPath).readText()
val serviceAccountPath = dotenv["SERVICE_ACCOUNT"] ?: throw Exception("Service account not found")
val serviceAccount = File(serviceAccountPath).inputStream()
val pingInterval = dotenv.get("PING_INTERVAL").toIntOrNull() ?: 10
val iterationCount = dotenv.get("ITERATION_COUNT").toIntOrNull() ?: 60
val pingInterval = dotenv.get("PING_INTERVAL", "10").toInt()
val iterationCount = dotenv.get("ITERATION_COUNT", "60").toInt()
val enableBussy = dotenv.get("ENABLE_BUSSY", "false") == "true"

logger.debug { "Getting Firebase app" }
val options: FirebaseOptions = FirebaseOptions.builder()
Expand Down Expand Up @@ -104,39 +106,41 @@ suspend fun main() {
setStatus("Fucking your mom", UserStatus.DO_NOT_DISTURB)
logger.info { "Starting app as ${it.user.username}#${it.user.discriminator}" }

CoroutineScope(Dispatchers.Default).launch {
val picked: MutableList<GuildMember> = mutableListOf()
if (enableBussy) {
CoroutineScope(Dispatchers.Default).launch {
val picked: MutableList<GuildMember> = mutableListOf()

while (isActive) {
if (bussies.size == 0) {
delay(pingInterval.seconds)
continue
}
while (isActive) {
if (bussies.size == 0) {
delay(pingInterval.seconds)
continue
}

if (bussyIteration == iterationCount || bussyIteration == 0) {
logger.debug { "Refreshing users" }
picked.clear()
if (bussyIteration == iterationCount || bussyIteration == 0) {
logger.debug { "Refreshing users" }
picked.clear()

bussies.forEach { bussy ->
val members = guild(bussy.serverId).getMembers(100)
picked += members[members.indices.random()]
}

bussies.forEach { bussy ->
val members = guild(bussy.serverId).getMembers(100)
picked += members[members.indices.random()]
bussyIteration = 0
}

bussyIteration = 0
}
bussies.forEachIndexed { index, bussy ->
val target = picked.getOrNull(index)
target
?.user
?.id
?.let { id ->
channel(bussy.channelId).sendMessage(bussy.message.replace("@author", "<@$id>"))
}
}

bussies.forEachIndexed { index, bussy ->
val target = picked.getOrNull(index)
target
?.user
?.id
?.let { id ->
channel(bussy.channelId).sendMessage(bussy.message.replace("@author", "<@$id>"))
}
delay(pingInterval.seconds)
bussyIteration++
}

delay(pingInterval.seconds)
bussyIteration++
}
}
}
Expand Down

0 comments on commit 84584d4

Please sign in to comment.