Skip to content

Commit

Permalink
Merge branch 'master' of /~https://github.com/xdnw/locutus
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jan 20, 2024
2 parents d6d0c1e + aee52d0 commit 7d5749f
Show file tree
Hide file tree
Showing 36 changed files with 276 additions and 646 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/locutus/wiki/WikiGenHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.locutus.wiki;

import com.google.gson.JsonObject;
import com.locutus.wiki.pages.WikiAiTools;
import com.locutus.wiki.pages.WikiAntiLeakPage;
import com.locutus.wiki.pages.WikiArgumentsPage;
Expand Down Expand Up @@ -202,4 +203,25 @@ private void writePage(BotWikiGen page) throws IOException {
File file = new File(pathRelative + File.separator + page.getPageName().toLowerCase().replace(" ", "_") + ".md");
Files.write(file.toPath(), markdown.getBytes());
}

public JsonObject generateSiteMap() {
JsonObject wiki = new JsonObject();
wiki.addProperty("home", "");
JsonObject wikiIntro = new JsonObject();
for (BotWikiGen page : getIntroPages()) {
wikiIntro.addProperty(page.getPageName(), "");
}
wiki.add("intro", wikiIntro);
JsonObject wikiTopics = new JsonObject();
for (BotWikiGen page : getTopicPages()) {
wikiTopics.addProperty(page.getPageName(), "");
}
wiki.add("topic", wikiTopics);
JsonObject wikiCommands = new JsonObject();
for (BotWikiGen page : getCommandPages()) {
wikiCommands.addProperty(page.getPageName(), "");
}
wiki.add("command", wikiCommands);
return wiki;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/locutus/wiki/pages/WikiAntiLeakPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class WikiAntiLeakPage extends BotWikiGen {
public WikiAntiLeakPage(CommandManager2 manager) {
super(manager, "announcements and opsec");
super(manager, "announcements_and_opsec");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class WikiAutoMaskingPage extends BotWikiGen {
public WikiAutoMaskingPage(CommandManager2 manager) {
super(manager, "auto masking");
super(manager, "auto_masking");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class WikiBeigeCyclingPage extends BotWikiGen {
public WikiBeigeCyclingPage(CommandManager2 manager) {
super(manager, "beige cycling");
super(manager, "beige_cycling");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class WikiCustomSheetsPage extends BotWikiGen {
public WikiCustomSheetsPage(CommandManager2 manager) {
super(manager, "custom spreadsheets");
super(manager, "custom_spreadsheets");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class WikiDelegateServers extends BotWikiGen {
public WikiDelegateServers(CommandManager2 manager) {
super(manager, "multiple servers");
super(manager, "multiple_servers");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class WikiFindingTargetsPage extends BotWikiGen {
public WikiFindingTargetsPage(CommandManager2 manager) {
super(manager, "target finding");
super(manager, "target_finding");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/locutus/wiki/pages/WikiLoanPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class WikiLoanPage extends BotWikiGen {
public WikiLoanPage(CommandManager2 manager) {
super(manager, "loan reporting");
super(manager, "loan_reporting");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/locutus/wiki/pages/WikiSelfRoles.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class WikiSelfRoles extends BotWikiGen {
public WikiSelfRoles(CommandManager2 manager) {
super(manager, "multiple servers");
super(manager, "multiple_servers");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class WikiSendTargetsPage extends BotWikiGen {
public WikiSendTargetsPage(CommandManager2 manager) {
super(manager, "sending targets");
super(manager, "sending_targets");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/locutus/wiki/pages/WikiSetupPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class WikiSetupPage extends BotWikiGen {
public WikiSetupPage(CommandManager2 manager) {
super(manager, "initial setup");
super(manager, "initial_setup");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class WikiWarAlertsPage extends BotWikiGen {
public WikiWarAlertsPage(CommandManager2 manager) {
super(manager, "war alerts");
super(manager, "war_alerts");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/locutus/wiki/pages/WikiWarRoomPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class WikiWarRoomPage extends BotWikiGen {
public WikiWarRoomPage(CommandManager2 manager) {
super(manager, "war rooms");
super(manager, "war_rooms");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public T apply(ValueStore store, Object t) {
if (!paramKey.isDefault()) {
System.out.println("Failed to apply " + paramKey + " to " + method.getDeclaringClass().getSimpleName() + "#" + method.getName());
throw e;
} else {
System.out.println("Option is default " + paramKey + " to " + method.getDeclaringClass().getSimpleName() + "#" + method.getName() + " | " + e.getMessage());
}
arg = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public Set<T> parseSet(ValueStore store2, String input) {
// get function
TypedFunction<T, ?> function = functions.get(section);
if (function != null) {
System.out.println("Return function 1" + function.getName() + " | " + function.getType());
System.out.println("Return function 1:" + function.getName() + " | " + function.getType());
return function;
}
System.out.println("Return non function section " + section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public CommandGroup(CommandCallable parent, String[] aliases, ValueStore store,
this.aliases = Arrays.asList(aliases);
}

public JSONObject toCommandMap() {
JSONObject root = new JSONObject();
public JsonObject generateSiteMap() {
JsonObject root = new JsonObject();
getParametricCallables(f -> {
String fullPath = f.getFullPath();
String[] split = fullPath.split(" ");
JSONObject current = root;
JsonObject current = root;
for (int i = 0; i < split.length - 1; i++) {
String s = split[i];
if (!current.has(s)) {
current.put(s, new JSONObject());
current.add(s, new JsonObject());
}
current = current.getJSONObject(s);
current = current.getAsJsonObject(s);
}
current.put(split[split.length - 1], "");
current.addProperty(split[split.length - 1], "");
return false;
});
return root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public ParametricCallable(CommandCallable parent, ValueStore store, Object objec
for (Annotation annotation : annotations) {
if (annotation instanceof Switch) {
parameter.setFlag(((Switch) annotation).value());
parameter.setOptional(true);
} else if (annotation instanceof Default) {
parameter.setOptional(true);
String[] value = ((Default) annotation).value();
Expand Down Expand Up @@ -712,7 +713,8 @@ public Object[] parseArgumentMap2(Map<String, Object> combined, ValueStore store
public Object apply(ParameterData param, Object o) {
if (o == null) {
if (!param.getBinding().isConsumer(store)) {
return locals.getProvided(param.getBinding().getKey(), false);
Object result = locals.getProvided(param.getBinding().getKey(), !param.isOptional());
return result;
}
String def = param.getDefaultValueString();
if (def != null) {
Expand Down Expand Up @@ -743,7 +745,8 @@ public Object apply(ParameterData param, Object o) {
public Object apply(ParameterData param, Object o) {
if (o == null) {
if (!param.getBinding().isConsumer(store)) {
return locals.getProvided(param.getBinding().getKey(), false);
Object result = locals.getProvided(param.getBinding().getKey(), !param.isOptional());
return result;
}
String def = param.getDefaultValueString();
if (def != null) {
Expand Down Expand Up @@ -797,10 +800,13 @@ public Object apply(ParameterData param, Object o) {
// List<String> args;
if (arg == null && parameter.isOptional()) {
if (parameter.getDefaultValue() == null) {
paramVals[i] = null;
if (parameter.getBinding().isConsumer(store)) {
paramVals[i] = null;
} else {
paramVals[i] = locals.getProvided(parameter.getBinding().getKey(), false);
}
continue;
}
// args = new ArrayList<>(Arrays.asList(parameter.getDefaultValue()));
arg2 = parameter.getDefaultValueString();
} else if (arg != null) {
arg2 = arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import link.locutus.discord.util.offshore.OffshoreInstance;
import link.locutus.discord.apiv1.enums.ResourceType;
import link.locutus.discord.util.offshore.TransferResult;
import link.locutus.discord.web.jooby.WebRoot;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
Expand Down Expand Up @@ -2278,7 +2279,7 @@ public String withdrawEscrowed(@Me OffshoreInstance offshore, @Me IMessageIO cha
@Command
@RolePermission(Roles.MEMBER)
public synchronized String grants(@Me GuildDB db, DBNation nation) {
String baseUrl = Settings.INSTANCE.WEB.REDIRECT + "/" + db.getIdLong() + "/";
String baseUrl = WebRoot.REDIRECT + "/" + db.getIdLong() + "/";
List<String> pages = Arrays.asList(
baseUrl + "infragrants/" + nation.getNation_id(),
baseUrl + "landgrants/" + nation.getNation_id(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package link.locutus.discord.commands.manager.v2.impl.pw.filter;

import io.javalin.http.RedirectResponse;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import link.locutus.discord.Locutus;
import link.locutus.discord.commands.manager.v2.binding.Key;
Expand All @@ -16,6 +17,8 @@
import link.locutus.discord.commands.manager.v2.command.CommandCallable;
import link.locutus.discord.commands.manager.v2.command.CommandUsageException;
import link.locutus.discord.commands.manager.v2.command.IMessageIO;
import link.locutus.discord.commands.manager.v2.command.ParameterData;
import link.locutus.discord.commands.manager.v2.command.ParametricCallable;
import link.locutus.discord.commands.manager.v2.impl.discord.permission.RolePermission;
import link.locutus.discord.commands.manager.v2.impl.pw.binding.PWBindings;
import link.locutus.discord.commands.manager.v2.impl.pw.refs.CM;
Expand Down Expand Up @@ -114,17 +117,20 @@ public String getDescription() {

public List<NationAttribute> getMetrics(ValueStore store) {
List<NationAttribute> result = new ArrayList<>();
for (CommandCallable cmd : getFilterCallables()) {
String id = cmd.aliases().get(0);
for (CommandCallable callable : getFilterCallables()) {
ParametricCallable cmd = (ParametricCallable) callable;
if (cmd.getUserParameters().stream().anyMatch(f -> !f.isOptional())) continue;
try {
TypedFunction<DBNation, ?> typeFunction = formatRecursively(store, id, null, 0, false);
if (typeFunction == null) continue;

NationAttribute metric = new NationAttribute(cmd.getPrimaryCommandId(), cmd.simpleDesc(), typeFunction.getType(), typeFunction);
result.add(metric);
} catch (IllegalStateException | CommandUsageException ignore) {
continue;
}
String id = cmd.aliases().get(0);
try {
TypedFunction<DBNation, ?> typeFunction = formatRecursively(store, id, null, 0, false);
if (typeFunction == null) continue;
NationAttribute metric = new NationAttribute(cmd.getPrimaryCommandId(), cmd.simpleDesc(), typeFunction.getType(), typeFunction);
result.add(metric);
} catch (IllegalStateException | CommandUsageException ignore) {
continue;
}
} catch (RedirectResponse ignore) {}
}
return result;
}
Expand Down Expand Up @@ -166,12 +172,16 @@ public NationAttributeDouble getMetricDouble(ValueStore store, String id, boolea

public List<NationAttributeDouble> getMetricsDouble(ValueStore store) {
List<NationAttributeDouble> result = new ArrayList<>();
for (CommandCallable cmd : getFilterCallables()) {
String id = cmd.aliases().get(0);
NationAttributeDouble metric = getMetricDouble(store, id, true);
if (metric != null) {
result.add(metric);
}
for (CommandCallable callable : getFilterCallables()) {
ParametricCallable cmd = (ParametricCallable) callable;
if (cmd.getUserParameters().stream().anyMatch(f -> !f.isOptional())) continue;
try {
String id = cmd.aliases().get(0);
NationAttributeDouble metric = getMetricDouble(store, id, true);
if (metric != null) {
result.add(metric);
}
} catch (RedirectResponse ignore) {}
}
for (Map.Entry<String, NationAttribute> entry : customMetrics.entrySet()) {
String id = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,33 +256,35 @@ public void run() {

List<DBNation> nationsCreated = nationsNone.stream().filter(f -> f.getDate() > createCutoff).toList();

for (DBNation nation : nationsCreated) {
long date = nation.getDate();
long ageMs = now - date;

// get the messages which are below ageMs but above the lastSent
List<Map.Entry<GuildDB, CustomConditionMessage>> messages = getMessagesBetween(creation, 0, ageMs);
messages.removeIf(f -> f.getValue().getOriginDate() > date || Math.abs(ageMs - f.getValue().getDelay()) > TimeUnit.DAYS.toMillis(7));
if (!messages.isEmpty()) {
Set<Long> guildsSent = new LongArraySet();
for (Map.Entry<GuildDB, CustomConditionMessage> entry : messages) {
GuildDB db = entry.getKey();
if (!guildsSent.add(db.getIdLong())) continue;
try {
CustomConditionMessage message = entry.getValue();

long lastMs = getMeta(nation, db, NationMeta.LAST_SENT_CREATION, -1L);
long lastAge = Math.max(lastMs - date + 1, 0);
if (lastAge > message.getDelay()) {
System.out.println("Last sent > delay");
continue;
}

System.out.println("Send 1");
message.send(db, nation, sendEnabled);
} finally {
if (updateMeta) {
db.setMeta(nation.getId(), NationMeta.LAST_SENT_CREATION, nowBuf);
if (creation != null) {
for (DBNation nation : nationsCreated) {
long date = nation.getDate();
long ageMs = now - date;

// get the messages which are below ageMs but above the lastSent
List<Map.Entry<GuildDB, CustomConditionMessage>> messages = getMessagesBetween(creation, 0, ageMs);
messages.removeIf(f -> f.getValue().getOriginDate() > date || Math.abs(ageMs - f.getValue().getDelay()) > TimeUnit.DAYS.toMillis(7));
if (!messages.isEmpty()) {
Set<Long> guildsSent = new LongArraySet();
for (Map.Entry<GuildDB, CustomConditionMessage> entry : messages) {
GuildDB db = entry.getKey();
if (!guildsSent.add(db.getIdLong())) continue;
try {
CustomConditionMessage message = entry.getValue();

long lastMs = getMeta(nation, db, NationMeta.LAST_SENT_CREATION, -1L);
long lastAge = Math.max(lastMs - date + 1, 0);
if (lastAge > message.getDelay()) {
System.out.println("Last sent > delay");
continue;
}

System.out.println("Send 1");
message.send(db, nation, sendEnabled);
} finally {
if (updateMeta) {
db.setMeta(nation.getId(), NationMeta.LAST_SENT_CREATION, nowBuf);
}
}
}
}
Expand Down Expand Up @@ -329,8 +331,6 @@ public void run() {
}
}
}


}
}

Expand Down
Loading

0 comments on commit 7d5749f

Please sign in to comment.