Skip to content

Commit

Permalink
Merge pull request #337 from MazeXP/feature/polls
Browse files Browse the repository at this point in the history
Implement polls
  • Loading branch information
Nihlus authored May 17, 2024
2 parents 87adfc5 + 33194d1 commit d3f21d4
Show file tree
Hide file tree
Showing 74 changed files with 2,063 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,19 @@ public enum GatewayIntents
/// Subscribes to the following events:
/// - AUTO_MODERATION_ACTION_EXECUTION
/// </summary>
AutoModerationExecution = 1 << 21
AutoModerationExecution = 1 << 21,

/// <summary>
/// Subscribes to the following events:
/// - MESSAGE_POLL_VOTE_ADD
/// - MESSAGE_POLL_VOTE_REMOVE
/// </summary>
GuildMessagePolls = 1 << 24,

/// <summary>
/// Subscribes to the following events:
/// - MESSAGE_POLL_VOTE_ADD
/// - MESSAGE_POLL_VOTE_REMOVE
/// </summary>
DirectMessagePolls = 1 << 25,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// IMessagePollVoteAdd.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents the addition of a vote to a poll.
/// </summary>
/// <remarks>If the poll allows multiple selections, then one event will be sent per answer.</remarks>
[PublicAPI]
public interface IMessagePollVoteAdd : IGatewayEvent
{
/// <summary>
/// Gets the ID of the user.
/// </summary>
Snowflake UserID { get; }

/// <summary>
/// Gets the ID of the channel.
/// </summary>
Snowflake ChannelID { get; }

/// <summary>
/// Gets the ID of the message.
/// </summary>
Snowflake MessageID { get; }

/// <summary>
/// Gets the ID of the guild.
/// </summary>
Optional<Snowflake> GuildID { get; }

/// <summary>
/// Gets the ID of the answer.
/// </summary>
int AnswerID { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// IMessagePollVoteRemove.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents the removal of a vote to a poll.
/// </summary>
/// <remarks>If the poll allows multiple selections, then one event will be sent per answer.</remarks>
[PublicAPI]
public interface IMessagePollVoteRemove : IGatewayEvent
{
/// <summary>
/// Gets the ID of the user.
/// </summary>
Snowflake UserID { get; }

/// <summary>
/// Gets the ID of the channel.
/// </summary>
Snowflake ChannelID { get; }

/// <summary>
/// Gets the ID of the message.
/// </summary>
Snowflake MessageID { get; }

/// <summary>
/// Gets the ID of the guild.
/// </summary>
Optional<Snowflake> GuildID { get; }

/// <summary>
/// Gets the ID of the answer.
/// </summary>
int AnswerID { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public interface IMessage : IPartialMessage
/// </summary>
new Optional<OneOf<IApplicationCommandInteractionMetadata, IMessageComponentInteractionMetadata, IModalSubmitInteractionMetadata>> InteractionMetadata { get; }

/// <summary>
/// Gets the poll sent with the message, if any.
/// </summary>
new Optional<IPoll> Poll { get; }

/// <inheritdoc/>
Optional<Snowflake> IPartialMessage.ID => this.ID;

Expand Down Expand Up @@ -291,4 +296,7 @@ public interface IMessage : IPartialMessage

/// <inheritdoc/>
Optional<OneOf<IApplicationCommandInteractionMetadata, IMessageComponentInteractionMetadata, IModalSubmitInteractionMetadata>> IPartialMessage.InteractionMetadata => this.InteractionMetadata;

/// <inheritdoc/>
Optional<IPoll> IPartialMessage.Poll => this.Poll;
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ public interface IPartialMessage

/// <inheritdoc cref="IMessage.InteractionMetadata"/>
Optional<OneOf<IApplicationCommandInteractionMetadata, IMessageComponentInteractionMetadata, IModalSubmitInteractionMetadata>> InteractionMetadata { get; }

/// <inheritdoc cref="IMessage.Poll"/>
Optional<IPoll> Poll { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,10 @@ public enum DiscordPermission
/// <summary>
/// Allows for sending voice messages.
/// </summary>
SendVoiceMessages = 46
SendVoiceMessages = 46,

/// <summary>
/// Allows for sending polls.
/// </summary>
SendPolls = 49,
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@ public enum DiscordStagePermission
UseExternalStickers = DiscordPermission.UseExternalStickers,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
SendVoiceMessages = DiscordPermission.SendVoiceMessages,

/// <inheritdoc cref="DiscordPermission.SendPolls"/>
SendPolls = DiscordPermission.SendPolls,
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@ public enum DiscordTextPermission
SendMessagesInThreads = DiscordPermission.SendMessagesInThreads,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
SendVoiceMessages = DiscordPermission.SendVoiceMessages,

/// <inheritdoc cref="DiscordPermission.SendPolls"/>
SendPolls = DiscordPermission.SendPolls,
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,8 @@ public enum DiscordVoicePermission
UseExternalSounds = DiscordPermission.UseExternalSounds,

/// <inheritdoc cref="DiscordPermission.SendVoiceMessages"/>
SendVoiceMessages = DiscordPermission.SendVoiceMessages
SendVoiceMessages = DiscordPermission.SendVoiceMessages,

/// <inheritdoc cref="DiscordPermission.SendPolls"/>
SendPolls = DiscordPermission.SendPolls,
}
65 changes: 65 additions & 0 deletions Backend/Remora.Discord.API.Abstractions/API/Objects/Polls/IPoll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// IPoll.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents a poll.
/// </summary>
[PublicAPI]
public interface IPoll
{
/// <summary>
/// Gets the question of the poll.
/// </summary>
IPollMedia Question { get; }

/// <summary>
/// Gets a list of each available answer in the poll.
/// </summary>
IReadOnlyList<IPollAnswer> Answers { get; }

/// <summary>
/// Gets the time when the poll ends.
/// </summary>
DateTimeOffset? Expiry { get; }

/// <summary>
/// Gets a value indicating whether a user can select multiple answers.
/// </summary>
bool IsMultiselectAllowed { get; }

/// <summary>
/// Gets the layout type of the poll.
/// </summary>
PollLayoutType LayoutType { get; }

/// <summary>
/// Gets the results of the poll.
/// </summary>
Optional<IPollResults> Results { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// IPollAnswer.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents a poll answer.
/// </summary>
[PublicAPI]
public interface IPollAnswer
{
/// <summary>
/// Gets the ID of the answer.
/// </summary>
Optional<int> AnswerID { get; }

/// <summary>
/// Gets the data of the answer.
/// </summary>
IPollMedia PollMedia { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// IPollAnswerCount.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents a count for a poll answer.
/// </summary>
[PublicAPI]
public interface IPollAnswerCount
{
/// <summary>
/// Gets the ID of the answer.
/// </summary>
int ID { get; }

/// <summary>
/// Gets the number of votes for this answer.
/// </summary>
int Count { get; }

/// <summary>
/// Gets a value indicating Whether the current user has voted for this answer.
/// </summary>
bool HasCurrentUserVoted { get; }
}
Loading

0 comments on commit d3f21d4

Please sign in to comment.