-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Webhooks #147
[FEATURE] Webhooks #147
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't try-catch the `DiscordRequest.UnhandledDiscordAPIErrorException" error. It should be added to the method signature.
@seailz Fixed. Any other comments on the current code? |
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
Did you want me to keep the Webhook class or just IncomingWebhook now that there will only be one kind of Webhook? |
leave it how it is atm |
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
* @param url The URL of the Webhook. | ||
* @param discordJar A discord.jar instance used internally. | ||
*/ | ||
public record Webhook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement modify methods.
* @param url The URL of the Webhook. | ||
* @param discordJar A discord.jar instance used internally. | ||
*/ | ||
public record Webhook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement the ability to retrieve, edit, and delete webhook messages.
Will eventually be re-opened. Fixing files |
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think these are the last things that need doing before we get this merged.
src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
* @param user The user object tied to the Webhook. | ||
* @param discordJar A discord.jar instance used internally. | ||
*/ | ||
public record IncomingWebhook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement the ability to retrieve, edit, and delete webhook messages.
src/main/java/com/seailz/discordjar/utils/image/ImageUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
src/main/java/com/seailz/discordjar/model/webhook/IncomingWebhook.java
Outdated
Show resolved
Hide resolved
public EditWebhookMessageAction editMessage(String messageId, String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName){ | ||
return new EditWebhookMessageAction(messageId, content, embeds, attachments, usernameOverride, avatarUrlOverride, threadName, id, token, discordJar); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public EditWebhookMessageAction editMessage(String messageId, String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName){ | |
return new EditWebhookMessageAction(messageId, content, embeds, attachments, usernameOverride, avatarUrlOverride, threadName, id, token, discordJar); | |
} | |
public EditWebhookMessageAction editMessage(String messageId){ | |
return new EditWebhookMessageAction(messageId, id, token, discordJar); | |
} |
Please also add other messages for sending embeds, attachements, etc.
private final Snowflake channelId; | ||
private final Snowflake webhookId; | ||
private final Snowflake guildId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should all be strings - not snowflakes. This applies to the rest of the project, by the way.
public WebhookExecuteAction(String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName, DiscordJar discordJar, Snowflake channelId, Snowflake webhookId, Snowflake guildId, String webhookToken) { | ||
this.content = content; | ||
this.embeds = embeds; | ||
this.attachments = attachments; | ||
this.usernameOverride = usernameOverride; | ||
this.avatarUrlOverride = avatarUrlOverride; | ||
this.threadName = threadName; | ||
this.discordJar = discordJar; | ||
this.channelId = channelId; | ||
this.webhookId = webhookId; | ||
this.guildId = guildId; | ||
this.webhookToken = webhookToken; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public WebhookExecuteAction(String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName, DiscordJar discordJar, Snowflake channelId, Snowflake webhookId, Snowflake guildId, String webhookToken) { | |
this.content = content; | |
this.embeds = embeds; | |
this.attachments = attachments; | |
this.usernameOverride = usernameOverride; | |
this.avatarUrlOverride = avatarUrlOverride; | |
this.threadName = threadName; | |
this.discordJar = discordJar; | |
this.channelId = channelId; | |
this.webhookId = webhookId; | |
this.guildId = guildId; | |
this.webhookToken = webhookToken; | |
} | |
public WebhookExecuteAction(String content, DiscordJar discordJar, String channelId, String webhookId, String guildId, String webhookToken) { | |
this.content = content; | |
this.discordJar = discordJar; | |
this.channelId = channelId; | |
this.webhookId = webhookId; | |
this.guildId = guildId; | |
this.webhookToken = webhookToken; | |
} |
public WebhookExecuteAction execute(String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName){ | ||
return new WebhookExecuteAction(content, embeds, attachments, usernameOverride, avatarUrlOverride, threadName, discordJar, channelId, id, guildId, token); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public WebhookExecuteAction execute(String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName){ | |
return new WebhookExecuteAction(content, embeds, attachments, usernameOverride, avatarUrlOverride, threadName, discordJar, channelId, id, guildId, token); | |
} | |
public WebhookExecuteAction execute(String content) { | |
return new WebhookExecuteAction(content, discordJar, channelId, id, guildId, token); | |
} |
public Response<Message> run() { | ||
Response<Message> future = new Response<>(); | ||
new Thread(() -> { | ||
|
||
JSONObject body = new JSONObject(); | ||
if (content != null) body.put("content", content); | ||
if (embeds != null) body.put("embeds", new JSONArray(embeds)); | ||
if (attachments != null) body.put("attachments", new JSONArray(attachments)); | ||
if (usernameOverride != null) body.put("username", usernameOverride); | ||
if (avatarUrlOverride != null) body.put("avatar_url", avatarUrlOverride); | ||
if (threadName != null) { | ||
body.put("thread_name", threadName); | ||
} | ||
DiscordRequest request = new DiscordRequest( | ||
body, | ||
new HashMap<>(), | ||
URLS.POST.GUILDS.CHANNELS.EXECUTE_WEBHOOK_WITH_WAIT.replace("{guild.id}", guildId.id()).replace("{channel.id}", channelId.id()).replace("{webhook.id}", webhookId.id()).replace("{webhook.token}", webhookToken), | ||
discordJar, | ||
URLS.POST.GUILDS.CHANNELS.EXECUTE_WEBHOOK_WITH_WAIT, | ||
RequestMethod.POST | ||
); | ||
try { | ||
future.complete(Message.decompile(request.invoke().body(), discordJar)); | ||
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { | ||
future.completeError(new Response.Error(e)); | ||
return; | ||
} | ||
|
||
}).start(); | ||
|
||
return future; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add support for files - see the MessageCreateAction class for more details on how that works.
* @param webhook.token The token of the webhook | ||
* @param wait Whether to wait for server confirmation | ||
*/ | ||
public static final String EXECUTE_WEBHOOK_WITH_WAIT = "/webhooks/{webhook.id}/{webhook.token}?wait=true"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please actually add support for this endpoint - also, query params should be implemented at use instead of as separate URLs.
public EditWebhookMessageAction(String messageId, String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName, Snowflake webhookId, String webhookToken, DiscordJar discordJar) { | ||
this.messageId = messageId; | ||
this.content = content; | ||
this.embeds = embeds; | ||
this.attachments = attachments; | ||
this.usernameOverride = usernameOverride; | ||
this.avatarUrlOverride = avatarUrlOverride; | ||
this.threadName = threadName; | ||
this.webhookId = webhookId; | ||
this.webhookToken = webhookToken; | ||
this.discordJar = discordJar; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public EditWebhookMessageAction(String messageId, String content, List<Embed> embeds, List<Attachment> attachments, String usernameOverride, String avatarUrlOverride, String threadName, Snowflake webhookId, String webhookToken, DiscordJar discordJar) { | |
this.messageId = messageId; | |
this.content = content; | |
this.embeds = embeds; | |
this.attachments = attachments; | |
this.usernameOverride = usernameOverride; | |
this.avatarUrlOverride = avatarUrlOverride; | |
this.threadName = threadName; | |
this.webhookId = webhookId; | |
this.webhookToken = webhookToken; | |
this.discordJar = discordJar; | |
} | |
public EditWebhookMessageAction(String messageId, String webhookId, String webhookToken, DiscordJar discordJar) { | |
this.messageId = messageId; | |
this.webhookId = webhookId; | |
this.webhookToken = webhookToken; | |
this.discordJar = discordJar; | |
} |
For future reference, a class that has an id field should implement the Snowflake interface - it's not meant to represent individual snowflakes. |
URLS.POST.GUILDS.CHANNELS.EXECUTE_WEBHOOK, | ||
RequestMethod.POST | ||
); | ||
public Message getMessage(String messageId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this to getMessageById please.
fb70cbf
to
f892df8
Compare
Pull Request
Changes
Closes #28
Description
Adds Webhooks. This pull request isn't final yet (I think) so I will probably mark it as draft.