diff --git a/DisCatSharp/Entities/Stage/DiscordStageEvent.cs b/DisCatSharp/Entities/Stage/DiscordStageEvent.cs new file mode 100644 index 000000000..92a63d898 --- /dev/null +++ b/DisCatSharp/Entities/Stage/DiscordStageEvent.cs @@ -0,0 +1,174 @@ +// This file is part of the DisCatSharp project. +// +// Copyright (c) 2021 AITSYS +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace DisCatSharp.Entities +{ + /// + /// Represents a Stage Event. + /// + public class DiscordStageEvent : SnowflakeObject, IEquatable + { + /// + /// Gets id of the associated Stage Channel. + /// + [JsonIgnore] + public DiscordChannel Stage + => this.Discord.Channels.TryGetValue(this.ChannelId, out var guild) ? guild : null; + + /// + /// Gets id of the associated Stage Channel id. + /// + [JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)] + public ulong ChannelId { get; internal set; } + + /// + /// Gets the name of the Stage Event. + /// + [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] + public string Name { get; internal set; } + + /// + /// Gets the description of the Stage Event. + /// + [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] + public string Description { get; internal set; } + + /// + /// Gets the entity type of the Stage Event. + /// Research. + /// + [JsonProperty("entity_type", NullValueHandling = NullValueHandling.Ignore)] + public int? EntityType { get; internal set; } + + /// + /// Gets the scheduled start time of the Stage Event. + /// + [JsonIgnore] + public DateTimeOffset? ScheduledStartTime + => !string.IsNullOrWhiteSpace(this.ScheduledStartTimeRaw) && DateTimeOffset.TryParse(this.ScheduledStartTimeRaw, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dto) ? + dto : null; + + /// + /// Gets the scheduled start time of the Stage Event as raw string. + /// + [JsonProperty("scheduled_start_time", NullValueHandling = NullValueHandling.Ignore)] + internal string ScheduledStartTimeRaw { get; set; } + + /// + /// Gets the topic of the Stage Event. + /// + [JsonProperty("privacy_level", NullValueHandling = NullValueHandling.Ignore)] + public StagePrivacyLevel PrivacyLevel { get; internal set; } + + internal DiscordStageEvent() { } + + #region Methods + + /// + /// Creates a Stage Event. + /// + /// Topic of the stage instance. + /// Privacy Level of the stage instance. + /// Audit log reason + /// Thrown when the client does not have the permission. + /// Thrown when the stage channel does not exist. + /// Thrown when an invalid parameter was provided. + /// Thrown when Discord is unable to process the request. + /*public async Task CreateAsync(Optional topic, Optional privacy_level, string reason = null) + => await this.Discord.ApiClient.CreateStageEventAsync(this.Id, topic, privacy_level, reason);*/ + + /// + /// Updates a Stage Event. + /// + /// Topic of the stage instance. + /// Privacy Level of the stage instance. + /// Audit log reason + /// Thrown when the client does not have the permission. + /// Thrown when the event does not exist. + /// Thrown when an invalid parameter was provided. + /// Thrown when Discord is unable to process the request. + /**/public async Task ModifyAsync(Optional topic, Optional privacy_level, string reason = null) + => await this.Discord.ApiClient.ModifyStageEventAsync(this.Id, topic, privacy_level, reason);*/ + + /// + /// Deletes a Stage Event. + /// + /// Audit log reason + /// Thrown when the client does not have the permission. + /// Thrown when the event does not exist. + /// Thrown when an invalid parameter was provided. + /// Thrown when Discord is unable to process the request. + /*public async Task DeleteAsync(string reason = null) + => await this.Discord.ApiClient.DeleteStageEventAsync(this.Id, reason);*/ + + #endregion + + /// + /// Checks whether this is equal to another object. + /// + /// Object to compare to. + /// Whether the object is equal to this . + public override bool Equals(object obj) + => this.Equals(obj as DiscordStageEvent); + + /// + /// Checks whether this is equal to another . + /// + /// to compare to. + /// Whether the is equal to this . + public bool Equals(DiscordStageEvent e) + => e is not null && (ReferenceEquals(this, e) || this.Id == e.Id); + + /// + /// Gets the hash code for this . + /// + /// The hash code for this . + public override int GetHashCode() => this.Id.GetHashCode(); + + /// + /// Gets whether the two objects are equal. + /// + /// First channel to compare. + /// Second channel to compare. + /// Whether the two channels are equal. + public static bool operator ==(DiscordStageEvent e1, DiscordStageEvent e2) + { + var o1 = e1 as object; + var o2 = e2 as object; + + return (o1 != null || o2 == null) && (o1 == null || o2 != null) && ((o1 == null && o2 == null) || e1.Id == e2.Id); + } + + /// + /// Gets whether the two objects are not equal. + /// + /// First channel to compare. + /// Second channel to compare. + /// Whether the two channels are not equal. + public static bool operator !=(DiscordStageEvent e1, DiscordStageEvent e2) + => !(e1 == e2); + } +}