Class: Discordrb::Webhook
- Inherits:
-
Object
- Object
- Discordrb::Webhook
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data.rb
Overview
A webhook on a server channel
Instance Attribute Summary collapse
-
#avatar ⇒ String
The webhook's avatar id.
-
#channel ⇒ Channel
The channel that the webhook is currently connected to.
-
#name ⇒ String
The webhook name.
-
#owner ⇒ Member, ...
readonly
Gets the user object of the creator of the webhook.
-
#server ⇒ Server
readonly
The server that the webhook is currently connected to.
-
#token ⇒ String
readonly
The webhook's token.
Attributes included from IDObject
Instance Method Summary collapse
-
#avatar_url ⇒ String
Utility function to get a webhook's avatar URL.
-
#delete(reason = nil) ⇒ Object
Deletes the webhook.
-
#delete_avatar ⇒ Object
Deletes the webhook's avatar.
-
#initialize(data, bot) ⇒ Webhook
constructor
A new instance of Webhook.
-
#inspect ⇒ Object
The
inspect
method is overwritten to give more useful output. -
#token? ⇒ true, false
Utility function to know if the webhook was requested through a webhook token, rather than auth.
-
#update(data) ⇒ Object
Updates the webhook if you need to edit more than 1 attribute.
Methods included from IDObject
#==, #creation_time, synthesise
Constructor Details
#initialize(data, bot) ⇒ Webhook
Returns a new instance of Webhook.
3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 |
# File 'lib/discordrb/data.rb', line 3766 def initialize(data, bot) @bot = bot @name = data['name'] @id = data['id'].to_i @channel = bot.channel(data['channel_id']) @server = @channel.server @token = data['token'] @avatar = data['avatar'] # Will not exist if the data was requested through a webhook token return unless data['user'] @owner = @server.member(data['user']['id'].to_i) return if @owner Discordrb::LOGGER.debug("Member with ID #{data['user']['id']} not cached (possibly left the server).") @owner = @bot.ensure_user(data['user']) end |
Instance Attribute Details
#avatar ⇒ String
Returns the webhook's avatar id.
3759 3760 3761 |
# File 'lib/discordrb/data.rb', line 3759 def avatar @avatar end |
#channel ⇒ Channel
Returns the channel that the webhook is currently connected to.
3750 3751 3752 |
# File 'lib/discordrb/data.rb', line 3750 def channel @channel end |
#name ⇒ String
Returns the webhook name.
3747 3748 3749 |
# File 'lib/discordrb/data.rb', line 3747 def name @name end |
#owner ⇒ Member, ... (readonly)
Gets the user object of the creator of the webhook. May be limited to username, discriminator, ID and avatar if the bot cannot reach the owner
3764 3765 3766 |
# File 'lib/discordrb/data.rb', line 3764 def owner @owner end |
#server ⇒ Server (readonly)
Returns the server that the webhook is currently connected to.
3753 3754 3755 |
# File 'lib/discordrb/data.rb', line 3753 def server @server end |
#token ⇒ String (readonly)
Returns the webhook's token.
3756 3757 3758 |
# File 'lib/discordrb/data.rb', line 3756 def token @token end |
Instance Method Details
#avatar_url ⇒ String
Utility function to get a webhook's avatar URL.
3835 3836 3837 3838 3839 |
# File 'lib/discordrb/data.rb', line 3835 def avatar_url return API::User.default_avatar unless @avatar API::User.avatar_url(@id, @avatar) end |
#delete(reason = nil) ⇒ Object
Deletes the webhook.
3825 3826 3827 3828 3829 3830 3831 |
# File 'lib/discordrb/data.rb', line 3825 def delete(reason = nil) if token? API::Webhook.token_delete_webhook(@token, @id, reason) else API::Webhook.delete_webhook(@bot.token, @id, reason) end end |
#delete_avatar ⇒ Object
Deletes the webhook's avatar.
3793 3794 3795 |
# File 'lib/discordrb/data.rb', line 3793 def delete_avatar update_webhook(avatar: nil) end |
#inspect ⇒ Object
The inspect
method is overwritten to give more useful output.
3842 3843 3844 |
# File 'lib/discordrb/data.rb', line 3842 def inspect "<Webhook name=#{@name} id=#{@id}>" end |
#token? ⇒ true, false
Utility function to know if the webhook was requested through a webhook token, rather than auth.
3848 3849 3850 |
# File 'lib/discordrb/data.rb', line 3848 def token? @owner.nil? end |
#update(data) ⇒ Object
Updates the webhook if you need to edit more than 1 attribute.
3815 3816 3817 3818 3819 3820 3821 |
# File 'lib/discordrb/data.rb', line 3815 def update(data) # Only pass a value for avatar if the key is defined as sending nil will delete the data[:avatar] = avatarise(data[:avatar]) if data.key?(:avatar) data[:channel_id] = data[:channel].resolve_id data.delete(:channel) update_webhook(data) end |