Skip to content

Commit

Permalink
Add search command
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle committed Sep 16, 2024
1 parent 98569a4 commit 2fec219
Show file tree
Hide file tree
Showing 8 changed files with 1,461 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ cmake-build-*/
# IntelliJ
out/

# VSCode
.vscode/

# mpeltonen/sbt-idea plugin
.idea_modules/

Expand Down Expand Up @@ -237,3 +240,4 @@ gradle-app.setting
# End of https://www.toptal.com/developers/gitignore/api/git,java,gradle,eclipse,netbeans,jetbrains+all,visualstudiocode.

bot.properties
bot
4 changes: 4 additions & 0 deletions bot.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ github-token: github_oauth_token
sentry-dsn: https://[email protected]/xxx
sentry-env: production
ocr-path: /usr/share/tesseract-ocr/4.00/tessdata
algolia-application-id: 0DTHI9QFCH
algolia-search-api-key: 3cc0567f76d2ed3ffdb4cc94f0ac9815
algolia-index-name: geysermc
algolia-site-search-url: https://geysermc.org/search?q=
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ dependencies {
// Image processing and OCR
implementation 'net.sourceforge.tess4j:tess4j:5.12.0'
implementation 'org.imgscalr:imgscalr-lib:4.2'

// Agolia Search (For Wiki)
// We should eventually switch to v4, but currently it doesn't serialize POJOs correctly...
// implementation 'com.algolia:algoliasearch:4.3.1'
implementation 'com.algolia:algoliasearch-core:3.16.9'
implementation 'com.algolia:algoliasearch-java-net:3.16.9'
}

jar {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/geysermc/discordbot/GeyserBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.geysermc.discordbot;

import com.algolia.search.DefaultSearchClient;
import com.algolia.search.SearchIndex;
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.command.ContextMenu;
Expand All @@ -51,6 +53,7 @@
import org.geysermc.discordbot.tags.TagsManager;
import org.geysermc.discordbot.updates.UpdateManager;
import org.geysermc.discordbot.util.BotHelpers;
import org.geysermc.discordbot.util.DocSearchResult;
import org.geysermc.discordbot.util.PropertiesManager;
import org.geysermc.discordbot.util.RssFeedManager;
import org.geysermc.discordbot.util.SentryEventManager;
Expand Down Expand Up @@ -87,6 +90,7 @@ public class GeyserBot {
private static JDA jda;
private static GitHub github;
private static Server httpServer;
private static SearchIndex<DocSearchResult> algolia;

static {
// Gathers all commands from "commands" package.
Expand Down Expand Up @@ -161,6 +165,10 @@ public static void main(String[] args) throws IOException {
// Connect to github
github = new GitHubBuilder().withOAuthToken(PropertiesManager.getGithubToken()).build();

// Connect to Algolia
algolia = DefaultSearchClient.create(PropertiesManager.getAlgoliaApplicationId(), PropertiesManager.getAlgoliaSearchApiKey())
.initIndex(PropertiesManager.getAlgoliaIndexName(), DocSearchResult.class);

// Initialize the waiter
EventWaiter waiter = new EventWaiter();

Expand Down Expand Up @@ -298,6 +306,10 @@ public static GitHub getGithub() {
return github;
}

public static SearchIndex<DocSearchResult> getAlgolia() {
return algolia;
}

public static ScheduledExecutorService getGeneralThreadPool() {
return generalThreadPool;
}
Expand Down
Loading

0 comments on commit 2fec219

Please sign in to comment.