Disabled imageListener and ServerJoined

This commit is contained in:
Aleksei 2020-02-22 12:15:40 -05:00
parent a309acd344
commit 29308afaed
2 changed files with 101 additions and 101 deletions

View File

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

View File

@ -23,13 +23,13 @@ public class ServerJoined implements ServerJoinListener {
this.db = db;
}
public void onServerJoin(ServerJoinEvent event) {
db.newServerProcess(event.getServer());
public void onServerJoin(ServerJoinEvent event) { // TODO: This needs fixing yo
// db.newServerProcess(event.getServer());
EmbedBuilder embed = new EmbedBuilder()
.setTitle("Server joined")
.setColor(Color.GREEN)
.addInlineField("Server name:", event.getServer().getName())
.addInlineField("Server Id:", event.getServer().getIdAsString());
// EmbedBuilder embed = new EmbedBuilder()
// .setTitle("Server joined")
// .setColor(Color.GREEN)
// .addInlineField("Server name:", event.getServer().getName())
// .addInlineField("Server Id:", event.getServer().getIdAsString());
}
}