Compare commits

...

85 commits

Author SHA1 Message Date
f762e18b1f chore: update names in action.yml
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m41s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 13:24:46 +02:00
c7b03d49c9 Update .forgejo/workflows/action.yml 2023-09-17 13:23:13 +02:00
55fafa29c5 chore: update names in action.yml
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 13:22:34 +02:00
d789b5ee64 chore: update README.md
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 4m13s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 13:20:41 +02:00
967492685a chore: update README.md
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 4m16s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 13:17:14 +02:00
e9fac0d687 fix: fixed removed functions
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 4m16s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 12:59:54 +02:00
d2af0fce94 chore!: upgrade dependencies & gradle (7.4.2 -> 8.3)
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-17 12:58:15 +02:00
672982ef37 chore: bump version
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m52s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-15 23:37:06 +02:00
95c22c6bd0 feat: moved all transactions into one package for reuse and simplicity
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m52s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-15 22:50:16 +02:00
e27efe094c chore: removed unused comment
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-15 22:49:12 +02:00
b77271517d chore: fixed naming in data objects
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m49s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 18:31:45 +02:00
99c607efd4 feat: added TimePlanningChannelsData
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 18:30:12 +02:00
fdf63c4605 chore: bump version
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m55s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 12:42:49 +02:00
caa5d49bad fix!: Changed all colors to EmbedColor
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m42s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 12:36:19 +02:00
8d14597a38 feat: make embed helper functions use EmbedColor instead of color
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 12:34:27 +02:00
dcdb5c6e56 feat: added EmbedColor
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 12:27:53 +02:00
af15f7eb73 chore: removed unused open modifier in IEditButton
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m35s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 09:46:19 +02:00
36f931b919 feat: improved UpdateRolesExtension
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m37s
chore: updated UpdateRolesExtension Documentation

Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 09:43:36 +02:00
39fb3ba7d6 chore: updated SendPlannerExtension documentation
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 09:42:29 +02:00
99964d7981 !feat: removed TestExtension.kt
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 09:41:43 +02:00
8a77b275dc feat: Bot now skips Bot Users
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 09:41:27 +02:00
3d1f2c7d8f chore: bump version
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m54s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 07:46:07 +02:00
7e0c8e5a9f feat: moved update logic into "updateInChannel" function, updated the function in Timeplanner buttons
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-14 07:44:43 +02:00
de1d8cd3a6 fix: fixed grammar
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m54s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 14:46:40 +02:00
990387fed2 chore: bump version
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m52s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 14:26:43 +02:00
4f8924fb1a Merge pull request 'chore: moved to proper data types in columns' (#3) from chore/cleanup-db into master
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m57s
Reviewed-on: #3
2023-09-11 13:49:47 +02:00
1424e31e2a chore: moved to proper data types in columns
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m45s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 13:35:17 +02:00
d97511eb8b chore: bump version
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m53s
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:48:33 +02:00
63fb1c0c8f feat: added DeclineEditButton
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:47:31 +02:00
308da65105 feat: improved function of AcceptEditButton
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:47:06 +02:00
9400a21403 feat: added Unavailable to MatchExtension table
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:46:33 +02:00
f7b701de20 feat: improved replaceXWithYinValuesAtTable function, edited MatchButtons
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:45:51 +02:00
165e1d342c feat: improved getAClonedEmbed function, added an equivalent using a EmbedBuilder
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-11 12:44:34 +02:00
883940c8fd Merge remote-tracking branch 'origin/master'
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 4m13s
2023-09-06 22:10:39 +02:00
18cd26c456 chore: bump version
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 22:10:17 +02:00
a3c1344f1a feat: Roles now update on button press
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 22:09:59 +02:00
f552ea4faa chore: improved readability
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 22:06:14 +02:00
d10f8901c9 fix: fixed AvailabilityManager
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 22:05:29 +02:00
925398db65 fix: fixed weekstamp
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 22:03:50 +02:00
b258747086 chore: improved imports
Signed-off-by: moonleay <contact@moonleay.net>
2023-09-06 21:59:41 +02:00
500ad1a912 Update .forgejo/workflows/action.yml
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m37s
2023-08-18 11:44:43 +02:00
862206e1d5 Update .forgejo/workflows/action.yml
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 2m30s
2023-08-18 11:40:51 +02:00
9f28aecd57 Update .forgejo/workflows/action.yml
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 3m46s
2023-08-18 11:25:30 +02:00
7bf0f8d56e Update .forgejo/workflows/action.yml 2023-08-18 11:24:48 +02:00
91e4dfde60 Update .forgejo/workflows/action.yml
All checks were successful
Build Gradle project / build-gradle-project (push) Successful in 3m17s
2023-08-18 11:16:47 +02:00
9305118f4a Update .forgejo/workflows/action.yml
Some checks failed
Build Gradle project / build-gradle-project (push) Failing after 1m16s
2023-08-18 11:13:03 +02:00
c638021326 Update .forgejo/workflows/action.yml
Some checks reported warnings
Build Gradle project / build-gradle-project (push) Has been cancelled
2023-08-18 09:20:31 +02:00
937541cf61 Update .forgejo/workflows/action.yml
Some checks failed
Build Gradle project / build-gradle-project (push) Failing after 8s
2023-08-18 09:00:23 +02:00
81d248bfb7 Update .forgejo/workflows/action.yml
Some checks reported warnings
Build Gradle project / build-gradle-project (push) Has been cancelled
2023-08-18 08:56:42 +02:00
3018918bff Update .forgejo/workflows/action.yml 2023-08-18 08:55:04 +02:00
9c1842d4f7 Update .forgejo/workflows/action.yml
Some checks failed
Build Gradle project / build-gradle-project (push) Failing after 7s
2023-08-18 08:53:44 +02:00
cf1fed51c3 Update .forgejo/workflows/action.yml
Some checks failed
Build Gradle project / build-gradle-project (push) Failing after 1m9s
2023-08-12 14:12:10 +02:00
9847192074 Update .forgejo/workflows/action.yml 2023-08-12 14:10:43 +02:00
a45d4ae26d Update .forgejo/workflows/action.yml 2023-08-12 14:09:39 +02:00
fc6824cd5e Update .forgejo/workflows/action.yml 2023-08-12 14:09:21 +02:00
1e65e609e1 Update .forgejo/workflows/action.yml
Signed-off-by: moonleay <account@moonleay.net>
2023-08-12 14:06:37 +02:00
a75a70b689 Update .forgejo/workflows/action.yml
Signed-off-by: moonleay <account@moonleay.net>
2023-08-12 14:04:55 +02:00
08b6601663 Update .forgejo/workflows/action.yml
Signed-off-by: moonleay <account@moonleay.net>
2023-08-12 14:02:50 +02:00
619be85353 Update .forgejo/workflows/action.yml
Signed-off-by: moonleay <account@moonleay.net>
2023-08-12 13:47:55 +02:00
c4233a7b6b fix> update ci
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 19:04:47 +02:00
149ce7d5c6 fix> update ci
Some checks failed
/ build_and_publish (push) Failing after 8s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 18:54:14 +02:00
bf8bc013d9 fix> update ci
Some checks failed
/ build_and_publish (push) Failing after 27s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 18:36:48 +02:00
0928d84b9a fix> update ci
Some checks failed
/ build_and_publish (push) Failing after 3s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 18:36:08 +02:00
e215f556e7 fix> update ci
Some checks failed
/ build_and_publish (push) Failing after 1m57s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 18:27:00 +02:00
90f9dd15c9 fix> update ci
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 18:01:12 +02:00
6b0c5058ab feat moved action.yml
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:41:04 +02:00
7d15ef910b feat moved action.yml
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:39:59 +02:00
d9cedb702b fix: fixed build.yml?????????????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:25:08 +02:00
6b391f2e4d fix: fixed build.yml????????????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:23:20 +02:00
4cc3fae4ab fix: fixed build.yml???????????????
Some checks failed
/ build_and_publish (push) Failing after 3s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:20:17 +02:00
9d68e9aebb fix: fixed build.yml??????????????
Some checks failed
/ build_and_publish (push) Failing after 3s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:19:40 +02:00
7dbae9a330 fix: fixed build.yml?????????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:18:42 +02:00
e344c9bd3a fix: fixed build.yml????????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:17:47 +02:00
02d95b7d12 fix: fixed build.yml???????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:15:48 +02:00
f3497f9a2b fix: fixed build.yml??????????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 02:00:07 +02:00
eb7ac71dd5 fix: fixed build.yml?????????
Some checks failed
/ Build (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 01:57:02 +02:00
9273b4b168 fix: fixed build.yml????????
Some checks reported warnings
/ Build (push) Has been cancelled
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 01:55:59 +02:00
c4b00aa9a5 fix: fixed build.yml???????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-05 01:40:41 +02:00
a2436cb002 fix: fixed build.yml??????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:32:45 +02:00
04fa9ad59a fix: fixed build.yml?????
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:30:17 +02:00
cd84d02608 fix: fixed build.yml????
Some checks failed
/ build_and_publish (push) Failing after 5s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:28:10 +02:00
2bfc327ceb fix: fixed build.yml???
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:25:46 +02:00
38832e1c0d fix: fixed build.yml??
Some checks failed
/ build_and_publish (push) Failing after 5s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:23:16 +02:00
7f2e74ff6c fix: fixed build.yml?
Some checks failed
/ build_and_publish (push) Failing after 3s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:22:29 +02:00
a93499cfb8 fix: fixed build.yml
Some checks failed
/ build_and_publish (push) Failing after 2s
Signed-off-by: moonleay <contact@moonleay.net>
2023-08-04 21:17:52 +02:00
43 changed files with 1099 additions and 682 deletions

View file

@ -0,0 +1,25 @@
name: Build Gradle project
on:
push:
jobs:
build-gradle-project:
runs-on: ubuntu-latest
steps:
- name: apt update
run: apt update
- name: apt upgrade
run: apt upgrade -y
- name: install prerequisits
run: apt install openjdk-17-jdk ca-certificates-java ssl-cert openssl ca-certificates -y
- name: Checkout project sources
uses: actions/checkout@v3
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Run build with Gradle Wrapper
run: ./gradlew shadowJar
- uses: actions/upload-artifact@v3
with:
name: lilJudd.jar
path: build/libs/

View file

@ -1,15 +0,0 @@
on: [ push ]
jobs:
build_and_publish:
runs-on: gradle
steps:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Clean Caches
run: |
rm -f .gradle/caches/modules-2/modules-2.lock
rm -fr .gradle/caches/*/plugin-resolution/
- name: Run shadowJar
run: ./gradlew shadowJar
- name: Run publish
run: ./gradlew publish

View file

@ -2,11 +2,9 @@
"Oh boy, here we go again" ~ me
A Discord Bot for Splatoon Teams
A Discord Bot for Splatoon Teams.
[![Latest Release](https://gitlab.com/moonleay/liljudd/-/badges/release.svg)](https://gitlab.com/moonleay/liljudd/-/releases)
[![pipeline status](https://gitlab.com/moonleay/liljudd/badges/master/pipeline.svg)](https://gitlab.com/moonleay/liljudd/-/commits/master)
[![License](https://img.shields.io/badge/license-GPL--3.0-brightgreen)](https://gitlab.com/moonleay/liljudd/-/blob/master/LICENSE)
More information can be found on the [Homepage](https://moonleay.net/projects/liljudd/).
## Contributors
@ -21,9 +19,13 @@ A Discord Bot for Splatoon Teams
- Commands
- version -- Show the versions of the bot and the most important dependencies
- feature -- Manage bot features
- match -- Create a new match
- updateroles -- Update the roles of all users
- sendplanner -- Send the planner message
- Features
- Time Planner -- Make the bot send messages and reactions into a selected channel in order to make planning easier
- Availability Manager -- Make the bot assign users roles every day, so it is possible to notify available people
- Match Planner -- Make a match, for which players can sign up and the bot will assign teams and roles to them
## (Maybe) upcoming features
@ -33,36 +35,30 @@ A Discord Bot for Splatoon Teams
- Rndm map command
- Maybe a DSB / DSL API
## TODO
- Rewrite the Database connection system (from transactions all over the place to a single package with transactions)
## How to self-host (using the Docker container)
1. Pull the container
1. Pull the container from [Docker Hub](https://hub.docker.com/repository/docker/limiteddev/liljudd/general)
2. Map /data/ to a folder on disk
3. Run the Bot once
4. Follow step 4 - 7 of "How to self-host (using the JAR)"
4. follow step 4 and 5 from the JAR section
5. Run the Bot again
6. Profit.
## How to self-host (using the JAR)
1. Download the latest release from the Package Registry ("Packages and registries" > "Package Registry")
1. It should be called something like this: "lilJudd-X.X.X-xxxxxxxx-prod.jar" (replace "X.X.X" with the latest
version and xxxxxxxx" with the commit its based on.)
2. If you want to run an early version, which may be (very) unsable, you can run a development version. Just use an
entry ending in "-dev.jar"
1. Download the latest release from the Releases page.
2. Place it anywhere you want.
3. Run the following command:
> java -jar lilJudd-X.X.X-xxxxxxxx-prod.jar
> java -jar lilJudd.jar
4. The bot should start and create a config file named "credentials.nils" in a folder called "data"
5. Open it and put in your credentials.
1. token: your Discord bot token
2. dbDomain: the domain and port of your postgresql database (e.g.: 192.168.178.1:5432)
3. dbName: the name of your database
3. dbName: the name of the database
4. dbUser: the username of the database
5. dbPassword: the password to your user
5. dbPassword: the password to the db user
6. Rerun the command
> java -jar lilJudd-X.X.X-xxxxxxxx-prod.jar
> java -jar lilJudd.jar
7. The bot should now be up and running.
## How to set up workspace

View file

@ -21,9 +21,9 @@ import org.jetbrains.gradle.ext.TaskTriggersConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.20"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.6"
kotlin("jvm") version "1.9.10"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
`maven-publish`
}
@ -32,14 +32,14 @@ val ownerID = 372703841151614976L
group = "net.moonleay.liljudd"
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
?: "2.4.2"
?: "2.5.6"
val kordver = "1.5.6"
val coroutinesver = "1.1.0"
val ktor_version = "2.3.0"
val exposedver = "0.40.1"
val postgresver = "42.3.8"
val krontabver = "2.1.2"
val kordver = "1.5.9-SNAPSHOT"
val coroutinesver = "1.7.3"
val ktor_version = "2.3.4"
val exposedver = "0.43.0"
val postgresver = "42.6.0"
val krontabver = "2.2.0"
val mavenArtifact = "lilJudd"
project.base.archivesName.set(mavenArtifact)
@ -72,6 +72,14 @@ repositories {
}
}
}
maven {
name = "sonatype"
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
maven {
name = "sonatype 2"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
val shadow by configurations.getting
@ -95,14 +103,14 @@ dependencies {
//Korntab
shadow("dev.inmo:krontab:$krontabver")
"shadow"("io.ktor:ktor-client-core-jvm:2.3.1")
"shadow"("io.ktor:ktor-client-cio-jvm:2.3.1")
"shadow"("io.ktor:ktor-client-core-jvm:2.3.4")
"shadow"("io.ktor:ktor-client-cio-jvm:2.3.4")
}
val targetJavaVersion = 17
val templateSrc = project.rootDir.resolve("src/main/templates")
val templateDest = project.buildDir.resolve("generated/templates")
val templateDest = project.projectDir.resolve("build/generated/templates")
val templateProps = mapOf(
"version" to project.version as String,
"ownerID" to ownerID,

Binary file not shown.

View file

@ -18,6 +18,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -19,7 +19,6 @@
package net.moonleay.lilJudd
import com.kotlindiscord.kord.extensions.ExtensibleBot
import dev.kord.common.Color
import dev.kord.common.entity.PresenceStatus
import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.event.gateway.ReadyEvent
@ -35,13 +34,11 @@ import net.moonleay.botendo.build.BuildConstants
import net.moonleay.lilJudd.buttons.component.EditButtonManager
import net.moonleay.lilJudd.data.CredentialManager
import net.moonleay.lilJudd.data.DB
import net.moonleay.lilJudd.extensions.FeatureManageExtension
import net.moonleay.lilJudd.extensions.MatchExtension
import net.moonleay.lilJudd.extensions.SendPlannerExtension
import net.moonleay.lilJudd.extensions.VersionExtension
import net.moonleay.lilJudd.extensions.*
import net.moonleay.lilJudd.features.AvailabilityManager
import net.moonleay.lilJudd.features.MatchManager
import net.moonleay.lilJudd.features.TimeManager
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
import kotlin.system.exitProcess
@ -79,6 +76,9 @@ object Bot {
CredentialManager.dbPassword
)
// Make sure the database is up-to-date
DB.register()
// Register all the jobs
jobs.addAll(
listOf(
@ -103,8 +103,7 @@ object Bot {
add(::FeatureManageExtension)
add(::SendPlannerExtension)
add(::MatchExtension)
//add(::UpdateRolesExtension) // This command is only for debugging purposes
//add(::TestExtension) // See comment in TestExtension.kt
add(::UpdateRolesExtension)
}
this.presence {
@ -146,9 +145,10 @@ object Bot {
response.respond {
this.embeds = mutableListOf(
MessageUtil.getEmbed(
Color(0xE0311A),
"Error",
"Could not find button with id \"${inter.componentId}\".\nPlease report this.",
EmbedColor.ERROR,
"404: Not Found",
"Could not find button with id \"${inter.componentId}\"." +
"\nPlease report this.",
u.asUser().username + "#" + u.asUser().discriminator
)
)

View file

@ -18,8 +18,9 @@
package net.moonleay.lilJudd.buttons.component
import net.moonleay.lilJudd.buttons.matchplanner.AcceptEditButton
import net.moonleay.lilJudd.buttons.matchplanner.CancelEditButton
import net.moonleay.lilJudd.buttons.matchplanner.SignMeUpEditButton
import net.moonleay.lilJudd.buttons.matchplanner.DeclineEditButton
import net.moonleay.lilJudd.buttons.timeplanner.IsAvailableEditButton
import net.moonleay.lilJudd.buttons.timeplanner.MaybeAvailableEditButton
import net.moonleay.lilJudd.buttons.timeplanner.NotAvailableEditButton
@ -29,7 +30,8 @@ object EditButtonManager {
IsAvailableEditButton(),
MaybeAvailableEditButton(),
NotAvailableEditButton(),
SignMeUpEditButton(),
CancelEditButton()
AcceptEditButton(),
CancelEditButton(),
DeclineEditButton(),
)
}

View file

@ -26,7 +26,7 @@ import dev.kord.core.entity.interaction.ButtonInteraction
interface IEditButton {
val id: String
open suspend fun onInteraction(
suspend fun onInteraction(
interaction: ButtonInteraction,
response: PublicMessageInteractionResponseBehavior,
guild: Guild,

View file

@ -0,0 +1,102 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.buttons.matchplanner
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.edit
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
import dev.kord.core.entity.Guild
import dev.kord.core.entity.User
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
class AcceptEditButton() : IEditButton {
override val id: String = "public.edit.btn.matchmanagement.accept"
override suspend fun onInteraction(
interaction: ButtonInteraction,
response: PublicMessageInteractionResponseBehavior,
guild: Guild,
user: User
) {
val m = interaction.message
val eb = MessageUtil.getAClonedEmbed(m.embeds[0])
var shouldEditButton = false
val mpdd = MatchPlanningDataRepository.getFromMessageInChannelInServer(
m.id.value.toLong(),
interaction.channelId.value.toLong(),
guild.id.value.toLong()
)
if (mpdd == null) {
Logger.out("mpdd is null")
return
}
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID))
if (role == null) {
Logger.out("role is null")
return
}
val member = interaction.user.asMember(guild.id) ?: return
// do the checks and update
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) {
Logger.out("Removing role from ${member.username}")
member.removeRole(role.id)
}
// remove the user from the 1st list in the embed
Logger.out("Removing ${user.username} from the 1st list in the embed")
eb.fields = EmbedUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", eb, 1).fields
shouldEditButton = true
}
if (m.embeds[0].fields[1].value.contains(user.id.value.toString())) {
Logger.out("Removing ${user.username} from the 2nd list in the embed")
eb.fields = EmbedUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", eb, 2).fields
shouldEditButton = true
}
if (!m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (!member.roleIds.contains(Snowflake(mpdd.roleID))) {
Logger.out("Adding role to ${member.username}")
member.addRole(role.id)
}
//Add the user to the list in the embed
Logger.out("Adding ${user.username} to the 1st list in the embed")
eb.fields = EmbedUtil.addXToValuesAtTable(user.id.value.toString(), eb, 1).fields
shouldEditButton = true
}
if (shouldEditButton) {
// update the message
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
this.embed {
this.color = eb.color
this.title = eb.title
this.description = eb.description
this.fields = eb.fields
this.footer = eb.footer
}
}
}
}
}

View file

@ -28,12 +28,9 @@ import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.util.EmbedUtil
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import net.moonleay.lilJudd.util.Logger
class CancelEditButton : IEditButton {
override val id: String = "public.edit.btn.matchmanagement.cancel"
@ -46,35 +43,22 @@ class CancelEditButton : IEditButton {
) {
val m = interaction.message
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
lateinit var mpdd: MatchPlanningDataData
var found = false
transaction {
for (pnr in MatchPlanningData.select {
MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
MatchPlanningData.serverid eq (guild.id.value.toString())) and (
MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
}) {
mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype],
pnr[MatchPlanningData.registererid],
pnr[MatchPlanningData.roleid],
pnr[MatchPlanningData.opponentName],
pnr[MatchPlanningData.messageid],
pnr[MatchPlanningData.timestamp],
pnr[MatchPlanningData.jobstr]
)
found = true
}
}
if (!found || mpdd == null) {
val mpdd = MatchPlanningDataRepository.getFromMessageInChannelInServer(
m.id.value.toLong(),
interaction.channelId.value.toLong(),
guild.id.value.toLong()
)
if (mpdd == null) {
Logger.out("mpdd is null")
return
}
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID))
if (role == null) {
Logger.out("role is null")
return
}
val role = guild.getRoleOrNull(Snowflake(mpdd.roleid)) ?: return
val member = interaction.user.asMember(guild.id)
if (member.roleIds.contains(Snowflake(mpdd.roleid))) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) {
member.removeRole(role.id)
}
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {

View file

@ -0,0 +1,102 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.buttons.matchplanner
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.edit
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
import dev.kord.core.entity.Guild
import dev.kord.core.entity.User
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
class DeclineEditButton : IEditButton {
override val id: String = "public.edit.btn.matchmanagement.decline"
override suspend fun onInteraction(
interaction: ButtonInteraction,
response: PublicMessageInteractionResponseBehavior,
guild: Guild,
user: User
) {
val m = interaction.message
val eb = MessageUtil.getAClonedEmbed(m.embeds[0])
var shouldEditButton = false
val mpdd = MatchPlanningDataRepository.getFromMessageInChannelInServer(
m.id.value.toLong(),
interaction.channelId.value.toLong(),
guild.id.value.toLong()
)
if (mpdd == null) {
Logger.out("mpdd is null")
return
}
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID))
if (role == null) {
Logger.out("role is null")
return
}
val member = interaction.user.asMember(guild.id) ?: return
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) {
Logger.out("Removing role from ${member.username}")
member.removeRole(role.id)
}
// remove the user from the 1st list in the embed
Logger.out("Removing ${user.username} from the 1st list in the embed")
eb.fields = EmbedUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", eb, 1).fields
shouldEditButton = true
}
if (!m.embeds[0].fields[1].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) {
Logger.out("Removing role from ${member.username}")
member.removeRole(role.id)
}
// Add the user to the list in the embed
Logger.out("Adding ${user.username} to the 2nd list in the embed")
eb.fields = EmbedUtil.addXToValuesAtTable(user.id.value.toString(), eb, 2).fields
shouldEditButton = true
}
if (m.embeds[0].fields[1].value.contains(user.id.value.toString())) {
// Remove the user from all tables
Logger.out("Removing ${user.username} from the 2nd list in the embed")
eb.fields = EmbedUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", eb, 2).fields
shouldEditButton = true
}
if (shouldEditButton) {
// update the message
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
this.embed {
this.color = eb.color
this.title = eb.title
this.description = eb.description
this.fields = eb.fields
this.footer = eb.footer
}
}
}
}
}

View file

@ -1,94 +0,0 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.buttons.matchplanner
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.edit
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
import dev.kord.core.entity.Guild
import dev.kord.core.entity.User
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.util.EmbedUtil
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
class SignMeUpEditButton() : IEditButton {
override val id: String = "public.edit.btn.matchmanagement.accept"
override suspend fun onInteraction(
interaction: ButtonInteraction,
response: PublicMessageInteractionResponseBehavior,
guild: Guild,
user: User
) {
val m = interaction.message
if (!m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
lateinit var mpdd: MatchPlanningDataData
var found = false
transaction {
for (pnr in MatchPlanningData.select {
MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
MatchPlanningData.serverid eq (guild.id.value.toString())) and (
MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
}) {
mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype],
pnr[MatchPlanningData.registererid],
pnr[MatchPlanningData.roleid],
pnr[MatchPlanningData.opponentName],
pnr[MatchPlanningData.messageid],
pnr[MatchPlanningData.timestamp],
pnr[MatchPlanningData.jobstr]
)
found = true
}
}
if (!found || mpdd == null) {
return
}
val role = guild.getRoleOrNull(Snowflake(mpdd.roleid)) ?: return
val member = interaction.user.asMember(guild.id)
if (!member.roleIds.contains(Snowflake(mpdd.roleid))) {
member.addRole(role.id)
}
//Add the user to the list in the embed
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
this.embed {
val temp = EmbedUtil.addXToValuesAtTable(user.id.value.toString(), m.embeds[0], 1)
this.color = temp.color
this.title = temp.title
this.description = temp.description
this.fields = temp.fields
this.footer = temp.footer
}
}
}
}
}

View file

@ -27,6 +27,7 @@ import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.features.AvailabilityManager
import net.moonleay.lilJudd.util.EmbedUtil
class IsAvailableEditButton : IEditButton {
@ -62,5 +63,6 @@ class IsAvailableEditButton : IEditButton {
}
}
}
AvailabilityManager.updateInChannel(interaction.channelId)
}
}

View file

@ -27,6 +27,7 @@ import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.features.AvailabilityManager
import net.moonleay.lilJudd.util.EmbedUtil
class MaybeAvailableEditButton : IEditButton {
@ -62,5 +63,6 @@ class MaybeAvailableEditButton : IEditButton {
}
}
}
AvailabilityManager.updateInChannel(interaction.channelId)
}
}

View file

@ -27,6 +27,7 @@ import dev.kord.core.entity.interaction.ButtonInteraction
import dev.kord.rest.builder.message.modify.embed
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.buttons.component.IEditButton
import net.moonleay.lilJudd.features.AvailabilityManager
import net.moonleay.lilJudd.util.EmbedUtil
class NotAvailableEditButton : IEditButton {
@ -62,5 +63,6 @@ class NotAvailableEditButton : IEditButton {
}
}
}
AvailabilityManager.updateInChannel(interaction.channelId)
}
}

View file

@ -19,10 +19,18 @@
package net.moonleay.lilJudd.data
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
object DB {
//Connect to the provided DB; trows errors, if the DB is not avalible.
private var connected = false
//Connect to the provided DB; trows errors, if the DB is not available.
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
Database.connect(
"jdbc:postgresql://$dbDomain/$dbName",
@ -30,5 +38,18 @@ object DB {
user = dbUser,
password = dbPasswd
)
connected = true
}
fun register() {
if (!connected)
return
// Register tables here
transaction {
SchemaUtils.create(TimePlanningChannels)
SchemaUtils.create(TimePlanningMessages)
SchemaUtils.create(MatchPlanningData)
SchemaUtils.create(PlanningNotifierRoles)
}
}
}

View file

@ -20,13 +20,13 @@ package net.moonleay.lilJudd.data.entry
data class MatchPlanningDataData(
val id: Int,
val serverid: String,
val channelid: String,
val matchtype: String,
val registererid: String,
val roleid: String,
val opponentname: String,
val messageid: String,
val timestamp: String,
val jobstr: String
val serverID: Long,
val channelID: Long,
val matchType: String,
val registererID: Long,
val roleID: Long,
val opponentName: String,
val messageID: Long,
val timestamp: Long,
val jobString: String
)

View file

@ -19,8 +19,9 @@
package net.moonleay.lilJudd.data.entry
data class PlanningNotifierRolesData(
val serverID: String, // The id of the server
val channelId: String, // The id of the channel
val hastimeroleid: String, // The id of the role that has time today
val wantstobenotifid: String // The id of the role that wants to be notified
val id: Int, // The id of the entry
val serverID: Long, // The id of the server
val channelID: Long, // The id of the channel
val hasTimeRoleID: Long, // The id of the role that has time today
val wantsToBeNotifiedID: Long // The id of the role that wants to be notified
)

View file

@ -0,0 +1,25 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.entry
data class TimePlanningChannelsData(
val id: Int,
val serverID: Long,
val channelID: Long,
)

View file

@ -19,8 +19,9 @@
package net.moonleay.lilJudd.data.entry
data class TimePlanningMessagesData(
val serverid: String, // The discord server id
val channelid: String, // The discord channel id
val weekstamp: String, // The timestamp of the monday of the week at 4am UTC
val messageids: String // IDs are in the following format: "{weekdayNr}:{id};{weekdayNr}:{id};[etc.]"
val id: Int, // The id of the entry
val serverID: Long, // The discord server id
val channelID: Long, // The discord channel id
val weekstamp: Long, // The timestamp of the monday of the week at 4am UTC
val messageIDs: String // IDs are in the following format: "{weekdayNr}:{id};{weekdayNr}:{id};[etc.]"
)

View file

@ -0,0 +1,112 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.repository
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
object MatchPlanningDataRepository {
fun getAll(): List<MatchPlanningDataData> {
val dataList = mutableListOf<MatchPlanningDataData>()
transaction {
MatchPlanningData.selectAll().forEach {
dataList.add(
MatchPlanningDataData(
it[MatchPlanningData.id],
it[MatchPlanningData.serverid],
it[MatchPlanningData.channelid],
it[MatchPlanningData.matchtype],
it[MatchPlanningData.registererid],
it[MatchPlanningData.roleid],
it[MatchPlanningData.opponentName],
it[MatchPlanningData.messageid],
it[MatchPlanningData.timestamp],
it[MatchPlanningData.jobstr]
)
)
}
}
return dataList
}
fun get(id: Int): MatchPlanningDataData? =
transaction {
MatchPlanningData.select { MatchPlanningData.id eq id }.firstOrNull()?.let {
MatchPlanningDataData(
it[MatchPlanningData.id],
it[MatchPlanningData.serverid],
it[MatchPlanningData.channelid],
it[MatchPlanningData.matchtype],
it[MatchPlanningData.registererid],
it[MatchPlanningData.roleid],
it[MatchPlanningData.opponentName],
it[MatchPlanningData.messageid],
it[MatchPlanningData.timestamp],
it[MatchPlanningData.jobstr]
)
}
}
fun getFromMessageInChannelInServer(messageID: Long, channelID: Long, serverID: Long): MatchPlanningDataData? =
transaction {
MatchPlanningData.select {
MatchPlanningData.messageid eq (messageID) and (
MatchPlanningData.serverid eq (serverID)) and (
MatchPlanningData.channelid eq (channelID))
}.firstOrNull()?.let {
MatchPlanningDataData(
it[MatchPlanningData.id],
it[MatchPlanningData.serverid],
it[MatchPlanningData.channelid],
it[MatchPlanningData.matchtype],
it[MatchPlanningData.registererid],
it[MatchPlanningData.roleid],
it[MatchPlanningData.opponentName],
it[MatchPlanningData.messageid],
it[MatchPlanningData.timestamp],
it[MatchPlanningData.jobstr]
)
}
}
fun delete(id: Int) {
transaction {
MatchPlanningData.deleteWhere { MatchPlanningData.id eq id }
}
}
fun write(data: MatchPlanningDataData): Int =
transaction {
MatchPlanningData.insert {
it[MatchPlanningData.serverid] = data.serverID
it[MatchPlanningData.channelid] = data.channelID
it[MatchPlanningData.matchtype] = data.matchType
it[MatchPlanningData.registererid] = data.registererID
it[MatchPlanningData.roleid] = data.roleID
it[MatchPlanningData.opponentName] = data.opponentName
it[MatchPlanningData.messageid] = data.messageID
it[MatchPlanningData.timestamp] = data.timestamp
it[MatchPlanningData.jobstr] = data.jobString
} get MatchPlanningData.id
}
}

View file

@ -0,0 +1,104 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.repository
import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
object PlanningNotifierRolesRepository {
fun getAll(): List<PlanningNotifierRolesData> {
val dataList = mutableListOf<PlanningNotifierRolesData>()
transaction {
for (pnr in PlanningNotifierRoles.selectAll()) {
dataList.add(
PlanningNotifierRolesData(
pnr[PlanningNotifierRoles.id],
pnr[PlanningNotifierRoles.serverid],
pnr[PlanningNotifierRoles.channelid],
pnr[PlanningNotifierRoles.hastimeroleid],
pnr[PlanningNotifierRoles.wantstobenotifiedid]
)
)
}
}
return dataList
}
fun getForChannel(channelID: Long): PlanningNotifierRolesData? =
transaction {
PlanningNotifierRoles.select {
PlanningNotifierRoles.channelid eq channelID
}.firstOrNull()?.let {
PlanningNotifierRolesData(
it[PlanningNotifierRoles.id],
it[PlanningNotifierRoles.serverid],
it[PlanningNotifierRoles.channelid],
it[PlanningNotifierRoles.hastimeroleid],
it[PlanningNotifierRoles.wantstobenotifiedid]
)
}
}
fun getForChannelInServer(channelID: Long, serverID: Long): PlanningNotifierRolesData? =
transaction {
PlanningNotifierRoles.select {
PlanningNotifierRoles.channelid eq channelID and (PlanningNotifierRoles.serverid eq serverID)
}.firstOrNull()?.let {
PlanningNotifierRolesData(
it[PlanningNotifierRoles.id],
it[PlanningNotifierRoles.serverid],
it[PlanningNotifierRoles.channelid],
it[PlanningNotifierRoles.hastimeroleid],
it[PlanningNotifierRoles.wantstobenotifiedid]
)
}
}
fun existsInChannel(channelID: Long): Boolean =
transaction {
PlanningNotifierRoles.select { PlanningNotifierRoles.channelid eq channelID }.count() > 0
}
fun existsInChannelFromSever(channelID: Long, serverID: Long): Boolean =
transaction {
PlanningNotifierRoles.select { PlanningNotifierRoles.channelid eq channelID and (PlanningNotifierRoles.serverid eq serverID) }
.count() > 0
}
fun write(data: PlanningNotifierRolesData) {
transaction {
PlanningNotifierRoles.insert {
it[PlanningNotifierRoles.serverid] = data.serverID
it[PlanningNotifierRoles.channelid] = data.channelID
it[PlanningNotifierRoles.hastimeroleid] = data.hasTimeRoleID
it[PlanningNotifierRoles.wantstobenotifiedid] = data.wantsToBeNotifiedID
} get PlanningNotifierRoles.id
}
}
fun delete(id: Int) {
transaction {
PlanningNotifierRoles.deleteWhere { PlanningNotifierRoles.id eq id }
}
}
}

View file

@ -0,0 +1,69 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.repository
import net.moonleay.lilJudd.data.entry.TimePlanningChannelsData
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
object TimePlanningChannelsRepository {
fun getAll(): List<TimePlanningChannelsData> {
val dataList = mutableListOf<TimePlanningChannelsData>()
transaction {
for (tp in TimePlanningChannels.selectAll())
dataList.add(
TimePlanningChannelsData(
id = tp[TimePlanningChannels.id],
serverID = tp[TimePlanningChannels.serverid],
channelID = tp[TimePlanningChannels.channelid],
)
)
}
return dataList
}
fun exists(channelID: Long, serverID: Long): Boolean =
transaction {
TimePlanningChannels.select { TimePlanningChannels.channelid eq channelID and (TimePlanningChannels.serverid eq serverID) }
.firstOrNull() != null
}
fun delete(id: Int) {
transaction {
TimePlanningChannels.deleteWhere { TimePlanningChannels.id eq id }
}
}
fun deleteFromChannelInServer(channelID: Long, serverID: Long) {
transaction {
TimePlanningChannels.deleteWhere { TimePlanningChannels.channelid eq channelID and (TimePlanningChannels.serverid eq serverID) }
}
}
fun write(data: TimePlanningChannelsData): Int =
transaction {
TimePlanningChannels.insert {
it[TimePlanningChannels.serverid] = data.serverID
it[TimePlanningChannels.channelid] = data.channelID
} get TimePlanningChannels.id
}
}

View file

@ -0,0 +1,76 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.repository
import net.moonleay.lilJudd.data.entry.TimePlanningMessagesData
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
object TimePlanningMessagesRepository {
fun write(data: TimePlanningMessagesData): Int =
transaction {
TimePlanningMessages.insert {
it[serverid] = data.serverID
it[channelid] = data.channelID
it[weekstamp] = data.weekstamp
it[messageids] = data.messageIDs
} get TimePlanningMessages.id
}
fun getWeek(stamp: Long): List<TimePlanningMessagesData> {
val dataList = mutableListOf<TimePlanningMessagesData>()
transaction {
for (pnr in TimePlanningMessages.select {
TimePlanningMessages.weekstamp eq (stamp)
}) {
dataList.add(
TimePlanningMessagesData(
pnr[TimePlanningMessages.id],
pnr[TimePlanningMessages.serverid],
pnr[TimePlanningMessages.channelid],
pnr[TimePlanningMessages.weekstamp],
pnr[TimePlanningMessages.messageids]
)
)
}
}
return dataList
}
fun getWeekInChannel(stamp: Long, channelID: Long): TimePlanningMessagesData? =
transaction {
TimePlanningMessages.select {
TimePlanningMessages.weekstamp eq (stamp) and (TimePlanningMessages.channelid eq channelID)
}.firstOrNull()?.let {
TimePlanningMessagesData(
it[TimePlanningMessages.id],
it[TimePlanningMessages.serverid],
it[TimePlanningMessages.channelid],
it[TimePlanningMessages.weekstamp],
it[TimePlanningMessages.messageids]
)
}
}
}

View file

@ -18,16 +18,17 @@
package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Table
object MatchPlanningData : IntIdTable() {
var serverid = varchar("serverid", 50)
var channelid = varchar("channelid", 50)
object MatchPlanningData : Table(name = "new_matchplanning_data") {
var id = integer("id").autoIncrement()
var serverid = long("serverid")
var channelid = long("channelid")
var matchtype = varchar("matchtype", 50)
var registererid = varchar("registererid", 50)
var roleid = varchar("roleid", 50)
var registererid = long("registererid")
var roleid = long("roleid")
var opponentName = varchar("opponentname", 100)
var messageid = varchar("messageid", 50)
var timestamp = varchar("timestamp", 50)
var messageid = long("messageid")
var timestamp = long("timestamp")
var jobstr = varchar("jobstr", 50)
}

View file

@ -18,11 +18,12 @@
package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Table
object PlanningNotifierRoles : IntIdTable() {
var serverid = varchar("serverid", 50)
var channelid = varchar("channelid", 50)
var hastimeroleid = varchar("hastimeroleid", 50)
var wantstobenotifiedid = varchar("wantstobenotifiedid", 50)
object PlanningNotifierRoles : Table(name = "new_planningnotifier_roles") {
var id = integer("id").autoIncrement()
var serverid = long("serverid")
var channelid = long("channelid")
var hastimeroleid = long("hastimeroleid")
var wantstobenotifiedid = long("wantstobenotifiedid")
}

View file

@ -18,9 +18,11 @@
package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Table
object TimePlanningChannels : IntIdTable() {
var serverid = varchar("serverid", 50)
val channelid = varchar("channelid", 50)
object TimePlanningChannels : Table(name = "new_timeplanning_channels") {
var id = integer("id").autoIncrement()
var serverid = long("serverid")
val channelid = long("channelid")
}

View file

@ -18,11 +18,12 @@
package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Table
object TimePlanningMessages : IntIdTable() {
var serverid = varchar("serverid", 50)
var channelid = varchar("channelid", 50)
var weekstamp = varchar("weekstamp", 50)
object TimePlanningMessages : Table(name = "new_timeplanning_messages") {
var id = integer("id").autoIncrement()
var serverid = long("serverid")
var channelid = long("channelid")
var weekstamp = long("weekstamp")
var messageids = varchar("messageids", 200)
}

View file

@ -25,11 +25,11 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.hasPermission
import dev.kord.common.Color
import dev.kord.common.entity.Permission
import net.moonleay.lilJudd.extensions.component.EnableOrDisable
import net.moonleay.lilJudd.features.component.FeatureEnum
import net.moonleay.lilJudd.features.component.FeatureManager
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
@ -51,7 +51,7 @@ class FeatureManageExtension : Extension() {
this.respond {
embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"403: Forbidden",
"You cannot edit features, as you don't have the Administrator permission.",
u.asUser().username + "#" + u.asUser().discriminator
@ -60,8 +60,8 @@ class FeatureManageExtension : Extension() {
}
return@action
}
val gID = this.guild!!.id.toString()
val cID = this.arguments.channel.id.toString()
val gID = this.guild!!.id.value.toLong()
val cID = this.arguments.channel.id.value.toLong()
val channel = this.arguments.channel
val args = this.arguments
Logger.out("${args.feature.readableName} ${args.setStatus.readableName} ${channel.data.name.value}")
@ -70,7 +70,7 @@ class FeatureManageExtension : Extension() {
this.respond {
this.embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"404: Not Found",
"The feature you are trying to edit does not exist.",
u.asUser().username + "#" + u.asUser().discriminator

View file

@ -25,20 +25,18 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.string
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.Color
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.behavior.createRole
import dev.kord.rest.builder.message.create.actionRow
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.extensions.component.MatchTypes
import net.moonleay.lilJudd.jobs.MatchJob
import net.moonleay.lilJudd.jobs.component.JobManager
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.MessageUtil
import net.moonleay.lilJudd.util.TimeUtil
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction
class MatchExtension : Extension() {
@ -54,19 +52,20 @@ class MatchExtension : Extension() {
this.action {
val args = this.arguments
val m = this.member!!
val gID = this.guild!!.id.value.toString()
val cID = this.channel.id.value.toString()
val gID = this.guild!!.id.value
val cID = this.channel.id.value
val opponent = args.opponent ?: "?"
val msg = this.respond {
this.embeds.add(
MessageUtil.getEmbedWithTable(
Color(0X4C4645),
EmbedColor.INFO,
args.matchType.readableName,
"***Vs. $opponent***\n" +
"At ${args.timeStamp}\n" +
"Registered by ${m.mention}",
mapOf(
"Signed up" to listOf(),
"Unavailable" to listOf(),
)
)
)
@ -89,7 +88,7 @@ class MatchExtension : Extension() {
this.channel.createMessage {
this.embeds.add(
MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"500: Internal Error",
"Could not find created role.\n" +
"It seems, that said role could not be created.",
@ -99,28 +98,28 @@ class MatchExtension : Extension() {
}
return@action
}
lateinit var tableID: EntityID<Int>
transaction {
tableID = MatchPlanningData.insert {
it[MatchPlanningData.serverid] = gID
it[MatchPlanningData.channelid] = cID
it[MatchPlanningData.messageid] = msg.id.value.toString()
it[MatchPlanningData.matchtype] = args.matchType.readableName
it[MatchPlanningData.roleid] = role.id.value.toString()
it[MatchPlanningData.registererid] = m.id.value.toString()
it[MatchPlanningData.opponentName] = opponent
it[MatchPlanningData.timestamp] = (zdt.toEpochSecond() * 1000).toString()
it[MatchPlanningData.jobstr] = jobString
} get MatchPlanningData.id
}
if (tableID == null) {
val tID = MatchPlanningDataRepository.write(
MatchPlanningDataData(
0,
gID.toLong(),
cID.toLong(),
args.matchType.readableName,
m.id.value.toLong(),
role.id.value.toLong(),
opponent,
msg.id.value.toLong(),
(zdt.toEpochSecond() * 1000),
jobString
)
)
if (tID == null || tID <= 0) {
return@action // Not saved to db
}
JobManager.addJob(
MatchJob(
jobString,
tableID.value,
"${args.matchType.readableName}_Vs_${opponent}_[${tableID.value}]-${gID}_${cID}"
tID,
"${args.matchType.readableName}_Vs_${opponent}_[${tID}]-${gID}_${cID}",
)
)
}

View file

@ -22,18 +22,13 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.hasPermission
import dev.kord.common.Color
import dev.kord.common.entity.Permission
import dev.kord.core.behavior.channel.createMessage
import dev.kord.rest.builder.message.create.actionRow
import kotlinx.coroutines.delay
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
import net.moonleay.lilJudd.util.TimeUtil
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction
import net.moonleay.lilJudd.data.entry.TimePlanningMessagesData
import net.moonleay.lilJudd.data.repository.TimePlanningMessagesRepository
import net.moonleay.lilJudd.util.*
import java.time.ZoneId
import java.time.ZonedDateTime
@ -47,13 +42,13 @@ class SendPlannerExtension : Extension() {
override suspend fun setup() {
publicSlashCommand() {
name = "sendplanner"
description = "Send the planner for the current and x next weeks"
description = "Send the planner for the current week"
this.action {
if (!this.member!!.asMember(this.guild!!.id)
.hasPermission(Permission.Administrator)
) {
val res = this.respond {
this.content = "no."
this.content = "You need to be an administrator to use this command."
}
res.delete()
return@action
@ -71,7 +66,7 @@ class SendPlannerExtension : Extension() {
c.createMessage {
this.embeds.add(
MessageUtil.getEmbed(
Color(0X4C4645),
EmbedColor.INFO,
"Time Planning Feature",
"Do you have time on the following Days?",
"Automated Message"
@ -83,7 +78,7 @@ class SendPlannerExtension : Extension() {
val msg = c.createMessage {
this.embeds.add(
MessageUtil.getEmbedWithTable(
Color(0X4C4645),
EmbedColor.INFO,
"",
"${then.dayOfWeek.name}, ${then.dayOfMonth}.${then.monthValue}.${then.year} /${it + 1}. weekday",
mapOf(
@ -105,14 +100,15 @@ class SendPlannerExtension : Extension() {
}
// Save the message ids
transaction {
TimePlanningMessages.insert {
it[serverid] = c.data.guildId.value.toString()
it[channelid] = c.id.value.toString()
it[weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
it[messageids] = msgStr
} get TimePlanningMessages.id
}
TimePlanningMessagesRepository.write(
TimePlanningMessagesData(
-1,
c.data.guildId.value?.value!!.toLong(),
c.id.value.toLong(),
(TimeUtil.getWeekStamp().toEpochSecond() * 1000),
msgStr
)
)
Logger.out("Finished with ${c.data.guildId.value}")
}
}

View file

@ -1,62 +0,0 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.extensions
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.Color
import dev.kord.rest.builder.message.create.actionRow
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.MessageUtil
/* This extension has no proper use.
It is used in testing to test stuff, without having to wait for certain events to trigger. */
class TestExtension : Extension() {
override val name = "test"
override val allowApplicationCommandInDMs: Boolean
get() = false
override suspend fun setup() {
publicSlashCommand {
name = "test"
description = "Test game"
this.action {
this.respond {
this.embeds.add(
MessageUtil.getEmbedWithTable(
Color(0X4C4645),
"",
"MONDAY, 22.05.2023",
mapOf(
"Is available" to listOf(),
"May be available" to listOf(),
"Is not available" to listOf()
)
)
)
this.actionRow {
this.components.addAll(EmbedUtil.getTimePlannerButtons().components)
}
}
}
}
}
}

View file

@ -23,16 +23,16 @@ import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.hasPermission
import dev.kord.common.entity.Permission
import dev.kord.gateway.PrivilegedIntent
import net.moonleay.lilJudd.features.AvailabilityManager
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
class UpdateRolesExtension : Extension() {
override val name = "updateroles"
override val allowApplicationCommandInDMs: Boolean
get() = false
@OptIn(PrivilegedIntent::class)
override suspend fun setup() {
publicSlashCommand() {
name = "updateroles"
@ -41,21 +41,34 @@ class UpdateRolesExtension : Extension() {
if (!this.member!!.asMember(this.guild!!.id)
.hasPermission(Permission.Administrator)
) {
val res = this.respond {
this.content = "no."
this.respond {
this.embeds.add(
MessageUtil.getEmbed(
EmbedColor.ERROR,
"403: Forbidden",
"You need to be an administrator to use this command.",
user.asUser().username + "#" + user.asUser().discriminator
)
)
}
res.delete()
return@action
}
val res = this.respond {
this.content = "OK."
this.respond {
this.embeds.add(
MessageUtil.getEmbed(
EmbedColor.SUCCESS,
"200: Success",
"Updating roles.\n" +
"This may take a while, please be patient.",
user.asUser().username + "#" + user.asUser().discriminator
)
)
}
// -- below here is the code of the cronjob --
Logger.out("Starting to update roles...")
AvailabilityManager.runThread()
AvailabilityManager.updateInChannel(this.channel.id)
}
}
}

View file

@ -20,8 +20,8 @@ package net.moonleay.lilJudd.extensions
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import dev.kord.common.Color
import net.moonleay.botendo.build.BuildConstants
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.MessageUtil
class VersionExtension : Extension() {
@ -33,7 +33,7 @@ class VersionExtension : Extension() {
this.action {
MessageUtil.sendEmbedForPublicSlashCommand(
this,
Color(0x52E01A),
EmbedColor.INFO,
"Lil' Judd",
"Lil' Judd ***v." + BuildConstants.version + "***\n" +
"Kord-Extensions ***v." + BuildConstants.kordVersion + "***\n" +

View file

@ -18,9 +18,9 @@
package net.moonleay.lilJudd.features
import com.kotlindiscord.kord.extensions.utils.isNullOrBot
import dev.inmo.krontab.buildSchedule
import dev.inmo.krontab.doInfinity
import dev.kord.common.Color
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.createRole
@ -32,127 +32,126 @@ import dev.kord.rest.builder.message.EmbedBuilder
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData
import net.moonleay.lilJudd.data.entry.TimePlanningMessagesData
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import net.moonleay.lilJudd.data.repository.PlanningNotifierRolesRepository
import net.moonleay.lilJudd.data.repository.TimePlanningMessagesRepository
import net.moonleay.lilJudd.extensions.FeatureManageExtension
import net.moonleay.lilJudd.features.component.FeatureEnum
import net.moonleay.lilJudd.features.component.IFeature
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
import net.moonleay.lilJudd.util.TimeUtil
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import net.moonleay.lilJudd.util.*
import java.time.ZonedDateTime
object AvailabilityManager : IFeature {
// This runs during the cronjob.
@OptIn(PrivilegedIntent::class)
suspend fun runThread() {
Logger.out("Starting to update roles...")
// ChannelID, Data
val messageMap = mutableMapOf<Snowflake, TimePlanningMessagesData>()
// ChannelID, Data
val roleMap = mutableMapOf<String, PlanningNotifierRolesData>()
val messages = TimePlanningMessagesRepository.getWeek(TimeUtil.getWeekStamp().toEpochSecond() * 1000)
.associateBy { it.channelID }
val targetedRoles = PlanningNotifierRolesRepository.getAll().associateBy { it.channelID }
transaction {
for (pnr in TimePlanningMessages.select {
TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
}) {
messageMap[Snowflake(pnr[TimePlanningMessages.channelid])] =
TimePlanningMessagesData(
pnr[TimePlanningMessages.serverid],
pnr[TimePlanningMessages.channelid],
pnr[TimePlanningMessages.weekstamp],
pnr[TimePlanningMessages.messageids]
)
}
for (pnr in PlanningNotifierRoles.selectAll()) {
roleMap[pnr[PlanningNotifierRoles.channelid]] =
PlanningNotifierRolesData(
pnr[PlanningNotifierRoles.serverid],
pnr[PlanningNotifierRoles.channelid],
pnr[PlanningNotifierRoles.hastimeroleid],
pnr[PlanningNotifierRoles.wantstobenotifiedid]
)
}
}
val weekday = ZonedDateTime.now().dayOfWeek // The current week day
val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp
Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
for (snf in messageMap.keys) { // snf = Snowflake
val data = messageMap[snf]!! // this is the data of the table
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelid)) == null)
for (id in messages.keys) {
val snf = Snowflake(id) // snf = Snowflake
val data = messages[id]!! // this is the data of the table
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null)
continue // This channel does not exist anymore.
val c =
Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(data.channelid))!! // Get the channel as MessageChannel
if (roleMap.isEmpty()) {
if (targetedRoles.isEmpty()) {
Logger.out("No saved roles. Canceling.")
return
}
val roleData = roleMap[data.channelid] // Get the role data
val roleData = targetedRoles[data.channelID] // Get the role data
if (roleData == null) {
Logger.out("Role for this channel does not exist")
return
}
val g = Bot.bot.kordRef.getGuildOrThrow(Snowflake(data.serverid))
// Get all members with the role
val mce = g.requestMembers {
this.requestAllMembers()
}
mce.collect { memberchunkevent ->
memberchunkevent.members.forEach {
Logger.out("Checking member ${it.id.value}")
if (it.roleIds.contains(Snowflake(roleData.hastimeroleid)))
it.removeRole(Snowflake(roleData.hastimeroleid))
}
}
Logger.out("Got through all members")
// This stores the ids of the messages.
// The format is weekdaNR:ID
// The last entry (nr 8) is empty, so we can ignore it
val messageIdSplit = data.messageids.split(";").subList(0, 7)
for (mid in messageIdSplit) {
Logger.out("Checking id $mid")
if (!mid.startsWith((TimeUtil.getDayOfMonthInt(weekday) - 1).toString(), true))
continue // This is not the right message, check the next one
val idFiltered = mid.split(":")[1] // This is the target message id
val message = c.getMessageOrNull(Snowflake(idFiltered)) // Get the message from the channel
if (message == null) {
Logger.out("Could not find message.")
break // This message does not exist anymore. Nothing we can do about that.
}
if (message.data.embeds.isEmpty()) {
Logger.out("There are no embeds.")
break // There are no embeds or there are not enough embeds
}
val targets = EmbedUtil.getAllUsersInTheFirstXTables(2, message.embeds[0])
for (tid in targets) {
Logger.out("Checking id $tid")
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(data.serverid))!!
.getMemberOrNull(Snowflake(tid)) == null
)
continue // This member does not exist anymore.
val member = Bot.bot.kordRef.getGuildOrThrow(Snowflake(data.serverid))
.getMember(Snowflake(tid)) // Get the member
if (member.roleIds.contains(Snowflake(roleData.hastimeroleid)))
continue // This member already has the role
member.addRole(Snowflake(roleData.hastimeroleid)) // Add the role
Logger.out("Added role to ${member.username}")
}
Logger.out("Done with message. Moving on...")
// We found the right message. We don't need to check the others.
break
Logger.out("Role for channel ${data.channelID} does not exist")
continue // this took way to long to find out that this was the issue
}
this.updateInChannel(snf, data, roleData)
}
Logger.out("Done! Until tomorrow! <3 ")
}
suspend fun updateInChannel(snf: Snowflake) {
val messageData = TimePlanningMessagesRepository.getWeekInChannel(
TimeUtil.getWeekStamp().toEpochSecond() * 1000,
snf.value.toLong()
)
val roleData = PlanningNotifierRolesRepository.getForChannel(snf.value.toLong())
if (messageData == null) {
Logger.out("Could not find data for channel ${snf.value}")
return
}
if (roleData == null) {
Logger.out("Role for channel ${messageData.channelID} does not exist")
return // this took way to long to find out that this was the issue
}
updateInChannel(snf, messageData, roleData)
}
@OptIn(PrivilegedIntent::class)
suspend fun updateInChannel(snf: Snowflake, tpmd: TimePlanningMessagesData, pnrd: PlanningNotifierRolesData) {
if (Bot.bot.kordRef.getChannel(snf) == null)
return // This channel does not exist anymore.
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(snf)!! // Get the channel as MessageChannel
val weekday = ZonedDateTime.now().dayOfWeek // The current week day
val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp
Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
val g = Bot.bot.kordRef.getGuild(Snowflake(tpmd.serverID))
// Get all members with the role
val mce = g.requestMembers {
this.requestAllMembers()
}
mce.collect { memberchunkevent ->
memberchunkevent.members.forEach {
if (!it.isNullOrBot()) { // Check if the member is a bot
Logger.out("Checking member ${it.id.value} (${it.username})")
if (it.roleIds.contains(Snowflake(pnrd.hasTimeRoleID))) {
it.removeRole(Snowflake(pnrd.hasTimeRoleID))
Logger.out("Removed role from ${it.username}") // Removed the role
}
}
// I cant use continue here, because it does not work with .forEach
}
}
Logger.out("Got through all members")
// This stores the ids of the messages.
// The format is weekdaNR:ID
// The last entry (nr 8) is empty, so we can ignore it
val messageIdSplit = tpmd.messageIDs.split(";").subList(0, 7)
for (mid in messageIdSplit) {
Logger.out("Checking id $mid")
if (!mid.startsWith((TimeUtil.getDayOfMonthInt(weekday) - 1).toString(), true))
continue// This is not the right message, check the next one
val idFiltered = mid.split(":")[1] // This is the target message id
val message = c.getMessageOrNull(Snowflake(idFiltered)) // Get the message from the channel
if (message == null) {
Logger.out("Could not find message.")
return // This message does not exist anymore. Nothing we can do about that.
}
if (message.data.embeds.isEmpty()) {
Logger.out("There are no embeds.")
return // There are no embeds or there are not enough embeds
}
val targets = EmbedUtil.getAllUsersInTheFirstXTables(2, message.embeds[0])
for (tid in targets) {
Logger.out("Checking id $tid")
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(tpmd.serverID))!!
.getMemberOrNull(Snowflake(tid)) == null
)
continue// This member does not exist anymore.
val member = Bot.bot.kordRef.getGuild(Snowflake(tpmd.serverID))
.getMember(Snowflake(tid)) // Get the member
if (member.roleIds.contains(Snowflake(pnrd.hasTimeRoleID)))
continue // This member already has the role
member.addRole(Snowflake(pnrd.hasTimeRoleID)) // Add the role
Logger.out("Added role to ${member.username}")
}
Logger.out("Done with message. Moving on...")
// We found the right message. We don't need to check the others.
break
}
}
override val feat: FeatureEnum
get() = FeatureEnum.PLANNINGROLES
@ -167,44 +166,40 @@ object AvailabilityManager : IFeature {
override suspend fun enable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder {
var alreadyExists = false
var alreadyExists = PlanningNotifierRolesRepository.existsInChannel(cID)
// Check if the channel and guild already exist in the db
transaction {
alreadyExists = PlanningNotifierRoles.select {
(PlanningNotifierRoles.serverid eq gID) and (PlanningNotifierRoles.channelid eq cID)
}.count() > 0
}
if (!alreadyExists) {
// Create the roles in Discord
val hasTimeRole = Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID)).createRole {
val hasTimeRole = Bot.bot.kordRef.getGuild(Snowflake(gID)).createRole {
this.name = "available [${ch.data.name.value}]"
this.mentionable = true
}
val htr = hasTimeRole.id.toString()
val htr = hasTimeRole.id.value.toLong()
val wantsNotifsRole = Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID)).createRole {
val wantsNotifsRole = Bot.bot.kordRef.getGuild(Snowflake(gID)).createRole {
this.name = "notifications [${ch.data.name.value}]"
this.mentionable = true
}
val wnr = wantsNotifsRole.id.toString()
val wnr = wantsNotifsRole.id.value.toLong()
// Save the role ids to db
transaction {
PlanningNotifierRoles.insert {
it[PlanningNotifierRoles.serverid] = gID
it[PlanningNotifierRoles.channelid] = cID
it[PlanningNotifierRoles.hastimeroleid] = htr
it[PlanningNotifierRoles.wantstobenotifiedid] = wnr
} get PlanningNotifierRoles.id
}
PlanningNotifierRolesRepository.write(
PlanningNotifierRolesData(
id = -1,
serverID = gID,
channelID = cID,
hasTimeRoleID = htr,
wantsToBeNotifiedID = wnr
)
)
return MessageUtil.getEmbed(
Color(0x52E01A),
EmbedColor.SUCCESS,
"200: Success",
"The feature was enabled in channel ${args.channel.data.name.value} with roles ${hasTimeRole.mention} & ${wantsNotifsRole.mention}.",
u.asUser().username + "#" + u.asUser().discriminator
@ -213,7 +208,7 @@ object AvailabilityManager : IFeature {
// They exist, do not add them
return MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"403: Forbidden",
"The feature is already enabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator
@ -222,43 +217,24 @@ object AvailabilityManager : IFeature {
override suspend fun disable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder {
// Check if entry exists in db
var alreadyExists = false
transaction {
alreadyExists = PlanningNotifierRoles.select {
(PlanningNotifierRoles.serverid eq gID) and (PlanningNotifierRoles.channelid eq cID)
}.count() > 0
}
if (alreadyExists) {
var matchingEntries: List<ResultRow> = mutableListOf()
transaction {
matchingEntries = PlanningNotifierRoles.select {
(PlanningNotifierRoles.serverid eq gID) and
(PlanningNotifierRoles.channelid eq cID)
}.toList()
}
if (PlanningNotifierRolesRepository.existsInChannelFromSever(cID, gID)) {
val entry = PlanningNotifierRolesRepository.getForChannelInServer(cID, gID)!!
// delete all entries for this guild and channel combo
for (e in matchingEntries) {
Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID))
.getRoleOrNull(Snowflake(e[PlanningNotifierRoles.hastimeroleid]))?.delete()
Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID))
.getRoleOrNull(Snowflake(e[PlanningNotifierRoles.wantstobenotifiedid]))
?.delete()
}
Bot.bot.kordRef.getGuild(Snowflake(gID))
.getRoleOrNull(Snowflake(entry.hasTimeRoleID))?.delete()
Bot.bot.kordRef.getGuild(Snowflake(gID))
.getRoleOrNull(Snowflake(entry.wantsToBeNotifiedID))?.delete()
// delete all found entries
transaction {
matchingEntries.forEach { entry ->
PlanningNotifierRoles.deleteWhere { id eq entry[id] }
}
}
PlanningNotifierRolesRepository.delete(entry.id)
return MessageUtil.getEmbed(
Color(0x52E019),
EmbedColor.SUCCESS,
"200: Success",
"The feature was disabled.",
u.asUser().username + "#" + u.asUser().discriminator
@ -266,7 +242,7 @@ object AvailabilityManager : IFeature {
}
// not in db, do nothing
return MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"403: Forbidden",
"The feature is already disabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator

View file

@ -21,46 +21,22 @@ package net.moonleay.lilJudd.features
import dev.kord.common.entity.Snowflake
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.jobs.MatchJob
import net.moonleay.lilJudd.jobs.component.JobManager
import net.moonleay.lilJudd.util.Logger
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
object MatchManager {
suspend fun update() {
Logger.out("Updating match roles...")
val dataList = mutableListOf<MatchPlanningDataData>()
transaction {
MatchPlanningData.selectAll().forEach {
dataList.add(
MatchPlanningDataData(
it[MatchPlanningData.id].value,
it[MatchPlanningData.serverid],
it[MatchPlanningData.channelid],
it[MatchPlanningData.matchtype],
it[MatchPlanningData.registererid],
it[MatchPlanningData.roleid],
it[MatchPlanningData.opponentName],
it[MatchPlanningData.messageid],
it[MatchPlanningData.timestamp],
it[MatchPlanningData.jobstr]
)
)
}
}
val dataList = MatchPlanningDataRepository.getAll()
for (data in dataList) {
Logger.out("Checking match role ${data.id}...")
if (data.timestamp.toLong() < System.currentTimeMillis()) {
if (data.timestamp < System.currentTimeMillis()) {
Logger.out("Match role ${data.id} is expired, removing...")
this.removeRoleFromGuild(data.serverid, data.roleid)
transaction {
MatchPlanningData.deleteWhere { MatchPlanningData.messageid eq data.messageid }
}
this.removeRoleFromGuild(data.serverID, data.roleID)
MatchPlanningDataRepository.delete(data.id)
continue
}
this.registerJob(data)
@ -71,17 +47,17 @@ object MatchManager {
private fun registerJob(data: MatchPlanningDataData) {
JobManager.addJob(
MatchJob(
data.jobstr,
data.jobString,
data.id,
"fromdb-${data.matchtype}_Vs_${data.opponentname}_[${data.id}]-${data.serverid}_${data.channelid}"
"fromdb-${data.matchType}_Vs_${data.opponentName}_[${data.id}]-${data.serverID}_${data.channelID}"
)
)
Logger.out("Registered job for match ${data.id}...")
}
private suspend fun removeRoleFromGuild(gid: String, rid: String): Boolean {
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid.toLong())) ?: return false
val role = guild.getRoleOrNull(Snowflake(rid.toLong())) ?: return false
private suspend fun removeRoleFromGuild(gid: Long, rid: Long): Boolean {
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid)) ?: return false
val role = guild.getRoleOrNull(Snowflake(rid)) ?: return false
role.delete()
return true
}

View file

@ -20,7 +20,6 @@ package net.moonleay.lilJudd.features
import dev.inmo.krontab.buildSchedule
import dev.inmo.krontab.doInfinity
import dev.kord.common.Color
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.createMessage
@ -30,20 +29,18 @@ import dev.kord.rest.builder.message.EmbedBuilder
import dev.kord.rest.builder.message.create.actionRow
import kotlinx.coroutines.delay
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import net.moonleay.lilJudd.data.entry.TimePlanningChannelsData
import net.moonleay.lilJudd.data.entry.TimePlanningMessagesData
import net.moonleay.lilJudd.data.repository.PlanningNotifierRolesRepository
import net.moonleay.lilJudd.data.repository.TimePlanningChannelsRepository
import net.moonleay.lilJudd.data.repository.TimePlanningMessagesRepository
import net.moonleay.lilJudd.extensions.FeatureManageExtension
import net.moonleay.lilJudd.features.component.FeatureEnum
import net.moonleay.lilJudd.features.component.IFeature
import net.moonleay.lilJudd.util.EmbedColor
import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
import net.moonleay.lilJudd.util.TimeUtil
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.ZoneId
import java.time.ZonedDateTime
@ -64,43 +61,26 @@ object TimeManager : IFeature {
private suspend fun runThread() {
Logger.out("Starting to notify...")
// ChannelID -> Data
val targetedChannels = TimePlanningChannelsRepository.getAll().associateBy { it.channelID }
val targetedRoles = PlanningNotifierRolesRepository.getAll().associateBy { it.channelID }
// ChannelID, ServerID
val channelList = mutableMapOf<Snowflake, Snowflake>()
// ChannelID, Data
val roleMap = mutableMapOf<Snowflake, PlanningNotifierRolesData>()
lateinit var msgStr: String
var msgStr = ""
transaction {
for (tp in TimePlanningChannels.selectAll()) {
channelList[Snowflake(tp[TimePlanningChannels.channelid])] =
Snowflake(tp[TimePlanningChannels.serverid])
Logger.out("Have to notify channel with ID ${tp[TimePlanningChannels.channelid]}.")
}
for (pnr in PlanningNotifierRoles.selectAll()) {
roleMap[Snowflake(pnr[PlanningNotifierRoles.channelid])] = PlanningNotifierRolesData(
pnr[PlanningNotifierRoles.serverid],
pnr[PlanningNotifierRoles.channelid],
pnr[PlanningNotifierRoles.hastimeroleid],
pnr[PlanningNotifierRoles.wantstobenotifiedid]
)
Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifiedid]}}")
}
}
Logger.out("${channelList.count()} Channels to notify with ${roleMap.count()} Roles to ping!")
for (ch in channelList.keys) {
Logger.out("${targetedChannels.count()} Channels to notify with ${targetedRoles.count()} Roles to ping!")
for (ch2 in targetedChannels.keys) {
val ch = Snowflake(ch2)
if (Bot.bot.kordRef.getChannel(ch) == null)
continue // TODO: Check if the channel is valid in another shard
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(ch)!!
if (roleMap != null && roleMap.keys.contains(ch) && roleMap[ch] != null) {
msgStr = ""
if (targetedRoles != null && targetedRoles.keys.contains(ch2) && targetedRoles[ch2] != null) {
c.createMessage {
this.content =
"The weekly planning starts now <@&${Snowflake(roleMap[ch]?.wantstobenotifid!!)}>"
"The weekly planning starts now <@&${Snowflake(targetedRoles[ch2]?.wantsToBeNotifiedID!!)}>"
this.embeds.add(
MessageUtil.getEmbed(
Color(0X4C4645),
EmbedColor.INFO,
"Time Planning Feature",
"Do you have time on the following Days?",
"Automated Message"
@ -111,7 +91,7 @@ object TimeManager : IFeature {
c.createMessage {
this.embeds.add(
MessageUtil.getEmbed(
Color(0X4C4645),
EmbedColor.INFO,
"Time Planning Feature",
"Do you have time on the following Days?",
"Automated Message"
@ -125,7 +105,7 @@ object TimeManager : IFeature {
val msg = c.createMessage {
this.embeds.add(
MessageUtil.getEmbedWithTable(
Color(0X4C4645),
EmbedColor.INFO,
"",
"${then.dayOfWeek.name}, ${then.dayOfMonth}.${then.monthValue}.${then.year} /${it + 1}. weekday",
mapOf(
@ -148,14 +128,15 @@ object TimeManager : IFeature {
}
// Save the message ids
transaction {
TimePlanningMessages.insert {
it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
it[TimePlanningMessages.channelid] = c.id.value.toString()
it[TimePlanningMessages.weekstamp] = TimeUtil.getWeekStamp().toOffsetDateTime().toString()
it[TimePlanningMessages.messageids] = msgStr
} get TimePlanningMessages.id
}
TimePlanningMessagesRepository.write(
TimePlanningMessagesData(
id = -1,
serverID = c.data.guildId.value?.value!!.toLong(),
channelID = c.data.id.value.toLong(),
weekstamp = then.minusDays(7).toEpochSecond(),
messageIDs = msgStr
)
)
Logger.out("Finished with ${c.data.guildId.value}")
}
Logger.out("Done! Until next Monday! <3 ")
@ -163,34 +144,22 @@ object TimeManager : IFeature {
override suspend fun enable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder {
var alreadyExists = false
transaction {
alreadyExists = TimePlanningChannels.select {
(TimePlanningChannels.serverid eq gID) and
(TimePlanningChannels.channelid eq cID)
}.count() > 0
}
if (!alreadyExists) {
transaction {
TimePlanningChannels.insert {
it[TimePlanningChannels.serverid] = gID
it[TimePlanningChannels.channelid] = cID
} get TimePlanningChannels.id
}
if (!TimePlanningChannelsRepository.exists(cID, gID)) {
TimePlanningChannelsRepository.write(TimePlanningChannelsData(id = -1, serverID = gID, channelID = cID))
return MessageUtil.getEmbed(
Color(0x52E01A),
EmbedColor.SUCCESS,
"200: Success",
"The feature was enabled in channel ${args.channel.data.name.value}",
u.asUser().username + "#" + u.asUser().discriminator
)
}
return MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"403: Forbidden",
"The feature is already enabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator
@ -199,33 +168,17 @@ object TimeManager : IFeature {
override suspend fun disable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder {
// Check if entry exists in db
var alreadyExists = false
transaction {
alreadyExists = TimePlanningChannels.select {
(TimePlanningChannels.serverid eq gID) and
(TimePlanningChannels.channelid eq cID)
}.count() > 0
}
if (alreadyExists) {
if (TimePlanningChannelsRepository.exists(cID, gID)) {
// delete all entrys for this channel
transaction {
val matchingEntries = TimePlanningChannels.select {
(TimePlanningChannels.serverid eq gID) and
(TimePlanningChannels.channelid eq cID)
}.toList()
matchingEntries.forEach { entry ->
TimePlanningChannels.deleteWhere { id eq entry[id] }
}
}
TimePlanningChannelsRepository.deleteFromChannelInServer(cID, gID)
return MessageUtil.getEmbed(
Color(0x52E019),
EmbedColor.SUCCESS,
"200: Success",
"The feature was disabled.",
u.asUser().username + "#" + u.asUser().discriminator
@ -233,7 +186,7 @@ object TimeManager : IFeature {
}
// Do nothing; not in db
return MessageUtil.getEmbed(
Color(0xE0311A),
EmbedColor.ERROR,
"403: Forbidden",
"The feature is already disabled in this channel.",
u.asUser().username + "#" + u.asUser().discriminator

View file

@ -29,16 +29,16 @@ interface IFeature {
suspend fun enable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder
suspend fun disable(
u: UserBehavior,
gID: String,
cID: String,
gID: Long,
cID: Long,
ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder

View file

@ -22,16 +22,11 @@ import dev.inmo.krontab.KronScheduler
import dev.kord.common.entity.Snowflake
import kotlinx.coroutines.Job
import net.moonleay.lilJudd.Bot
import net.moonleay.lilJudd.data.entry.MatchPlanningDataData
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.repository.MatchPlanningDataRepository
import net.moonleay.lilJudd.jobs.component.CronjobType
import net.moonleay.lilJudd.jobs.component.ICronjob
import net.moonleay.lilJudd.jobs.component.JobManager
import net.moonleay.lilJudd.util.Logger
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
class MatchJob(
override val jobIncoming: String,
@ -48,41 +43,19 @@ class MatchJob(
* */
override suspend fun jobFunction() {
Logger.out("Running MatchJob \"${this.jobName}\"")
lateinit var mpdd: MatchPlanningDataData
transaction {
for (pnr in MatchPlanningData.select {
MatchPlanningData.id eq (tableId)
}) {
mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype],
pnr[MatchPlanningData.registererid],
pnr[MatchPlanningData.roleid],
pnr[MatchPlanningData.opponentName],
pnr[MatchPlanningData.messageid],
pnr[MatchPlanningData.timestamp],
pnr[MatchPlanningData.jobstr]
)
}
}
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(mpdd.serverid))
val mpdd = MatchPlanningDataRepository.get(tableId)!!
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(mpdd.serverID))
if (guild == null) {
Logger.out("Guild not found.")
return
}
val r = guild.getRoleOrNull(Snowflake(mpdd.roleid))
val r = guild.getRoleOrNull(Snowflake(mpdd.roleID))
if (r == null) {
Logger.out("Role not found.")
return
}
r.delete()
transaction {
MatchPlanningData.deleteWhere {
MatchPlanningData.id eq (tableId)
}
}
MatchPlanningDataRepository.delete(tableId)
Logger.out("MatchJob \"${this.jobName}\" finished.")
Logger.out("Killing job \"${this.jobName}\"..")
JobManager.killJob(this)

View file

@ -0,0 +1,28 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.util
import dev.kord.common.Color
enum class EmbedColor(val color: Color) {
ERROR(Color(0xE0311A)),
WARNING(Color(0xFFA500)),
SUCCESS(Color(0x52E01A)),
INFO(Color(0x4C4645)),
}

View file

@ -41,17 +41,26 @@ object EmbedUtil {
fun getMatchButtons(): ActionRowBuilder {
val ar = ActionRowBuilder()
ar.interactionButton(ButtonStyle.Success, "public.edit.btn.matchmanagement.accept") {
this.label = "Sign me up!"
this.label = "I'm in!"
}
ar.interactionButton(ButtonStyle.Danger, "public.edit.btn.matchmanagement.cancel") {
this.label = "Cancel"
ar.interactionButton(ButtonStyle.Danger, "public.edit.btn.matchmanagement.decline") {
this.label = "I'm out!"
}
/*
ar.interactionButton(ButtonStyle.Secondary, "public.edit.btn.matchmanagement.cancel") {
this.label = "Cancel this match..."
} */
return ar
}
fun replaceXWithYinValuesAtTable(x: String, y: String, e: Embed, table: Int): EmbedBuilder {
val ebb = MessageUtil.getAClonedEmbedd(e)
for ((i, f) in e.fields.withIndex()) {
return replaceXWithYinValuesAtTable(x, y, MessageUtil.getAClonedEmbed(e), table)
}
fun replaceXWithYinValuesAtTable(x: String, y: String, ebb: EmbedBuilder, table: Int): EmbedBuilder {
val ebbb = MessageUtil.getAClonedEmbed(ebb)
ebbb.fields = mutableListOf()
for ((i, f) in ebb.fields.withIndex()) {
val fb = EmbedBuilder.Field()
fb.name = f.name
if (i == table - 1) {
@ -66,9 +75,9 @@ object EmbedUtil {
} else
fb.value = f.value
fb.inline = true
ebb.fields.add(fb)
ebbb.fields.add(fb)
}
return ebb
return ebbb
}
fun getAllUsersInTheFirstXTables(amountOfTables: Int, e: Embed): List<String> {
@ -87,8 +96,13 @@ object EmbedUtil {
}
fun addXToValuesAtTable(x: String, e: Embed, table: Int): EmbedBuilder {
val ebb = MessageUtil.getAClonedEmbedd(e)
for ((i, f) in e.fields.withIndex()) {
return addXToValuesAtTable(x, MessageUtil.getAClonedEmbed(e), table)
}
fun addXToValuesAtTable(x: String, ebb: EmbedBuilder, table: Int): EmbedBuilder {
val ebbb = MessageUtil.getAClonedEmbed(ebb)
ebbb.fields = mutableListOf()
ebb.fields.forEachIndexed { i, f ->
val fb = EmbedBuilder.Field()
fb.name = f.name
if (i == table - 1)
@ -105,9 +119,9 @@ object EmbedUtil {
}
fb.inline = true
ebb.fields.add(fb)
ebbb.fields.add(fb)
}
return ebb
return ebbb
}
}

View file

@ -22,7 +22,6 @@ import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashCommandContext
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.Color
import dev.kord.core.entity.Embed
import dev.kord.rest.builder.message.EmbedBuilder
import java.time.LocalDateTime
@ -34,7 +33,7 @@ object MessageUtil {
///Send an embedded message as a reply
suspend fun sendEmbedForPublicSlashCommand(
ctx: PublicSlashCommandContext<Arguments, ModalForm>,
color: Color,
color: EmbedColor,
title: String,
description: String
) {
@ -53,7 +52,7 @@ object MessageUtil {
///Send an embedded message with an image as a reply
suspend fun sendEmbedForPublicSlashCommandWithImage(
ctx: PublicSlashCommandContext<Arguments, ModalForm>,
color: Color,
color: EmbedColor,
title: String,
description: String,
thumbnailUrl: String
@ -71,17 +70,39 @@ object MessageUtil {
}
}
///Get a cloned embedded message, missing only the fields
fun getAClonedEmbedd(e: Embed): EmbedBuilder {
///Get a cloned embedded message
fun getAClonedEmbed(e: Embed): EmbedBuilder {
val ebb = EmbedBuilder()
ebb.color = e.color
ebb.title = e.title
e.fields.forEach {
val fb = EmbedBuilder.Field()
fb.name = it.name
fb.value = it.value
fb.inline = it.inline
ebb.fields.add(fb)
}
ebb.description = e.description
return ebb
}
fun getAClonedEmbed(e: EmbedBuilder): EmbedBuilder {
val ebb = EmbedBuilder()
ebb.color = e.color
ebb.title = e.title
e.fields.forEach {
val fb = EmbedBuilder.Field()
fb.name = it.name
fb.value = it.value
fb.inline = it.inline
ebb.fields.add(fb)
}
ebb.description = e.description
return ebb
}
fun getEmbedWithTableWithFooter(
color: Color,
color: EmbedColor,
title: String,
description: String,
values: Map<String, List<String>>?,
@ -95,7 +116,7 @@ object MessageUtil {
///Get an embedded msg with image, title and description
fun getEmbedWithTable(
color: Color,
color: EmbedColor,
title: String,
description: String,
values: Map<String, List<String>>?
@ -118,20 +139,20 @@ object MessageUtil {
///Get an embedded msg with title and description
fun getEmbedSmall(
color: Color,
color: EmbedColor,
title: String,
description: String
): EmbedBuilder {
val ebb = EmbedBuilder()
ebb.title = title
ebb.description = description
ebb.color = color
ebb.color = color.color
return ebb
}
///Get an embedded msg with title, description and a src
fun getEmbed(
color: Color,
color: EmbedColor,
title: String,
description: String,
source: String
@ -145,7 +166,7 @@ object MessageUtil {
///Get an embedded msg with image, title, description and a src
fun getEmbedWithImage(
color: Color,
color: EmbedColor,
title: String,
description: String,
source: String,