mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-05 16:01:49 +00:00
added Arole to command received handler in order to handle it
restructured channel service calls a little bit moved dm sending to message service fixed log level configuration added full user dto, to be used as a combination of a AUserInServer and Member, for operations which need both, to avoid converting and reloading the user added mute command and mute role command added mute table added mute role table added job to automatically unmute people at the given time period restructured warn service removed simple message log for warnings added method to templating to support formatting instants
This commit is contained in:
@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.templating.config;
|
||||
|
||||
import dev.sheldan.abstracto.templating.loading.DatabaseTemplateLoader;
|
||||
import dev.sheldan.abstracto.templating.methods.DurationMethod;
|
||||
import dev.sheldan.abstracto.templating.methods.InstantMethod;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,12 +21,16 @@ public class FreemarkerConfiguration {
|
||||
@Autowired
|
||||
private DurationMethod durationMethod;
|
||||
|
||||
@Autowired
|
||||
private InstantMethod instantMethod;
|
||||
|
||||
@Bean
|
||||
public Configuration freeMarkerConfiguration() throws IOException, TemplateException {
|
||||
FreeMarkerConfigurationFactory factory = new FreeMarkerConfigurationFactory();
|
||||
factory.setPreTemplateLoaders(templateLoader);
|
||||
Configuration configuration = factory.createConfiguration();
|
||||
configuration.setSharedVariable("fmtDuration", durationMethod);
|
||||
configuration.setSharedVariable("formatInstant", instantMethod);
|
||||
configuration.setEncoding(Locale.getDefault(), "utf-8");
|
||||
// needed to support default methods in interfaces
|
||||
configuration.setIncompatibleImprovements(Configuration.VERSION_2_3_29);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package dev.sheldan.abstracto.templating.methods;
|
||||
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import freemarker.ext.beans.StringModel;
|
||||
import freemarker.template.SimpleScalar;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class InstantMethod implements TemplateMethodModelEx {
|
||||
|
||||
@Autowired
|
||||
private TemplateService service;
|
||||
|
||||
@Override
|
||||
public Object exec(List arguments) throws TemplateModelException {
|
||||
if (arguments.size() != 2) {
|
||||
throw new TemplateModelException("Incorrect parameters passed.");
|
||||
}
|
||||
Object wrappedObject = ((StringModel) arguments.get(0)).getWrappedObject();
|
||||
if(!(wrappedObject instanceof Instant)) {
|
||||
throw new TemplateModelException("Passed argument was not a instant object");
|
||||
}
|
||||
|
||||
String formatString = ((SimpleScalar) arguments.get(1)).getAsString();
|
||||
Instant duration = (Instant) wrappedObject;
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatString)
|
||||
.withZone(ZoneId.systemDefault());
|
||||
return formatter.format(duration);
|
||||
}
|
||||
|
||||
private HashMap<String, Object> getParam(Long value) {
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
params.put("amount", value);
|
||||
return params;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user