1 /// Classes related to webhooks 2 module dcord.types.webhook; 3 4 import dcord.types, std.typecons, vibe.data.json, std.stdio, std.conv; 5 6 /// A Webhook object 7 class Webhook { 8 /// The client instance that the webhook is linked to 9 Client client; 10 /// The webhook's URL 11 string url; 12 /// The webhook's name 13 string name; 14 /// The webhook's token 15 string token; 16 /// The webhook's type 17 int type; 18 /// The webhook's avatar 19 Nullable!(string) avatar; 20 /// URL to the webhook's avatar 21 Nullable!(string) avatarUrl; 22 /// The channel ID snowflake 23 Snowflake channelID; 24 /// The guild ID snowflake 25 Snowflake guildID; 26 /// The Application ID snowflake 27 Snowflake applicationID; 28 /// The snowflake of the actual webhook's ID 29 Snowflake id; 30 this(Client client, Snowflake id) { 31 this.id = id; 32 this.client = client; 33 VibeJSON payload = client.api.getWebhook(this.id); 34 writeln(payload); 35 this.name = payload["name"].to!string; 36 this.type = payload["type"].to!int; 37 if(payload["avatar"].type != Json.Type.null_) this.avatar = payload["avatar"].to!string; 38 this.channelID = payload["channelID"].to!int; 39 this.guildID = payload["guildID"].to!int; 40 this.applicationID = payload["applicationID"].to!int; 41 this.token = payload["token"].to!string; 42 this.url = "https://discord.com/api/webhooks/" ~ this.id.to!string ~ "/" ~ this.token; 43 if(!this.avatar.isNull) 44 this.avatarUrl = "https://cdn.discordapp.com/avatars/" ~ this.id.to!string ~ "/" ~ this.avatar; 45 } 46 void sendMessage(inout(string) content, inout(string) nonce=null, inout(bool) tts=false, inout(MessageEmbed[]) embeds=null) { 47 this.client.api.sendWebhookMessage(this.id, this.token, content, nonce, tts, embeds); 48 } 49 void sendMessage(inout(string) content, inout(string) nonce=null, inout(bool) tts=false, inout(MessageEmbed) embed=null) { 50 this.client.api.sendWebhookMessage(this.id, this.token, content, nonce, tts, embed); 51 } 52 void deleteWebhook() { 53 this.client.api.deleteWebhook(this.id); 54 } 55 } 56