Skip to content

Commit

Permalink
Merge pull request #202 from flytegg/feat/auto-deploy
Browse files Browse the repository at this point in the history
Add auto-deployment
  • Loading branch information
stephendotgg authored Oct 30, 2023
2 parents a403551 + 7725037 commit 2c92d40
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 13 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Compile & Deploy Gradle Jar

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: "adopt"
java-version: "17"

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Cache Gradle Dependencies
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}-

- name: Create build directory
run: mkdir -p build

- name: Gradle build
run: |
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
./gradlew build -PoutputDir=build
- name: Install JQ
run: sudo apt-get install jq

- name: Obtain Pterodactyl upload endpoint
run: |
response=$(curl "https://${{ vars.PTERO_HOST }}/api/client/servers/${{ vars.PTERO_SERVER_ID }}/files/upload" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${{ secrets.PTERO_API_KEY }}' \
-X GET)
url=$(echo "$response" | jq -r .attributes.url)
echo "URL=$url" >> $GITHUB_ENV
- name: Upload jar to Pterodactyl upload endpoint
run: |
echo $URL
echo $REPO_NAME
file=$(ls build/libs/$REPO_NAME.jar)
curl "$URL&directory=/plugins" \
-H 'Content-Type: multipart/form-data' \
-F "files=@$file" \
-X POST
- name: Restart Pterodactyl server
run: |
curl "https://${{ vars.PTERO_HOST }}/api/client/servers/${{ vars.PTERO_SERVER_ID }}/power" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${{ secrets.PTERO_API_KEY }}' \
-X POST \
-d '{
"signal": "restart"
}'
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}

build {
dependsOn(shadowJar)
}

shadowJar {
archiveFileName.set("ls-discord-bot.jar")
}

jar {
manifest {
attributes["Main-Class"] = application.mainClass
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/learnspigot/bot/Bot.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.learnspigot.bot

import com.learnspigot.bot.docs.DocRegistry
import com.learnspigot.bot.intellijkey.IJUltimateKeyRegistry
import com.learnspigot.bot.knowledgebase.KnowledgebaseRegistry
import com.learnspigot.bot.lecture.LectureRegistry
Expand Down Expand Up @@ -43,7 +42,7 @@ class Bot {

val guild = jda.getGuildById(Environment.get("GUILD_ID"))!!
VerificationMessage(guild)
LeaderboardMessage(guild, profileRegistry)
LeaderboardMessage(profileRegistry)

Neptune.Builder(jda, this)
.addGuilds(guild)
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/learnspigot/bot/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Server {
val managementRole = guild.getRoleById(Environment.get("MANAGEMENT_ROLE_ID"))!!

val leaderboardChannel = guild.getTextChannelById(Environment.get("LEADERBOARD_CHANNEL_ID"))!!
val verifyChannel = guild.getTextChannelById(Environment.get("VERIFY_CHANNEL_ID"))!!
val managerChannel = guild.getTextChannelById(Environment.get("MANAGER_CHANNEL_ID"))!!
val starboardChannel = guild.getTextChannelById(Environment.get("STARBOARD_CHANNEL_ID"))!!
val helpChannel = guild.getForumChannelById(Environment.get("HELP_CHANNEL_ID"))!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.learnspigot.bot.reputation
import com.learnspigot.bot.profile.ProfileRegistry
import com.learnspigot.bot.Server
import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.entities.Message
import net.dv8tion.jda.api.entities.MessageEmbed
import net.dv8tion.jda.api.entities.MessageHistory
import java.time.Instant
import java.time.YearMonth
import java.time.ZoneOffset
Expand All @@ -13,17 +14,27 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
import java.util.function.Consumer

class LeaderboardMessage(guild: Guild, private val profileRegistry: ProfileRegistry) {
class LeaderboardMessage(private val profileRegistry: ProfileRegistry) {

private val medals: List<String> = listOf(":first_place:", ":second_place:", ":third_place:")

private val executorService = Executors.newSingleThreadScheduledExecutor()

private var monthlyRewardMessage = Server.leaderboardChannel.sendMessageEmbeds(buildPrizeEmbed()).complete()
private var lifetimeMessage = Server.leaderboardChannel.sendMessageEmbeds(buildLeaderboard(false)).complete()
private var monthlyMessage = Server.leaderboardChannel.sendMessageEmbeds(buildLeaderboard(true)).complete()
private val monthlyRewardMessage: Message
private val lifetimeMessage: Message
private val monthlyMessage: Message

init {
Server.leaderboardChannel.apply {
// Clean up old message(s)
MessageHistory.getHistoryFromBeginning(this).complete().retrievedHistory.forEach { it.delete().queue() }

// Send new messages
monthlyRewardMessage = sendMessageEmbeds(buildPrizeEmbed()).complete()
lifetimeMessage = sendMessageEmbeds(buildLeaderboard(false)).complete()
monthlyMessage = sendMessageEmbeds(buildLeaderboard(true)).complete()
}

executorService.scheduleAtFixedRate({
lifetimeMessage.editMessageEmbeds(buildLeaderboard(false)).queue()
monthlyMessage.editMessageEmbeds(buildLeaderboard(true)).queue()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
package com.learnspigot.bot.verification

import com.learnspigot.bot.Environment
import com.learnspigot.bot.Server
import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.entities.MessageHistory
import net.dv8tion.jda.api.interactions.components.buttons.Button

class VerificationMessage(guild: Guild) {

init {
guild.getTextChannelById(Environment.get("VERIFY_CHANNEL_ID"))!!.sendMessageEmbeds(
// Clean up old message(s)
MessageHistory.getHistoryFromBeginning(Server.verifyChannel)
.complete().retrievedHistory.forEach { message -> message.delete().queue() }

// Send new message
Server.verifyChannel.sendMessageEmbeds(
embed()
.setTitle("VERIFY YOU OWN THE COURSE")
.setDescription("""
.setDescription(
"""
Welcome to the Discord for the LearnSpigot course!
:disappointed: **Don't own the course? See """.trimIndent() + guild.getTextChannelById(Environment.get("GET_COURSE_CHANNEL_ID"))!!.asMention + """
:disappointed: **Don't own the course? See """.trimIndent() + guild.getTextChannelById(
Environment.get("GET_COURSE_CHANNEL_ID")
)!!.asMention + """
**
The URL you need to use is the link to your public profile, to get this:
:one: Hover over your profile picture in the top right on Udemy
:two: Select "Public profile" from the dropdown menu
:three: Copy the link from your browser
Please make sure that you have [privacy settings](https://www.udemy.com/instructor/profile/privacy/) enabled so that we can verify you own the course.""".trimIndent())
Please make sure that you have [privacy settings](https://www.udemy.com/instructor/profile/privacy/) enabled so that we can verify you own the course.""".trimIndent()
)
.setFooter("Once you've verified, you'll have access to our 50 man support team, hundreds of additional tutorials and a supportive community.")
.build())
.build()
)
.addActionRow(Button.success("verify", "Click to Verify"))
.queue()
}

}

0 comments on commit 2c92d40

Please sign in to comment.