Class: OnyxCord::Channel
- Inherits:
-
Object
- Object
- OnyxCord::Channel
- Includes:
- IDObject
- Defined in:
- lib/onyxcord/models/channel.rb
Overview
A Discord channel, including data like the topic
Constant Summary collapse
- TYPES =
Map of channel types.
{ text: 0, dm: 1, voice: 2, group: 3, category: 4, news: 5, store: 6, news_thread: 10, public_thread: 11, private_thread: 12, stage_voice: 13, directory: 14, forum: 15, media: 16 }.freeze
- FLAGS =
Map of channel flags.
{ pinned: 1 << 1, require_tag: 1 << 4, hide_download_options: 1 << 15 }.freeze
- FORUM_LAYOUTS =
Map of forum layouts.
{ not_set: 0, list_view: 1, gallery_view: 2 }.freeze
- FORUM_SORT_ORDERS =
Map of forum sort orders.
{ latest_activity: 0, creation_time: 1 }.freeze
- VIDEO_QUALITY_MODES =
Map of video quality modes.
{ auto: 1, full: 2 }.freeze
Instance Attribute Summary collapse
-
#archive_timestamp ⇒ Time?
readonly
The timestamp of when this threads status last changed.
-
#archived ⇒ true, ...
(also: #archived?)
readonly
Whether or not this thread is archived.
-
#auto_archive_duration ⇒ Integer?
readonly
How long after the last message before a thread is automatically archived.
-
#bitrate ⇒ Integer
The bitrate (in bps) of the channel.
-
#default_auto_archive_duration ⇒ Integer?
readonly
The default client-side duration before a thread is automatically hidden.
-
#default_forum_layout ⇒ Integer?
readonly
The default layout used to display threads in this forum or media channel.
-
#default_sort_order ⇒ Integer?
readonly
The default sorting order for threads in this forum or media channel.
-
#default_thread_rate_limit_per_user ⇒ Integer?
readonly
The initial slowmode rate set on newly created threads in this channel.
-
#flags ⇒ Integer
readonly
The flags set on this channel combined as a bitfield.
-
#invitable ⇒ true, ...
(also: #invitable?)
readonly
For private threads, determines whether non-moderators can add other non-moderators to a thread.
-
#join_timestamp ⇒ Time?
readonly
When the current user joined this thread.
-
#last_message_id ⇒ Integer?
readonly
The ID of the last message sent in this channel.
-
#last_pin_timestamp ⇒ Time?
readonly
The time at when the last pinned message was pinned in this channel.
-
#locked ⇒ true, ...
(also: #locked?)
readonly
Whether this thread is locked or not.
-
#member_count ⇒ Integer?
readonly
An approximate count of members in a thread.
-
#member_flags ⇒ Integer?
readonly
Member flags for this thread, used for notifications.
-
#message_count ⇒ Integer?
readonly
An approximate count of messages sent in a thread, excluding deleted messages.
-
#name ⇒ String
This channel's name.
-
#owner_id ⇒ Integer?
readonly
The ID of the owner of the group channel or nil if this is not a group channel.
-
#parent_id ⇒ Integer?
readonly
The ID of the parent channel, if this channel is inside a category.
-
#position ⇒ Integer
The channel's position on the channel list.
-
#rate_limit_per_user ⇒ Integer
(also: #slowmode_rate)
The amount of time (in seconds) users need to wait to send in between messages.
-
#recipients ⇒ Array<Recipient>?
readonly
The array of recipients of the private messages, or nil if this is not a Private channel.
-
#topic ⇒ String
The channel's topic.
-
#total_message_sent ⇒ Integer
(also: #total_messages_sent)
readonly
An approximate count of messages sent in this thread, including deleted messages.
-
#type ⇒ Integer
readonly
The type of this channel.
-
#user_limit ⇒ Integer
(also: #limit)
The amount of users that can be in the channel.
-
#video_quality_mode ⇒ Integer?
readonly
The video quality mode of this voice or stage channel.
-
#voice_region ⇒ String?
readonly
The ID of the RTC voice region for this voice or stage channel.
Attributes included from IDObject
Threads collapse
-
#add_member(member) ⇒ Object
Add a member to the thread.
-
#join_thread ⇒ Object
Join this thread.
-
#leave_thread ⇒ Object
Leave this thread.
-
#members ⇒ Object
Members in the thread.
- #remove_member(member) ⇒ Object
Instance Method Summary collapse
-
#add_tags(tags, reason: nil) ⇒ Object
(also: #add_tag)
Add one or more tags to this thread channel.
-
#await(key, attributes = {}, &block) ⇒ Object
deprecated
Deprecated.
Will be changed to blocking behavior in v4.0. Use #await! instead.
-
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message in this channel.
-
#category ⇒ Channel?
(also: #parent)
The category channel, if this channel is in a category.
-
#category=(channel) ⇒ Object
(also: #parent=)
Sets this channels parent category.
-
#category? ⇒ true, false
Whether or not this channel is a category channel.
-
#children ⇒ Array<Channel>
(also: #channels)
Returns the children of this channel, if it is a category.
-
#create_tag(name:, moderated:, emoji: nil, reason: nil) ⇒ nil
Create a tag in this forum or media channel.
-
#create_webhook(name, avatar = nil, reason = nil) ⇒ Webhook
Creates a webhook in this channel.
-
#creation_time ⇒ Time?
Get the time at when this channel was created at.
-
#default_channel? ⇒ true, false
(also: #default?)
Whether or not this channel is the default channel.
- #default_reaction ⇒ Object
-
#define_overwrite(thing, allow = 0, deny = 0, reason: nil) ⇒ Object
Defines a permission overwrite for this channel that sets the specified thing to the specified allow and deny permission sets, or change an existing one.
-
#delete(reason = nil) ⇒ Object
Permanently deletes this channel.
-
#delete_message(message) ⇒ Object
Deletes a message on this channel.
-
#delete_messages(messages, strict = false, reason = nil) ⇒ Integer
Deletes a collection of messages.
-
#delete_overwrite(target, reason = nil) ⇒ Object
Deletes a permission overwrite for this channel.
-
#directory? ⇒ true, false
Whether or not this channel is a directory channel.
-
#follow(target, reason: nil) ⇒ Integer
Follow the announcement (news) channel to send crossposted messages to a target channel.
-
#forum? ⇒ true, false
Whether or not this channel is a forum channel.
-
#group? ⇒ true, false
Whether or not this channel is a group channel.
-
#history(amount, before_id = nil, after_id = nil, around_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
-
#inspect ⇒ Object
The default
inspectmethod is overwritten to give more useful output. -
#invites ⇒ Array<Invite>
Requests a list of Invites to the channel.
-
#last_message ⇒ Message, ...
Returns the last message or forum post created in this channel.
-
#link ⇒ String
(also: #jump_link)
A URL that a user can use to navigate to this channel in the client.
-
#load_message(message_id) ⇒ Message?
(also: #message)
Returns a single message from this channel's history by ID.
-
#make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Invite
(also: #invite)
Creates a new invite to this channel.
-
#media? ⇒ true, false
Whether or not this channel is a media channel.
-
#member_overwrites ⇒ Overwrite
Any member-type permission overwrites on this channel.
-
#mention ⇒ String
A string that will mention the channel as a clickable link on Discord.
-
#modify(name: :undef, type: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent: :undef, voice_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, tags: :undef, default_reaction: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, locked: :undef, invitable: :undef, add_flags: :undef, remove_flags: :undef, position: :undef, auto_archive_duration: :undef, default_thread_rate_limit_per_user: :undef, reason: nil) ⇒ nil
Modify the properties of the channel.
-
#news? ⇒ true, false
Whether or not this channel is a news channel.
-
#news_thread? ⇒ true, false
Whether or not this channel is a news thread.
-
#nsfw=(nsfw) ⇒ Object
Sets whether this channel is NSFW.
-
#nsfw? ⇒ true, false
Check if this channel is marked as NSFW.
-
#permission_overwrites(type = nil) ⇒ Object
(also: #overwrites)
This channel's permission overwrites.
-
#permission_overwrites=(overwrites) ⇒ Object
Bulk sets this channels permission overwrites.
-
#pins(limit: 50) ⇒ Array<Message>
Requests the pinned messages in a channel.
-
#pm? ⇒ true, false
Whether or not this channel is a PM channel.
-
#private? ⇒ true, false
Whether or not this channel is a PM or group channel.
-
#private_thread? ⇒ true, false
Whether or not this channel is a private thread.
-
#prune(amount, strict = false, reason = nil) {|message| ... } ⇒ Integer
Delete the last N messages on this channel.
-
#public_thread? ⇒ true, false
Whether or not this channel is a public thread.
-
#recipient ⇒ Recipient?
The recipient of the private messages, or nil if this is not a PM channel.
-
#remove_tags(tags, reason: nil) ⇒ Object
(also: #remove_tag)
Remove one or more tag from this thread channel.
-
#role_overwrites ⇒ Overwrite
Any role-type permission overwrites on this channel.
-
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) {|embed| ... } ⇒ Message
Convenience method to send a message with an embed.
-
#send_file(file, caption: nil, tts: false, filename: nil, spoiler: nil) ⇒ Object
Sends a file to this channel.
-
#send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Message
(also: #send)
Sends a message to this channel.
-
#send_message!(content: '', timeout: nil, tts: false, embeds: [], attachments: nil, allowed_mentions: nil, reference: nil, components: nil, flags: 0, has_components: false, components_v2: false, nonce: nil, enforce_nonce: false, poll: nil) {|builder, view| ... } ⇒ Message?
Send a message to this channel.
-
#send_multiple(content) ⇒ Object
Sends multiple messages to a channel.
-
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Object
Sends a temporary message to this channel.
-
#server ⇒ Server?
The server this channel is on.
-
#slowmode? ⇒ true, false
Whether or not this channel has slowmode enabled.
-
#sort_after(other = nil, lock_permissions = false) ⇒ Object
Sorts this channel's position to follow another channel.
-
#split_send(content) ⇒ Object
Splits a message into chunks whose length is at most the Discord character limit, then sends them individually.
-
#stage? ⇒ true, false
Whether or not this channel is a stage channel.
-
#start_forum_thread(name:, auto_archive_duration: nil, rate_limit_per_user: nil, tags: nil, content: nil, embeds: nil, allowed_mentions: nil, components: nil, stickers: nil, attachments: nil, flags: nil, has_components: false, components_v2: false, reason: nil) {|builder, view| ... } ⇒ Message
Start a thread in a forum or media channel.
-
#start_thread(name, auto_archive_duration, message: nil, type: 11) ⇒ Channel
Start a thread.
-
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds.
-
#store? ⇒ true, false
Whether or not this channel is a store channel.
-
#sync_overwrites ⇒ Object
(also: #sync)
Syncs this channels overwrites with its parent category.
-
#synchronized? ⇒ true, ...
(also: #synced?)
Whether this channels permissions match the permission overwrites of the category that it's in, or nil if it is not in a category.
-
#tag(id) ⇒ ChannelTag?
Get a tag in this forum or media channel.
-
#tag?(id) ⇒ true, false
Check if a specific tag has been applied to this thread.
-
#tags ⇒ Array<ChannelTag>
Get the tags for this channel.
-
#text? ⇒ true, false
Whether or not this channel is a text channel.
-
#text_channels ⇒ Array<Channel>
Returns the text channels in this category, if it is a category channel.
-
#thread? ⇒ true, false
Whether or not this channel is a thread.
-
#thread_only? ⇒ true, false
Check if this channel is a forum or media channel.
-
#users ⇒ Array<Member>
The list of users currently in this channel.
-
#voice? ⇒ true, false
Whether or not this channel is a voice channel.
-
#voice_channels ⇒ Array<Channel>
Returns the voice channels in this category, if it is a category channel.
-
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the channel.
Methods included from IDObject
Instance Attribute Details
#archive_timestamp ⇒ Time? (readonly)
Returns The timestamp of when this threads status last changed.
105 106 107 |
# File 'lib/onyxcord/models/channel.rb', line 105 def @archive_timestamp end |
#archived ⇒ true, ... (readonly) Also known as: archived?
Returns Whether or not this thread is archived.
98 99 100 |
# File 'lib/onyxcord/models/channel.rb', line 98 def archived @archived end |
#auto_archive_duration ⇒ Integer? (readonly)
Returns How long after the last message before a thread is automatically archived.
102 103 104 |
# File 'lib/onyxcord/models/channel.rb', line 102 def auto_archive_duration @auto_archive_duration end |
#bitrate ⇒ Integer
Returns the bitrate (in bps) of the channel.
78 79 80 |
# File 'lib/onyxcord/models/channel.rb', line 78 def bitrate @bitrate end |
#default_auto_archive_duration ⇒ Integer? (readonly)
Returns The default client-side duration before a thread is automatically hidden.
143 144 145 |
# File 'lib/onyxcord/models/channel.rb', line 143 def default_auto_archive_duration @default_auto_archive_duration end |
#default_forum_layout ⇒ Integer? (readonly)
Returns The default layout used to display threads in this forum or media channel.
149 150 151 |
# File 'lib/onyxcord/models/channel.rb', line 149 def default_forum_layout @default_forum_layout end |
#default_sort_order ⇒ Integer? (readonly)
Returns The default sorting order for threads in this forum or media channel.
146 147 148 |
# File 'lib/onyxcord/models/channel.rb', line 146 def default_sort_order @default_sort_order end |
#default_thread_rate_limit_per_user ⇒ Integer? (readonly)
Returns The initial slowmode rate set on newly created threads in this channel.
152 153 154 |
# File 'lib/onyxcord/models/channel.rb', line 152 def default_thread_rate_limit_per_user @default_thread_rate_limit_per_user end |
#flags ⇒ Integer (readonly)
Returns The flags set on this channel combined as a bitfield.
133 134 135 |
# File 'lib/onyxcord/models/channel.rb', line 133 def flags @flags end |
#invitable ⇒ true, ... (readonly) Also known as: invitable?
Returns For private threads, determines whether non-moderators can add other non-moderators to a thread.
119 120 121 |
# File 'lib/onyxcord/models/channel.rb', line 119 def invitable @invitable end |
#join_timestamp ⇒ Time? (readonly)
Returns When the current user joined this thread.
112 113 114 |
# File 'lib/onyxcord/models/channel.rb', line 112 def @join_timestamp end |
#last_message_id ⇒ Integer? (readonly)
Returns The ID of the last message sent in this channel. This may not point to a valid message.
126 127 128 |
# File 'lib/onyxcord/models/channel.rb', line 126 def @last_message_id end |
#last_pin_timestamp ⇒ Time? (readonly)
Returns The time at when the last pinned message was pinned in this channel.
123 124 125 |
# File 'lib/onyxcord/models/channel.rb', line 123 def @last_pin_timestamp end |
#locked ⇒ true, ... (readonly) Also known as: locked?
Returns Whether this thread is locked or not.
108 109 110 |
# File 'lib/onyxcord/models/channel.rb', line 108 def locked @locked end |
#member_count ⇒ Integer? (readonly)
Returns An approximate count of members in a thread. Stops counting at 50.
95 96 97 |
# File 'lib/onyxcord/models/channel.rb', line 95 def member_count @member_count end |
#member_flags ⇒ Integer? (readonly)
Returns Member flags for this thread, used for notifications.
115 116 117 |
# File 'lib/onyxcord/models/channel.rb', line 115 def member_flags @member_flags end |
#message_count ⇒ Integer? (readonly)
Returns An approximate count of messages sent in a thread, excluding deleted messages.
92 93 94 |
# File 'lib/onyxcord/models/channel.rb', line 92 def @message_count end |
#name ⇒ String
Returns this channel's name.
57 58 59 |
# File 'lib/onyxcord/models/channel.rb', line 57 def name @name end |
#owner_id ⇒ Integer? (readonly)
Returns the ID of the owner of the group channel or nil if this is not a group channel. If this channel is a thread, this is the member that started the thread.
69 70 71 |
# File 'lib/onyxcord/models/channel.rb', line 69 def owner_id @owner_id end |
#parent_id ⇒ Integer? (readonly)
Returns the ID of the parent channel, if this channel is inside a category. If this channel is a thread, this is the text channel it is a child to.
61 62 63 |
# File 'lib/onyxcord/models/channel.rb', line 61 def parent_id @parent_id end |
#position ⇒ Integer
Returns the channel's position on the channel list.
85 86 87 |
# File 'lib/onyxcord/models/channel.rb', line 85 def position @position end |
#rate_limit_per_user ⇒ Integer Also known as: slowmode_rate
Returns the amount of time (in seconds) users need to wait to send in between messages.
88 89 90 |
# File 'lib/onyxcord/models/channel.rb', line 88 def rate_limit_per_user @rate_limit_per_user end |
#recipients ⇒ Array<Recipient>? (readonly)
Returns the array of recipients of the private messages, or nil if this is not a Private channel.
72 73 74 |
# File 'lib/onyxcord/models/channel.rb', line 72 def recipients @recipients end |
#topic ⇒ String
Returns the channel's topic.
75 76 77 |
# File 'lib/onyxcord/models/channel.rb', line 75 def topic @topic end |
#total_message_sent ⇒ Integer (readonly) Also known as: total_messages_sent
Returns An approximate count of messages sent in this thread, including deleted messages.
129 130 131 |
# File 'lib/onyxcord/models/channel.rb', line 129 def @total_message_sent end |
#type ⇒ Integer (readonly)
Returns the type of this channel.
65 66 67 |
# File 'lib/onyxcord/models/channel.rb', line 65 def type @type end |
#user_limit ⇒ Integer Also known as: limit
Returns the amount of users that can be in the channel. 0 means it is unlimited.
81 82 83 |
# File 'lib/onyxcord/models/channel.rb', line 81 def user_limit @user_limit end |
#video_quality_mode ⇒ Integer? (readonly)
Returns The video quality mode of this voice or stage channel.
140 141 142 |
# File 'lib/onyxcord/models/channel.rb', line 140 def video_quality_mode @video_quality_mode end |
#voice_region ⇒ String? (readonly)
Returns The ID of the RTC voice region for this voice or stage channel. A region of nil means the
the voice region will automatically be determined by Discord.
137 138 139 |
# File 'lib/onyxcord/models/channel.rb', line 137 def voice_region @voice_region end |
Instance Method Details
#add_member(member) ⇒ Object
Add a member to the thread
1115 1116 1117 |
# File 'lib/onyxcord/models/channel.rb', line 1115 def add_member(member) @bot.add_thread_member(@id, member) end |
#add_tags(tags, reason: nil) ⇒ Object Also known as: add_tag
Add one or more tags to this thread channel.
1068 1069 1070 1071 1072 |
# File 'lib/onyxcord/models/channel.rb', line 1068 def (, reason: nil) raise 'Cannot add tags to this channel' unless parent&.thread_only? modify(tags: @applied_tags + Array().map(&:resolve_id), reason: reason) end |
#await(key, attributes = {}, &block) ⇒ Object
Will be changed to blocking behavior in v4.0. Use #await! instead.
Add an Await for a message in this channel. This is identical in functionality to adding a
Events::MessageEvent await with the in attribute as this channel.
888 889 890 |
# File 'lib/onyxcord/models/channel.rb', line 888 def await(key, attributes = {}, &block) @bot.add_await(key, OnyxCord::Events::MessageEvent, { in: @id }.merge(attributes), &block) end |
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message in this channel. This is identical in functionality to adding a
Events::MessageEvent await with the in attribute as this channel.
895 896 897 |
# File 'lib/onyxcord/models/channel.rb', line 895 def await!(attributes = {}, &block) @bot.add_await!(OnyxCord::Events::MessageEvent, { in: @id }.merge(attributes), &block) end |
#category ⇒ Channel? Also known as: parent
Returns the category channel, if this channel is in a category.
334 335 336 |
# File 'lib/onyxcord/models/channel.rb', line 334 def category @bot.channel(@parent_id) if @parent_id end |
#category=(channel) ⇒ Object Also known as: parent=
Sets this channels parent category
343 344 345 346 347 348 |
# File 'lib/onyxcord/models/channel.rb', line 343 def category=(channel) channel = @bot.channel(channel) raise ArgumentError, 'Cannot set parent category to a channel that isn\'t a category' unless channel.category? modify(parent: channel) end |
#category? ⇒ true, false
Returns whether or not this channel is a category channel.
273 274 275 |
# File 'lib/onyxcord/models/channel.rb', line 273 def category? @type == 4 end |
#children ⇒ Array<Channel> Also known as: channels
Returns the children of this channel, if it is a category. Otherwise returns an empty array.
496 497 498 499 500 |
# File 'lib/onyxcord/models/channel.rb', line 496 def children return [] unless category? server.channels.select { |c| c.parent_id == id } end |
#create_tag(name:, moderated:, emoji: nil, reason: nil) ⇒ nil
Create a tag in this forum or media channel.
1092 1093 1094 |
# File 'lib/onyxcord/models/channel.rb', line 1092 def create_tag(name:, moderated:, emoji: nil, reason: nil) ({ name:, moderated:, **Emoji.build_emoji_hash(emoji) }, reason) if thread_only? end |
#create_webhook(name, avatar = nil, reason = nil) ⇒ Webhook
Creates a webhook in this channel
928 929 930 931 932 933 |
# File 'lib/onyxcord/models/channel.rb', line 928 def create_webhook(name, avatar = nil, reason = nil) raise ArgumentError, 'Tried to create a webhook in a non-server channel' unless server response = REST::Channel.create_webhook(@bot.token, @id, name, avatar, reason) Webhook.new(OnyxCord::Internal::JSON.parse(response), @bot) end |
#creation_time ⇒ Time?
Get the time at when this channel was created at.
426 427 428 429 430 |
# File 'lib/onyxcord/models/channel.rb', line 426 def creation_time return @create_timestamp if @create_timestamp Time.at(((@id >> 22) + OnyxCord::DISCORD_EPOCH) / 1000.0) end |
#default_channel? ⇒ true, false Also known as: default?
Returns whether or not this channel is the default channel.
527 528 529 |
# File 'lib/onyxcord/models/channel.rb', line 527 def default_channel? server.default_channel == self end |
#default_reaction ⇒ Object
1034 1035 1036 |
# File 'lib/onyxcord/models/channel.rb', line 1034 def default_reaction @default_reaction.is_a?(Integer) ? server.emojis[@default_reaction] : @default_reaction end |
#define_overwrite(overwrite) ⇒ Object #define_overwrite(thing, allow, deny) ⇒ Object
Defines a permission overwrite for this channel that sets the specified thing to the specified allow and deny permission sets, or change an existing one.
738 739 740 741 742 743 744 745 746 747 |
# File 'lib/onyxcord/models/channel.rb', line 738 def define_overwrite(thing, allow = 0, deny = 0, reason: nil) unless thing.is_a? Overwrite allow_bits = allow.respond_to?(:bits) ? allow.bits : allow deny_bits = deny.respond_to?(:bits) ? deny.bits : deny thing = Overwrite.new(thing, allow: allow_bits, deny: deny_bits) end REST::Channel.(@bot.token, @id, thing.id, thing.allow.bits, thing.deny.bits, thing.type, reason) end |
#delete(reason = nil) ⇒ Object
Permanently deletes this channel
675 676 677 |
# File 'lib/onyxcord/models/channel.rb', line 675 def delete(reason = nil) REST::Channel.delete(@bot.token, @id, reason) end |
#delete_message(message) ⇒ Object
Deletes a message on this channel. Mostly useful in case a message needs to be deleted when only the ID is known
669 670 671 |
# File 'lib/onyxcord/models/channel.rb', line 669 def () REST::Channel.(@bot.token, @id, .resolve_id) end |
#delete_messages(messages, strict = false, reason = nil) ⇒ Integer
Deletes a collection of messages
870 871 872 873 874 875 |
# File 'lib/onyxcord/models/channel.rb', line 870 def (, strict = false, reason = nil) raise ArgumentError, 'Can only delete between 2 and 100 messages!' unless .count.between?(2, 100) .map!(&:resolve_id) bulk_delete(, strict, reason) end |
#delete_overwrite(target, reason = nil) ⇒ Object
Deletes a permission overwrite for this channel
752 753 754 755 756 |
# File 'lib/onyxcord/models/channel.rb', line 752 def delete_overwrite(target, reason = nil) raise 'Tried deleting a overwrite for an invalid target' unless target.respond_to?(:resolve_id) REST::Channel.(@bot.token, @id, target.resolve_id, reason) end |
#directory? ⇒ true, false
Returns whether or not this channel is a directory channel.
313 314 315 |
# File 'lib/onyxcord/models/channel.rb', line 313 def directory? @type == 14 end |
#follow(target, reason: nil) ⇒ Integer
Follow the announcement (news) channel to send crossposted messages to a target channel.
957 958 959 960 961 |
# File 'lib/onyxcord/models/channel.rb', line 957 def follow(target, reason: nil) raise 'Cannot follow a non-announcement channel' unless news? OnyxCord::Internal::JSON.parse(REST::Channel.follow_channel(@bot.token, @id, target.resolve_id, reason))['webhook_id'].to_i end |
#forum? ⇒ true, false
Returns whether or not this channel is a forum channel.
318 319 320 |
# File 'lib/onyxcord/models/channel.rb', line 318 def forum? @type == 15 end |
#group? ⇒ true, false
Returns whether or not this channel is a group channel.
268 269 270 |
# File 'lib/onyxcord/models/channel.rb', line 268 def group? @type == 3 end |
#history(amount, before_id = nil, after_id = nil, around_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
782 783 784 785 |
# File 'lib/onyxcord/models/channel.rb', line 782 def history(amount, before_id = nil, after_id = nil, around_id = nil) logs = REST::Channel.(@bot.token, @id, amount, before_id, after_id, around_id) OnyxCord::Internal::JSON.parse(logs).map { || Message.new(, @bot) } end |
#inspect ⇒ Object
The default inspect method is overwritten to give more useful output.
1217 1218 1219 |
# File 'lib/onyxcord/models/channel.rb', line 1217 def inspect "<Channel name=#{@name} id=#{@id} topic=\"#{@topic}\" type=#{@type} position=#{@position} server=#{@server || @server_id}>" end |
#invites ⇒ Array<Invite>
Requests a list of Invites to the channel.
946 947 948 949 950 951 |
# File 'lib/onyxcord/models/channel.rb', line 946 def invites raise 'Tried to request invites from a non-server channel' unless server invites = OnyxCord::Internal::JSON.parse(REST::Channel.invites(@bot.token, @id)) invites.map { |invite_data| Invite.new(invite_data, @bot) } end |
#join_thread ⇒ Object
Join this thread.
1099 1100 1101 |
# File 'lib/onyxcord/models/channel.rb', line 1099 def join_thread @bot.join_thread(@id) end |
#last_message ⇒ Message, ...
Returns the last message or forum post created in this channel.
966 967 968 969 970 971 972 973 974 |
# File 'lib/onyxcord/models/channel.rb', line 966 def return unless @last_message_id if forum? || media? @bot.channel(@last_message_id) else (@last_message_id) end end |
#leave_thread ⇒ Object
Leave this thread
1104 1105 1106 |
# File 'lib/onyxcord/models/channel.rb', line 1104 def leave_thread @bot.leave_thread(@id) end |
#link ⇒ String Also known as: jump_link
Returns a URL that a user can use to navigate to this channel in the client.
1296 1297 1298 |
# File 'lib/onyxcord/models/channel.rb', line 1296 def link "https://discord.com/channels/#{@server_id || '@me'}/#{@id}" end |
#load_message(message_id) ⇒ Message? Also known as: message
Returns a single message from this channel's history by ID.
798 799 800 801 802 803 804 805 |
# File 'lib/onyxcord/models/channel.rb', line 798 def () raise ArgumentError, 'message_id cannot be nil' if .nil? response = REST::Channel.(@bot.token, @id, ) Message.new(OnyxCord::Internal::JSON.parse(response), @bot) rescue OnyxCord::Errors::UnknownMessage nil end |
#make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Invite Also known as: invite
Creates a new invite to this channel.
906 907 908 909 |
# File 'lib/onyxcord/models/channel.rb', line 906 def make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) response = REST::Channel.create_invite(@bot.token, @id, max_age, max_uses, temporary, unique, reason) Invite.new(OnyxCord::Internal::JSON.parse(response), @bot) end |
#media? ⇒ true, false
Returns whether or not this channel is a media channel.
323 324 325 |
# File 'lib/onyxcord/models/channel.rb', line 323 def media? @type == 16 end |
#member_overwrites ⇒ Overwrite
Returns any member-type permission overwrites on this channel.
517 518 519 |
# File 'lib/onyxcord/models/channel.rb', line 517 def member_overwrites :member end |
#members ⇒ Object
Members in the thread.
1109 1110 1111 |
# File 'lib/onyxcord/models/channel.rb', line 1109 def members @bot.thread_members[@id].collect { |id| @server_id ? @bot.member(@server_id, id) : @bot.user(id) } end |
#mention ⇒ String
Returns a string that will mention the channel as a clickable link on Discord.
160 161 162 |
# File 'lib/onyxcord/models/channel.rb', line 160 def mention "<##{@id}>" end |
#modify(name: :undef, type: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent: :undef, voice_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, tags: :undef, default_reaction: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, locked: :undef, invitable: :undef, add_flags: :undef, remove_flags: :undef, position: :undef, auto_archive_duration: :undef, default_thread_rate_limit_per_user: :undef, reason: nil) ⇒ nil
Modify the properties of the channel.
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 |
# File 'lib/onyxcord/models/channel.rb', line 1154 def modify( name: :undef, type: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent: :undef, voice_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, tags: :undef, default_reaction: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, locked: :undef, invitable: :undef, add_flags: :undef, remove_flags: :undef, position: :undef, auto_archive_duration: :undef, default_thread_rate_limit_per_user: :undef, reason: nil ) data = { name: name, type: TYPES[type] || type, topic: topic, nsfw: nsfw, position: position, rate_limit_per_user: rate_limit_per_user, bitrate: bitrate, user_limit: user_limit, permission_overwrites: == :undef ? : &.map(&:to_hash), parent_id: parent == :undef ? parent : parent&.resolve_id, rtc_region: voice_region == :undef ? voice_region : voice_region&.to_s, video_quality_mode: VIDEO_QUALITY_MODES[video_quality_mode] || video_quality_mode, default_auto_archive_duration: default_auto_archive_duration, default_reaction_emoji: default_reaction == :undef ? default_reaction : Emoji.build_emoji_hash(default_reaction), default_sort_order: FORUM_SORT_ORDERS[default_sort_order] || default_sort_order, default_forum_layout: FORUM_LAYOUTS[default_forum_layout] || default_forum_layout, archived: archived, flags: flags == :undef ? flags : Array(flags).map { |bit| FLAGS[bit] || bit.to_i }.reduce(&:|), default_thread_rate_limit_per_user: default_thread_rate_limit_per_user, auto_archive_duration: auto_archive_duration, locked: locked, invitable: invitable } if != :undef && (thread_only? || thread?) = (thread? ? &.map(&:resolve_id) : &.map(&:to_h)) data[thread_only? ? :available_tags : :applied_tags] = end if data[:type] != :undef if news? && data[:type] != TYPES[:text] raise ArgumentError, 'Can only convert news channels to text channels' elsif text? && data[:type] != TYPES[:news] raise ArgumentError, 'Can only convert text channels to news channels' elsif !text? && !news? raise ArgumentError, 'Can only convert between text and news channels' end end if add_flags != :undef || remove_flags != :undef raise ArgumentError, "'add_flags' and 'remove_flags' cannot be used with 'flags'" if flags != :undef to_flags = lambda do |value| [*(value == :undef ? 0 : value)].map { |bit| FLAGS[bit] || bit.to_i }.reduce(&:|) end data[:flags] = ((@flags & ~to_flags.call(remove_flags)) | to_flags.call(add_flags)) end update_data(OnyxCord::Internal::JSON.parse(REST::Channel.update!(@bot.token, @id, **data, reason: reason))) nil end |
#news? ⇒ true, false
Returns whether or not this channel is a news channel.
278 279 280 |
# File 'lib/onyxcord/models/channel.rb', line 278 def news? @type == 5 end |
#news_thread? ⇒ true, false
Returns whether or not this channel is a news thread.
288 289 290 |
# File 'lib/onyxcord/models/channel.rb', line 288 def news_thread? @type == 10 end |
#nsfw=(nsfw) ⇒ Object
Sets whether this channel is NSFW
435 436 437 438 439 |
# File 'lib/onyxcord/models/channel.rb', line 435 def nsfw=(nsfw) raise ArgumentError, 'nsfw value must be true or false' unless nsfw.is_a?(TrueClass) || nsfw.is_a?(FalseClass) modify(nsfw: nsfw) end |
#nsfw? ⇒ true, false
Check if this channel is marked as NSFW.
420 421 422 |
# File 'lib/onyxcord/models/channel.rb', line 420 def nsfw? thread? ? (parent&.nsfw? || false) : @nsfw end |
#permission_overwrites ⇒ Hash<Integer => Overwrite> #permission_overwrites(type) ⇒ Array<Overwrite> Also known as: overwrites
This channel's permission overwrites
450 451 452 453 454 |
# File 'lib/onyxcord/models/channel.rb', line 450 def (type = nil) return @permission_overwrites unless type @permission_overwrites.values.select { |e| e.type == type } end |
#permission_overwrites=(overwrites) ⇒ Object
Bulk sets this channels permission overwrites
460 461 462 |
# File 'lib/onyxcord/models/channel.rb', line 460 def (overwrites) modify(permission_overwrites: overwrites) end |
#pins(limit: 50) ⇒ Array<Message>
Requests the pinned messages in a channel.
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
# File 'lib/onyxcord/models/channel.rb', line 812 def pins(limit: 50) get_pins = proc do |fetch_limit, before = nil| resp = REST::Channel.(@bot.token, @id, fetch_limit, before&.iso8601) OnyxCord::Internal::JSON.parse(resp)['items'].map { |pin| Message.new(pin['message'].merge({ 'pinned_at' => pin['pinned_at'] }), @bot) } end # Can be done without pagination. return get_pins.call(limit) if limit && limit <= 50 paginator = Paginator.new(limit, :down) do |last_page| if last_page && last_page.count < 50 [] else get_pins.call(50, last_page&.last&.pinned_at) end end paginator.to_a end |
#pm? ⇒ true, false
Returns whether or not this channel is a PM channel.
258 259 260 |
# File 'lib/onyxcord/models/channel.rb', line 258 def pm? @type == 1 end |
#private? ⇒ true, false
Returns whether or not this channel is a PM or group channel.
155 156 157 |
# File 'lib/onyxcord/models/channel.rb', line 155 def private? pm? || group? end |
#private_thread? ⇒ true, false
Returns whether or not this channel is a private thread.
298 299 300 |
# File 'lib/onyxcord/models/channel.rb', line 298 def private_thread? @type == 12 end |
#prune(amount, strict = false, reason = nil) {|message| ... } ⇒ Integer
Delete the last N messages on this channel.
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/onyxcord/models/channel.rb', line 842 def prune(amount, strict = false, reason = nil, &block) raise ArgumentError, 'Can only delete between 1 and 100 messages!' unless amount.between?(1, 100) = if block history(amount).select(&block).map(&:id) else history_ids(amount) end case .size when 0 0 when 1 REST::Channel.(@bot.token, @id, .first, reason) 1 else bulk_delete(, strict, reason) end end |
#public_thread? ⇒ true, false
Returns whether or not this channel is a public thread.
293 294 295 |
# File 'lib/onyxcord/models/channel.rb', line 293 def public_thread? @type == 11 end |
#recipient ⇒ Recipient?
Returns the recipient of the private messages, or nil if this is not a PM channel.
165 166 167 |
# File 'lib/onyxcord/models/channel.rb', line 165 def recipient @recipients.first if pm? end |
#remove_member(member) ⇒ Object
1120 1121 1122 |
# File 'lib/onyxcord/models/channel.rb', line 1120 def remove_member(member) @bot.remove_thread_member(@id, member) end |
#remove_tags(tags, reason: nil) ⇒ Object Also known as: remove_tag
Remove one or more tag from this thread channel.
1078 1079 1080 1081 1082 |
# File 'lib/onyxcord/models/channel.rb', line 1078 def (, reason: nil) raise 'Cannot remove tags from this channel' unless parent&.thread_only? modify(tags: @applied_tags - Array().map(&:resolve_id), reason: reason) end |
#role_overwrites ⇒ Overwrite
Returns any role-type permission overwrites on this channel.
522 523 524 |
# File 'lib/onyxcord/models/channel.rb', line 522 def role_overwrites :role end |
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) {|embed| ... } ⇒ Message
Convenience method to send a message with an embed.
585 586 587 588 589 590 591 592 |
# File 'lib/onyxcord/models/channel.rb', line 585 def ( = '', = nil, = nil, tts = false, allowed_mentions = nil, = nil, components = nil, flags = 0) ||= OnyxCord::Webhooks::Embed.new view = OnyxCord::Webhooks::View.new yield(, view) if block_given? (, tts, , , allowed_mentions, , components || view.to_a, flags) end |
#send_file(file, caption: nil, tts: false, filename: nil, spoiler: nil) ⇒ Object
Sends a file to this channel. If it is an image, it will be embedded.
663 664 665 |
# File 'lib/onyxcord/models/channel.rb', line 663 def send_file(file, caption: nil, tts: false, filename: nil, spoiler: nil) @bot.send_file(@id, file, caption: caption, tts: tts, filename: filename, spoiler: spoiler) end |
#send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Message Also known as: send
Sends a message to this channel.
548 549 550 |
# File 'lib/onyxcord/models/channel.rb', line 548 def (content, tts = false, = nil, = nil, allowed_mentions = nil, = nil, components = nil, flags = 0) @bot.(@id, content, tts, , , allowed_mentions, , components, flags) end |
#send_message!(content: '', timeout: nil, tts: false, embeds: [], attachments: nil, allowed_mentions: nil, reference: nil, components: nil, flags: 0, has_components: false, components_v2: false, nonce: nil, enforce_nonce: false, poll: nil) {|builder, view| ... } ⇒ Message?
Send a message to this channel.
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/onyxcord/models/channel.rb', line 618 def (content: '', timeout: nil, tts: false, embeds: [], attachments: nil, allowed_mentions: nil, reference: nil, components: nil, flags: 0, has_components: false, components_v2: false, nonce: nil, enforce_nonce: false, poll: nil) builder = OnyxCord::Webhooks::Builder.new view = OnyxCord::Webhooks::View.new builder.tts = tts builder.poll = poll builder.content = content &.each { || builder << } builder.allowed_mentions = allowed_mentions yield(builder, view) if block_given? components = components&.to_a || view.to_a flags = Array(flags).map { |flag| OnyxCord::Message::FLAGS[flag] || flag }.reduce(0, &:|) flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2) builder = builder.to_json_hash if timeout @bot.(@id, builder[:content], timeout, builder[:tts], builder[:embeds], , builder[:allowed_mentions], reference, components, flags, nonce, enforce_nonce, builder[:poll]) else @bot.(@id, builder[:content], builder[:tts], builder[:embeds], , builder[:allowed_mentions], reference, components, flags, nonce, enforce_nonce, builder[:poll]) end end |
#send_multiple(content) ⇒ Object
Sends multiple messages to a channel
644 645 646 |
# File 'lib/onyxcord/models/channel.rb', line 644 def send_multiple(content) content.each { |text| (content: text) } end |
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Object
Sends a temporary message to this channel.
564 565 566 |
# File 'lib/onyxcord/models/channel.rb', line 564 def (content, timeout, tts = false, = nil, = nil, allowed_mentions = nil, = nil, components = nil, flags = 0) @bot.(@id, content, timeout, tts, , , allowed_mentions, , components, flags) end |
#server ⇒ Server?
Returns the server this channel is on. If this channel is a PM channel, it will be nil.
242 243 244 245 246 247 248 249 250 |
# File 'lib/onyxcord/models/channel.rb', line 242 def server return @server if @server return nil if private? @server = @bot.server(@server_id) raise OnyxCord::Errors::NoPermission, 'The bot does not have access to this server' unless @server @server end |
#slowmode? ⇒ true, false
Returns whether or not this channel has slowmode enabled.
534 535 536 |
# File 'lib/onyxcord/models/channel.rb', line 534 def slowmode? @rate_limit_per_user != 0 end |
#sort_after(other = nil, lock_permissions = false) ⇒ Object
Sorts this channel's position to follow another channel.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/onyxcord/models/channel.rb', line 357 def sort_after(other = nil, = false) raise TypeError, 'other must be one of Channel, NilClass, String, or Integer' unless other.is_a?(Channel) || other.nil? || other.respond_to?(:resolve_id) other = @bot.channel(other.resolve_id) if other # Container for the API request payload move_argument = [] if other raise ArgumentError, 'Can only sort a channel after a channel of the same type!' unless other.category? || (@type == other.type) raise ArgumentError, 'Can only sort a channel after a channel in the same server!' unless other.server == server # Store `others` parent (or if `other` is a category itself) parent = if category? && other.category? # If we're sorting two categories, there is no new parent nil elsif other.category? # `other` is the category this channel will be moved into other else # `other`'s parent is the category this channel will be # moved into (if it exists) other.parent end end # Collect and sort the IDs within the context (category or not) that we # need to form our payload with ids = if parent parent.children else server.channels.reject(&:parent_id).select { |c| c.type == @type } end.sort_by(&:position).map(&:id) # Move our channel ID after the target ID by deleting it, # getting the index of `other`, and inserting it after. ids.delete(@id) if ids.include?(@id) index = other ? (ids.index { |c| c == other.id } || -1) + 1 : 0 ids.insert(index, @id) # Generate `move_argument`, making the positions in order from how # we have sorted them in the above logic ids.each_with_index do |id, pos| # These keys are present in each element hash = { id: id, position: pos } # Conditionally add `lock_permissions` and `parent_id` if we're # iterating past ourselves if id == @id hash[:lock_permissions] = true if hash[:parent_id] = parent.nil? ? nil : parent.id end # Add it to the stack move_argument << hash end REST::Server.update_channel_positions(@bot.token, @server_id, move_argument) end |
#split_send(content) ⇒ Object
Splits a message into chunks whose length is at most the Discord character limit, then sends them individually. Useful for sending long messages, but be wary of rate limits!
650 651 652 653 |
# File 'lib/onyxcord/models/channel.rb', line 650 def split_send(content) send_multiple(OnyxCord.(content)) nil end |
#stage? ⇒ true, false
Returns whether or not this channel is a stage channel.
308 309 310 |
# File 'lib/onyxcord/models/channel.rb', line 308 def stage? @type == 13 end |
#start_forum_thread(name:, auto_archive_duration: nil, rate_limit_per_user: nil, tags: nil, content: nil, embeds: nil, allowed_mentions: nil, components: nil, stickers: nil, attachments: nil, flags: nil, has_components: false, components_v2: false, reason: nil) {|builder, view| ... } ⇒ Message
Start a thread in a forum or media channel.
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
# File 'lib/onyxcord/models/channel.rb', line 1013 def start_forum_thread(name:, auto_archive_duration: nil, rate_limit_per_user: nil, tags: nil, content: nil, embeds: nil, allowed_mentions: nil, components: nil, stickers: nil, attachments: nil, flags: nil, has_components: false, components_v2: false, reason: nil) builder = OnyxCord::Webhooks::Builder.new view = OnyxCord::Webhooks::View.new builder.content = content &.each { || builder << } builder.allowed_mentions = allowed_mentions yield(builder, view) if block_given? components = components&.to_a || view.to_a flags = Array(flags).map { |flag| OnyxCord::Message::FLAGS[flag] || flag }.reduce(0, &:|) flags = OnyxCord::MessageComponents.apply_v2_flag(flags, components, force: has_components || components_v2) builder = builder.to_json_hash = { content: builder[:content], embeds: builder[:embeds], allowed_mentions: builder[:allowed_mentions], components: components, sticker_ids: stickers&.map(&:resolve_id), flags: flags } response = OnyxCord::Internal::JSON.parse(REST::Channel.start_thread_in_forum_or_media_channel(@bot.token, @id, name, .compact, , rate_limit_per_user, auto_archive_duration, &.map(&:resolve_id), reason)) Message.new(response['message'].merge!('channel_id' => response['id'], 'thread' => response), @bot) end |
#start_thread(name, auto_archive_duration, message: nil, type: 11) ⇒ Channel
Start a thread.
983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/onyxcord/models/channel.rb', line 983 def start_thread(name, auto_archive_duration, message: nil, type: 11) = &.id || type = TYPES[type] || type data = if REST::Channel.(@bot.token, @id, , name, auto_archive_duration) else REST::Channel.(@bot.token, @id, name, auto_archive_duration, type) end @bot.ensure_channel(OnyxCord::Internal::JSON.parse(data)) end |
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds. If you want to keep typing you'll have to resend this every five seconds. (An abstraction for this will eventually be coming)
918 919 920 |
# File 'lib/onyxcord/models/channel.rb', line 918 def start_typing REST::Channel.start_typing(@bot.token, @id) end |
#store? ⇒ true, false
Returns whether or not this channel is a store channel.
283 284 285 |
# File 'lib/onyxcord/models/channel.rb', line 283 def store? @type == 6 end |
#sync_overwrites ⇒ Object Also known as: sync
Syncs this channels overwrites with its parent category
477 478 479 480 481 |
# File 'lib/onyxcord/models/channel.rb', line 477 def sync_overwrites raise 'Cannot sync overwrites on a channel with no parent category' unless parent self. = parent. end |
#synchronized? ⇒ true, ... Also known as: synced?
Returns whether this channels permissions match the permission overwrites of the category that it's in, or nil if it is not in a category.
486 487 488 489 490 |
# File 'lib/onyxcord/models/channel.rb', line 486 def synchronized? return unless parent == parent. end |
#tag(id) ⇒ ChannelTag?
Get a tag in this forum or media channel.
1041 1042 1043 1044 |
# File 'lib/onyxcord/models/channel.rb', line 1041 def tag(id) id = id.resolve_id @available_tags.find { |t| t.id == id } end |
#tag?(id) ⇒ true, false
Check if a specific tag has been applied to this thread.
1049 1050 1051 |
# File 'lib/onyxcord/models/channel.rb', line 1049 def tag?(id) @applied_tags.any?(id&.resolve_id) end |
#tags ⇒ Array<ChannelTag>
Get the tags for this channel. If this channel is a thread channel, then the tags that have been applied to the thread will be returned, and if the channel is a forum or media channel, then the tags that can be applied onto threads created in this channel will be returned instead.
1058 1059 1060 1061 1062 1063 1064 |
# File 'lib/onyxcord/models/channel.rb', line 1058 def return @available_tags if thread_only? return @applied_tags.filter_map { |tag_id| parent&.tag(tag_id) } if thread? [] end |
#text? ⇒ true, false
Returns whether or not this channel is a text channel.
253 254 255 |
# File 'lib/onyxcord/models/channel.rb', line 253 def text? @type.zero? end |
#text_channels ⇒ Array<Channel>
Returns the text channels in this category, if it is a category channel. Otherwise returns an empty array.
506 507 508 |
# File 'lib/onyxcord/models/channel.rb', line 506 def text_channels children.select(&:text?) end |
#thread? ⇒ true, false
Returns whether or not this channel is a thread.
303 304 305 |
# File 'lib/onyxcord/models/channel.rb', line 303 def thread? news_thread? || public_thread? || private_thread? end |
#thread_only? ⇒ true, false
Check if this channel is a forum or media channel.
329 330 331 |
# File 'lib/onyxcord/models/channel.rb', line 329 def thread_only? forum? || media? end |
#users ⇒ Array<Member>
The list of users currently in this channel. For a voice channel, it will return all the members currently in that channel. For a text channel, it will return all online members that have permission to read it.
761 762 763 764 765 766 767 |
# File 'lib/onyxcord/models/channel.rb', line 761 def users if text? server.online_members(include_idle: true).select { |u| u. self } elsif voice? server.voice_states.filter_map { |id, voice_state| server.member(id) if !voice_state.voice_channel.nil? && voice_state.voice_channel.id == @id } end end |
#voice? ⇒ true, false
Returns whether or not this channel is a voice channel.
263 264 265 |
# File 'lib/onyxcord/models/channel.rb', line 263 def voice? @type == 2 end |
#voice_channels ⇒ Array<Channel>
Returns the voice channels in this category, if it is a category channel. Otherwise returns an empty array.
512 513 514 |
# File 'lib/onyxcord/models/channel.rb', line 512 def voice_channels children.select(&:voice?) end |
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the channel.
937 938 939 940 941 942 |
# File 'lib/onyxcord/models/channel.rb', line 937 def webhooks raise 'Tried to request webhooks from a non-server channel' unless server webhooks = OnyxCord::Internal::JSON.parse(REST::Channel.webhooks(@bot.token, @id)) webhooks.map { |webhook_data| Webhook.new(webhook_data, @bot) } end |