Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
fix: Remove bug func (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
book000 authored Aug 22, 2022
1 parent 678205b commit 9a64531
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 194 deletions.
21 changes: 20 additions & 1 deletion src/main/java/com/jaoafa/javajaotan2/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandClient;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.command.ContextMenu;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import com.jaoafa.javajaotan2.lib.*;
import com.jaoafa.javajaotan2.tasks.Task_CheckMailVerified;
Expand Down Expand Up @@ -115,7 +116,8 @@ public static void main(String[] args) {
GatewayIntent.MESSAGE_CONTENT,
GatewayIntent.GUILD_MESSAGE_TYPING,
GatewayIntent.DIRECT_MESSAGE_TYPING,
GatewayIntent.GUILD_EMOJIS_AND_STICKERS
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
GatewayIntent.GUILD_MESSAGE_REACTIONS
)
.setAutoReconnect(true)
.setBulkDeleteSplittingEnabled(false)
Expand Down Expand Up @@ -155,6 +157,7 @@ static CommandClient getCommandClient() {
builder.setOwnerId(config.getOwnerId());

registerCommand(builder);
registerMenu(builder);

// とりあえずスラッシュコマンドはサポートしない

Expand Down Expand Up @@ -306,6 +309,22 @@ static void registerEvent(JDABuilder jdaBuilder) {
}
}

static void registerMenu(CommandClientBuilder builder) {
final String commandPackage = "com.jaoafa.javajaotan2.menu";
Reflections reflections = new Reflections(commandPackage);
Set<Class<? extends ContextMenu>> subTypes = reflections.getSubTypesOf(ContextMenu.class);

for (Class<? extends ContextMenu> theClass : subTypes) {
try {
builder.addContextMenu(theClass.getDeclaredConstructor().newInstance());
getLogger().info("%s: メニューの登録に成功しました".formatted(theClass.getSimpleName()));
} catch (Throwable throwable) {
throwable.printStackTrace();
getLogger().error("%s: メニューの登録に失敗しました".formatted(theClass.getSimpleName()));
}
}
}

static void registerTask() {
SchedulerFactory factory = new StdSchedulerFactory();
List<TaskConfig> tasks = List.of(
Expand Down
130 changes: 0 additions & 130 deletions src/main/java/com/jaoafa/javajaotan2/event/Event_BugReaction.java

This file was deleted.

63 changes: 0 additions & 63 deletions src/main/java/com/jaoafa/javajaotan2/lib/JavajaotanLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@

package com.jaoafa.javajaotan2.lib;

import com.jaoafa.javajaotan2.Main;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -99,62 +92,6 @@ public static String getContentDisplay(Message message, String raw) {
return tmp;
}

@Nonnull
public static CreateIssueResponse createIssue(String repo, String title, String body) {
String githubToken = Main.getConfig().getGitHubAPIToken();
if (githubToken == null || githubToken.isEmpty()) {
return new CreateIssueResponse(
IssueResponseType.FAILED,
"GitHub API Token が設定されていません。",
-1
);
}
String url = String.format("https://api.github.com/repos/%s/issues", repo);
JSONObject json = new JSONObject()
.put("title", title)
.put("body", body)
.put("labels", new JSONArray()
.put("\uD83D\uDC1Bbug"));

try {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = RequestBody.create(json.toString(), MediaType.parse("application/json; charset=UTF-8"));
Request request = new Request.Builder()
.url(url)
.header("Authorization", String.format("token %s", githubToken))
.post(requestBody)
.build();
JSONObject obj;
try (Response response = client.newCall(request).execute()) {
if (response.code() != 201) {
return new CreateIssueResponse(
IssueResponseType.FAILED,
"Issue の作成に失敗しました。",
-1
);
}
obj = new JSONObject(Objects.requireNonNull(response.body()).string());
}

int issueNum = obj.getInt("number");
return new CreateIssueResponse(
IssueResponseType.SUCCESS,
"Issue の作成に成功しました。",
issueNum
);
} catch (IOException e) {
e.printStackTrace();
return new CreateIssueResponse(
IssueResponseType.FAILED,
"Issue の作成に失敗しました。" + e.getMessage(),
-1
);
}
}

public record CreateIssueResponse(IssueResponseType responseType, String message, int issueNumber) {
}

public enum IssueResponseType {
SUCCESS,
FAILED
Expand Down

0 comments on commit 9a64531

Please sign in to comment.