forked from discord-net/Discord.Net
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit dca41a348e36a9b4e7006ef3a76377eb32aad276 Author: quin lynch <[email protected]> Date: Thu Sep 23 07:02:19 2021 -0300 Autocomplete commands
- Loading branch information
Showing
20 changed files
with
681 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Represents an autocomplete option. | ||
/// </summary> | ||
public class AutocompleteOption | ||
{ | ||
/// <summary> | ||
/// Gets the type of this option | ||
/// </summary> | ||
public ApplicationCommandOptionType Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the option. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the value of the option. | ||
/// </summary> | ||
public object Value { get; } | ||
|
||
/// <summary> | ||
/// Gets whether or not this option is focused by the executing user. | ||
/// </summary> | ||
public bool Focused { get; } | ||
|
||
internal AutocompleteOption(ApplicationCommandOptionType type, string name, object value, bool focused) | ||
{ | ||
this.Type = type; | ||
this.Name = name; | ||
this.Value = value; | ||
this.Focused = focused; | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Represents a result to an autocomplete interaction. | ||
/// </summary> | ||
public class AutocompleteResult | ||
{ | ||
private object _value { get; set; } | ||
private string _name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the result. | ||
/// </summary> | ||
/// <remarks> | ||
/// Name cannot be null and has to be between 1-100 characters in length. | ||
/// </remarks> | ||
/// <exception cref="ArgumentNullException"/> | ||
/// <exception cref="ArgumentException"/> | ||
public string Name | ||
{ | ||
get => _name; | ||
set | ||
{ | ||
if (value == null) | ||
throw new ArgumentException("Name cannot be null!"); | ||
if (value.Length > 100) | ||
throw new ArgumentException("Name length must be less than or equal to 100 characters in length!"); | ||
if (value.Length < 1) | ||
throw new ArgumentException("Name length must at least 1 character in length!"); | ||
_name = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the value of the result. | ||
/// </summary> | ||
/// <remarks> | ||
/// Only <see cref="string"/>, <see cref="int"/>, and <see cref="double"/> are allowed for a value. | ||
/// </remarks> | ||
/// <exception cref="ArgumentNullException"/> | ||
/// <exception cref="ArgumentException"/> | ||
public object Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
if (value == null) | ||
throw new ArgumentNullException("Value cannot be null"); | ||
|
||
switch (value) | ||
{ | ||
case string str: | ||
_value = str; | ||
break; | ||
case int integer: | ||
_value = integer; | ||
break; | ||
case double number: | ||
_value = number; | ||
break; | ||
|
||
default: | ||
throw new ArgumentException($"Type {value.GetType().Name} cannot be set as a value! Only string, int, and double allowed!"); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="AutocompleteResult"/>. | ||
/// </summary> | ||
public AutocompleteResult() { } | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="AutocompleteResult"/> with the passed in <paramref name="name"/> and <paramref name="value"/>. | ||
/// </summary> | ||
/// <exception cref="ArgumentNullException"/> | ||
/// <exception cref="ArgumentException"/> | ||
public AutocompleteResult(string name, object value) | ||
{ | ||
this.Name = name; | ||
this.Value = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AutocompleteInteractionData : IDiscordInteractionData | ||
{ | ||
[JsonProperty("id")] | ||
public ulong Id { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("type")] | ||
public ApplicationCommandType Type { get; set; } | ||
|
||
[JsonProperty("version")] | ||
public ulong Version { get; set; } | ||
|
||
[JsonProperty("options")] | ||
public AutocompleteInteractionDataOption[] Options { get; set; } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AutocompleteInteractionDataOption | ||
{ | ||
[JsonProperty("type")] | ||
public ApplicationCommandOptionType Type { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("value")] | ||
public object Value { get; set; } | ||
|
||
[JsonProperty("focused")] | ||
public bool Focused { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.