Disabled imageListener and ServerJoined
This commit is contained in:
parent
a309acd344
commit
29308afaed
@ -32,126 +32,126 @@ public class ImageListener implements MessageCreateListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageCreate(MessageCreateEvent event) {
|
public void onMessageCreate(MessageCreateEvent event) { // TODO: This needs immediate help
|
||||||
|
|
||||||
event.getMessage().getUserAuthor().ifPresent(author -> {
|
// event.getMessage().getUserAuthor().ifPresent(author -> {
|
||||||
if (author.isBot()) {
|
// if (author.isBot()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
Message message = event.getMessage();
|
// Message message = event.getMessage();
|
||||||
String channel = event.getChannel().getIdAsString();
|
// String channel = event.getChannel().getIdAsString();
|
||||||
String submitter = event.getMessage().getAuthor().getIdAsString();
|
// String submitter = event.getMessage().getAuthor().getIdAsString();
|
||||||
|
|
||||||
if (message.getAttachments().stream().noneMatch(MessageAttachment::isImage)) {
|
// if (message.getAttachments().stream().noneMatch(MessageAttachment::isImage)) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// If the message contains an image, check if the channel is being listened to for image storage
|
// // If the message contains an image, check if the channel is being listened to for image storage
|
||||||
|
|
||||||
String dbTable = null;
|
// String dbTable = null;
|
||||||
|
|
||||||
if(r.db("fsbot").table("channels").g("cId").contains(channel).run(conn)) {
|
// if(r.db("fsbot").table("channels").g("cId").contains(channel).run(conn)) {
|
||||||
Cursor cursor = r.db("fsbot")
|
// Cursor cursor = r.db("fsbot")
|
||||||
.table("channels")
|
// .table("channels")
|
||||||
.filter(row -> row.getField("cId").eq(channel))
|
// .filter(row -> row.getField("cId").eq(channel))
|
||||||
.getField("tag")
|
// .getField("tag")
|
||||||
.run(conn);
|
// .run(conn);
|
||||||
|
|
||||||
List tags = cursor.toList();
|
// List tags = cursor.toList();
|
||||||
|
|
||||||
for (Object tag : tags) {
|
// for (Object tag : tags) {
|
||||||
dbTable = tag.toString();
|
// dbTable = tag.toString();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<MessageAttachment> attachments = message.getAttachments();
|
// List<MessageAttachment> attachments = message.getAttachments();
|
||||||
|
|
||||||
for (MessageAttachment attachment : attachments) {
|
// for (MessageAttachment attachment : attachments) {
|
||||||
String discordLink = attachment.getUrl().toString();
|
// String discordLink = attachment.getUrl().toString();
|
||||||
String imgurLink = null;
|
// String imgurLink = null;
|
||||||
|
|
||||||
// Upload the image to imgur
|
// // Upload the image to imgur
|
||||||
try {
|
// try {
|
||||||
OkHttpClient client = new OkHttpClient();
|
// OkHttpClient client = new OkHttpClient();
|
||||||
|
|
||||||
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
|
// MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
|
||||||
|
|
||||||
RequestBody body = RequestBody.create(
|
// RequestBody body = RequestBody.create(
|
||||||
mediaType,
|
// mediaType,
|
||||||
String.format("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n%s\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", discordLink));
|
// String.format("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n%s\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", discordLink));
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
// Request request = new Request.Builder()
|
||||||
.url("https://api.imgur.com/3/image")
|
// .url("https://api.imgur.com/3/image")
|
||||||
.method("POST", body)
|
// .method("POST", body)
|
||||||
.header("Authorization", BotConfig.IMGUR_ID)
|
// .header("Authorization", BotConfig.IMGUR_ID)
|
||||||
.header("Authorization", BotConfig.IMGUR_BEARER)
|
// .header("Authorization", BotConfig.IMGUR_BEARER)
|
||||||
.build();
|
// .build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
// Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
if (response.body() == null) {
|
// if (response.body() == null) {
|
||||||
event.getChannel().sendMessage("Something went wrong!");
|
// event.getChannel().sendMessage("Something went wrong!");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
String jsonData = response.body().string();
|
// String jsonData = response.body().string();
|
||||||
imgurLink = new JSONObject(jsonData).getJSONObject("data").getString("link");
|
// imgurLink = new JSONObject(jsonData).getJSONObject("data").getString("link");
|
||||||
|
|
||||||
if (imgurLink == null) {
|
// if (imgurLink == null) {
|
||||||
event.getChannel().sendMessage("Something went wrong!");
|
// event.getChannel().sendMessage("Something went wrong!");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
catch (Exception e) {
|
// catch (Exception e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
|
|
||||||
r.db("fsbot").table("outfits").insert(
|
// r.db("fsbot").table("outfits").insert(
|
||||||
r.hashMap("link", imgurLink)
|
// r.hashMap("link", imgurLink)
|
||||||
.with("submitter", submitter)
|
// .with("submitter", submitter)
|
||||||
.with("tag", dbTable)
|
// .with("tag", dbTable)
|
||||||
).run(conn);
|
// ).run(conn);
|
||||||
|
|
||||||
final String finalLink = imgurLink;
|
// final String finalLink = imgurLink;
|
||||||
Cursor imgId = r.db("fsbot")
|
// Cursor imgId = r.db("fsbot")
|
||||||
.table("outfits")
|
// .table("outfits")
|
||||||
.filter(row -> row.getField("link").eq(finalLink))
|
// .filter(row -> row.getField("link").eq(finalLink))
|
||||||
.getField("id")
|
// .getField("id")
|
||||||
.run(conn);
|
// .run(conn);
|
||||||
|
|
||||||
String embedId = null;
|
// String embedId = null;
|
||||||
List imgIds = imgId.toList();
|
// List imgIds = imgId.toList();
|
||||||
for (Object id : imgIds) {
|
// for (Object id : imgIds) {
|
||||||
embedId = id.toString();
|
// embedId = id.toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
EmbedBuilder embed = new EmbedBuilder()
|
// EmbedBuilder embed = new EmbedBuilder()
|
||||||
.setTitle("Added an entry of tag " + dbTable)
|
// .setTitle("Added an entry of tag " + dbTable)
|
||||||
.setColor(Color.GREEN)
|
// .setColor(Color.GREEN)
|
||||||
.setThumbnail(imgurLink)
|
// .setThumbnail(imgurLink)
|
||||||
.setAuthor("Placeholder")
|
// .setAuthor("Placeholder")
|
||||||
.setFooter(embedId);
|
// .setFooter(embedId);
|
||||||
|
|
||||||
event.getApi().getUserById(submitter).thenAccept(user -> embed.setAuthor(user.getDiscriminatedName()));
|
// event.getApi().getUserById(submitter).thenAccept(user -> embed.setAuthor(user.getDiscriminatedName()));
|
||||||
|
|
||||||
event.getApi().getChannelById(BotConfig.OUTFIT_LOG).ifPresent(chnl -> {
|
// event.getApi().getChannelById(BotConfig.OUTFIT_LOG).ifPresent(chnl -> {
|
||||||
chnl.asTextChannel().ifPresent(txtchnl -> {
|
// chnl.asTextChannel().ifPresent(txtchnl -> {
|
||||||
txtchnl.sendMessage(embed).join();
|
// txtchnl.sendMessage(embed).join();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
if (dbTable.equals("disaster")) {
|
// if (dbTable.equals("disaster")) {
|
||||||
// Add custom panda emoji: <:PandaWut:433045737245376522>
|
// // Add custom panda emoji: <:PandaWut:433045737245376522>
|
||||||
message.addReaction("PandaWut:433045737245376522");
|
// message.addReaction("PandaWut:433045737245376522");
|
||||||
}
|
// }
|
||||||
|
|
||||||
message.addReaction(EmojiParser.parseToUnicode(":heartpulse:"));
|
// message.addReaction(EmojiParser.parseToUnicode(":heartpulse:"));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,13 +23,13 @@ public class ServerJoined implements ServerJoinListener {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServerJoin(ServerJoinEvent event) {
|
public void onServerJoin(ServerJoinEvent event) { // TODO: This needs fixing yo
|
||||||
db.newServerProcess(event.getServer());
|
// db.newServerProcess(event.getServer());
|
||||||
|
|
||||||
EmbedBuilder embed = new EmbedBuilder()
|
// EmbedBuilder embed = new EmbedBuilder()
|
||||||
.setTitle("Server joined")
|
// .setTitle("Server joined")
|
||||||
.setColor(Color.GREEN)
|
// .setColor(Color.GREEN)
|
||||||
.addInlineField("Server name:", event.getServer().getName())
|
// .addInlineField("Server name:", event.getServer().getName())
|
||||||
.addInlineField("Server Id:", event.getServer().getIdAsString());
|
// .addInlineField("Server Id:", event.getServer().getIdAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user