forked from TheCurle/Camelot
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start splitting modules into separate projects for organizational pur…
…poses
- Loading branch information
1 parent
929f5e6
commit e97d956
Showing
26 changed files
with
466 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id 'groovy-gradle-plugin' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import java.util.stream.Collectors | ||
|
||
project.plugins.apply('java-library') | ||
project.plugins.apply('groovy') | ||
|
||
var config = project.extensions.create('camelotModule', CamelotModuleConfig) | ||
|
||
var library = project.configurations.create('library') | ||
var moduleConfig = project.configurations.create('module') | ||
project.configurations.getByName('api').extendsFrom(library, moduleConfig) | ||
project.configurations.create('configOut') | ||
project.configurations.create('configOutSrc') | ||
|
||
sourceSets.create('config') | ||
|
||
dependencies { | ||
"configImplementation"(implementation(project(':config'))) | ||
"configOut"(compileOnly(sourceSets.config.output)) | ||
"configOutSrc"(sourceSets.config.allSource) | ||
|
||
compileOnly group: 'com.google.auto.service', name: 'auto-service', version: '1.0.1' | ||
annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: '1.0.1' | ||
|
||
implementation(project(':')) | ||
} | ||
|
||
java.toolchain.languageVersion = JavaLanguageVersion.of(21) | ||
java.toolchain.vendor = JvmVendorSpec.GRAAL_VM | ||
|
||
compileJava { | ||
options.encoding = 'UTF-8' | ||
options.compilerArgs.add('--enable-preview') | ||
} | ||
|
||
tasks.jar { | ||
from(sourceSets.config.output) | ||
} | ||
|
||
abstract class CamelotModuleConfig { | ||
@Input | ||
abstract Property<String> getId() | ||
} | ||
|
||
tasks.register('createFiles') { | ||
doLast { | ||
var name = config.id.get().split('-') | ||
.toList().stream().map { it.capitalize() } | ||
.collect(Collectors.joining('')) | ||
var modulePkg = config.id.get().replace('-', '') | ||
writeOrMove(project.file("src/main/java/net/neoforged/camelot/module/${modulePkg}/${name}Module.java"), null, """ | ||
package net.neoforged.camelot.module.${modulePkg}; | ||
import com.google.auto.service.AutoService; | ||
import net.neoforged.camelot.config.module.${name}; | ||
import net.neoforged.camelot.module.api.CamelotModule; | ||
@AutoService(CamelotModule.class) | ||
public class ${name}Module extends CamelotModule.Base<${name}> { | ||
public ${name}Module() { | ||
super(${name}.class); | ||
} | ||
@Override | ||
public String id() { | ||
return "${config.id.get()}"; | ||
} | ||
}""") | ||
writeOrMove(project.file("src/config/groovy/net/neoforged/camelot/config/module/${name}.groovy"), rootProject.file("config/src/main/groovy/net/neoforged/camelot/config/module/${name}.groovy"), """ | ||
package net.neoforged.camelot.config.module | ||
import groovy.transform.CompileStatic | ||
@CompileStatic | ||
class ${name} extends ModuleConfiguration { | ||
}""") | ||
} | ||
} | ||
|
||
tasks.register('createDBFolder') { | ||
doLast { | ||
var modulePkg = config.id.get().replace('-', '') | ||
project.file("src/main/resources/net/neoforged/camelot/module/${modulePkg}/db/schema").mkdirs() | ||
} | ||
} | ||
|
||
private static void writeOrMove(File file, File source, String txt) { | ||
if (source?.exists()) { | ||
file.delete() | ||
file << source.text | ||
source.delete() | ||
} else { | ||
file.delete() | ||
file.parentFile.mkdirs() | ||
file << txt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
id 'camelot-module' | ||
} | ||
|
||
camelotModule { | ||
id = 'file-preview' | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ged/camelot/module/FilePreviewModule.java → ...module/filepreview/FilePreviewModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id 'camelot-module' | ||
} | ||
|
||
camelotModule { | ||
id = 'info-channels' | ||
} | ||
|
||
dependencies { | ||
library(libs.bundles.jdbi) | ||
library(libs.bundles.jackson) | ||
} |
File renamed without changes.
85 changes: 85 additions & 0 deletions
85
...-channels/src/main/java/net/neoforged/camelot/module/infochannels/InfoChannelsModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package net.neoforged.camelot.module.infochannels; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.jagrosh.jdautilities.command.CommandClientBuilder; | ||
import net.dv8tion.jda.api.JDA; | ||
import net.neoforged.camelot.BotMain; | ||
import net.neoforged.camelot.config.module.InfoChannels; | ||
import net.neoforged.camelot.db.schemas.GithubLocation; | ||
import net.neoforged.camelot.module.BuiltInModule; | ||
import net.neoforged.camelot.module.api.CamelotModule; | ||
import net.neoforged.camelot.module.infochannels.command.InfoChannelCommand; | ||
import net.neoforged.camelot.module.infochannels.command.RuleCommand; | ||
import net.neoforged.camelot.module.infochannels.db.InfoChannel; | ||
import net.neoforged.camelot.module.infochannels.db.InfoChannelsDAO; | ||
import net.neoforged.camelot.module.infochannels.db.RulesDAO; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Info channels module. | ||
*/ | ||
@AutoService(CamelotModule.class) | ||
public class InfoChannelsModule extends CamelotModule.WithDatabase<InfoChannels> { | ||
public InfoChannelsModule() { | ||
super(InfoChannels.class); | ||
|
||
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder | ||
.add(BuiltInModule.DatabaseSource.MAIN, 15, stmt -> { | ||
logger.info("Migrating info channels from main.db to info-channels.db"); | ||
var infoChannels = stmt.executeQuery("select * from info_channels"); | ||
db().useExtension(InfoChannelsDAO.class, db -> { | ||
while (infoChannels.next()) { | ||
db.insert( | ||
new InfoChannel( | ||
infoChannels.getLong(1), | ||
GithubLocation.parse(infoChannels.getString(2)), | ||
infoChannels.getBoolean(3), | ||
infoChannels.getString(4), | ||
InfoChannel.Type.values()[infoChannels.getInt(5)] | ||
) | ||
); | ||
} | ||
}); | ||
|
||
logger.info("Migrating rules from main.db to info-channels.db"); | ||
var rules = stmt.executeQuery("select * from rules"); | ||
db().useExtension(RulesDAO.class, db -> { | ||
while (rules.next()) { | ||
db.insert( | ||
rules.getLong(1), | ||
rules.getLong(2), | ||
rules.getInt(3), | ||
rules.getString(4) | ||
); | ||
} | ||
}); | ||
})); | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return "info-channels"; | ||
} | ||
|
||
@Override | ||
public boolean shouldLoad() { | ||
return config().getAuth() != null; | ||
} | ||
|
||
@Override | ||
public void registerCommands(CommandClientBuilder builder) { | ||
builder.addSlashCommand(new InfoChannelCommand()) | ||
.addSlashCommand(RuleCommand.INSTANCE) | ||
.addCommand(RuleCommand.INSTANCE) | ||
.addContextMenu(new InfoChannelCommand.UploadToDiscohookContextMenu()); | ||
} | ||
|
||
@Override | ||
public void setup(JDA jda) { | ||
jda.addEventListener(InfoChannelCommand.EVENT_LISTENER); | ||
|
||
// Update info channels every couple of minutes | ||
BotMain.EXECUTOR.scheduleAtFixedRate(InfoChannelCommand::run, 1, 2, TimeUnit.MINUTES); | ||
} | ||
} |
Oops, something went wrong.