aboutsummaryrefslogtreecommitdiff
path: root/src/model/webhook.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2017-01-23 12:16:06 -0800
committerAustin Hellyer <[email protected]>2017-01-23 12:16:06 -0800
commit651c618f17cb92d3ea9bbd1d5f5c92a015ff64e0 (patch)
treedcf452e8fe73411af331678a769cb769a32dd12e /src/model/webhook.rs
parentFix no-framework compilation (diff)
downloadserenity-651c618f17cb92d3ea9bbd1d5f5c92a015ff64e0.tar.xz
serenity-651c618f17cb92d3ea9bbd1d5f5c92a015ff64e0.zip
Switch to a mostly-fully OOP approach
The context is now strictly in relation to the context of the current channel related to the event, if any. See Context::say for a list of events that the context can be used for.
Diffstat (limited to 'src/model/webhook.rs')
-rw-r--r--src/model/webhook.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/model/webhook.rs b/src/model/webhook.rs
index 9d3a393..f1a664d 100644
--- a/src/model/webhook.rs
+++ b/src/model/webhook.rs
@@ -1,6 +1,6 @@
use serde_json::builder::ObjectBuilder;
use std::mem;
-use super::{Message, Webhook};
+use super::{Message, Webhook, WebhookId};
use ::utils::builder::ExecuteWebhook;
use ::client::rest;
use ::internal::prelude::*;
@@ -12,7 +12,7 @@ impl Webhook {
/// authentication is not required.
///
/// [`rest::delete_webhook_with_token`]: ../client/rest/fn.delete_webhook_with_token.html
- #[cfg(feature="methods")]
+ #[inline]
pub fn delete(&self) -> Result<()> {
rest::delete_webhook_with_token(self.id.0, &self.token)
}
@@ -63,7 +63,6 @@ impl Webhook {
///
/// [`rest::edit_webhook`]: ../client/rest/fn.edit_webhook.html
/// [`rest::edit_webhook_with_token`]: ../client/rest/fn.edit_webhook_with_token.html
- #[cfg(feature="methods")]
pub fn edit(&mut self, name: Option<&str>, avatar: Option<&str>)
-> Result<()> {
if name.is_none() && avatar.is_none() {
@@ -84,9 +83,7 @@ impl Webhook {
map = map.insert("name", name);
}
- let map = map.build();
-
- match rest::edit_webhook_with_token(self.id.0, &self.token, map) {
+ match rest::edit_webhook_with_token(self.id.0, &self.token, map.build()) {
Ok(replacement) => {
mem::replace(self, replacement);
@@ -143,12 +140,9 @@ impl Webhook {
/// .embeds(vec![embed]))
/// .expect("Error executing");
/// ```
- #[cfg(feature="methods")]
- pub fn execute<F>(&self, f: F) -> Result<Message>
- where F: FnOnce(ExecuteWebhook) -> ExecuteWebhook {
- let map = f(ExecuteWebhook::default()).0.build();
-
- rest::execute_webhook(self.id.0, &self.token, map)
+ #[inline]
+ pub fn execute<F: FnOnce(ExecuteWebhook) -> ExecuteWebhook>(&self, f: F) -> Result<Message> {
+ rest::execute_webhook(self.id.0, &self.token, f(ExecuteWebhook::default()).0.build())
}
/// Retrieves the latest information about the webhook, editing the
@@ -158,7 +152,6 @@ impl Webhook {
/// authentication is not required.
///
/// [`rest::get_webhook_with_token`]: ../client/rest/fn.get_webhook_with_token.html
- #[cfg(feature="methods")]
pub fn refresh(&mut self) -> Result<()> {
match rest::get_webhook_with_token(self.id.0, &self.token) {
Ok(replacement) => {
@@ -170,3 +163,15 @@ impl Webhook {
}
}
}
+
+impl WebhookId {
+ /// Retrieves the webhook by the Id.
+ ///
+ /// **Note**: Requires the [Manage Webhooks] permission.
+ ///
+ /// [Manage Webhooks]: permissions/constant.MANAGE_WEBHOOKS.html
+ #[inline]
+ pub fn get(&self) -> Result<Webhook> {
+ rest::get_webhook(self.0)
+ }
+}