Skip to content

Commit

Permalink
Merge pull request #40 from Kirollos/develop
Browse files Browse the repository at this point in the history
Merge 2.1.1 -> Main
  • Loading branch information
dassjosh authored Jan 26, 2022
2 parents 2538510 + 52ceb60 commit c1bd7b8
Show file tree
Hide file tree
Showing 52 changed files with 902 additions and 188 deletions.
7 changes: 1 addition & 6 deletions Oxide.Ext.Discord/BotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ public class BotClient
/// If the connection is initialized and not disconnected
/// </summary>
public bool Initialized { get; private set; }

/// <summary>
/// If the bot has successfully connected to the websocket at least once
/// </summary>
public bool ConnectedSuccessfully { get; internal set; }


/// <summary>
/// Application reference for this bot
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Oxide.Ext.Discord.Entities.Interactions.ApplicationCommands;
using Oxide.Ext.Discord.Exceptions;

namespace Oxide.Ext.Discord.Builders.ApplicationCommands
{
Expand Down Expand Up @@ -65,12 +66,12 @@ public SubCommandGroupBuilder AddSubCommandGroup(string name, string description

if (_chosenType.HasValue && _chosenType.Value != CommandOptionType.SubCommandGroup && _chosenType.Value != CommandOptionType.SubCommand)
{
throw new Exception("Cannot mix sub command / sub command groups with command options");
throw new InvalidApplicationCommandException("Cannot mix sub command / sub command groups with command options");
}

if (Command.Type == ApplicationCommandType.Message || Command.Type == ApplicationCommandType.User)
{
throw new Exception("Message and User commands cannot have sub command groups");
throw new InvalidApplicationCommandException("Message and User commands cannot have sub command groups");
}

_chosenType = CommandOptionType.SubCommandGroup;
Expand All @@ -94,12 +95,12 @@ public SubCommandBuilder AddSubCommand(string name, string description)

if (_chosenType.HasValue && _chosenType.Value != CommandOptionType.SubCommandGroup && _chosenType.Value != CommandOptionType.SubCommand)
{
throw new Exception("Cannot mix sub command / sub command groups with command options");
throw new InvalidApplicationCommandException("Cannot mix sub command / sub command groups with command options");
}

if (Command.Type == ApplicationCommandType.Message || Command.Type == ApplicationCommandType.User)
{
throw new Exception("Message and User commands cannot have sub commands");
throw new InvalidApplicationCommandException("Message and User commands cannot have sub commands");
}

_chosenType = CommandOptionType.SubCommand;
Expand All @@ -118,7 +119,7 @@ public CommandOptionBuilder AddOption(CommandOptionType type, string name, strin
{
if (_chosenType.HasValue && (_chosenType.Value == CommandOptionType.SubCommandGroup || _chosenType.Value == CommandOptionType.SubCommand))
{
throw new Exception("Cannot mix sub command / sub command groups with command options");
throw new InvalidApplicationCommandException("Cannot mix sub command / sub command groups with command options");
}

return new CommandOptionBuilder(_options, type, name, description, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Interactions.ApplicationCommands;
using Oxide.Ext.Discord.Exceptions;

namespace Oxide.Ext.Discord.Builders.ApplicationCommands
{
Expand All @@ -22,7 +23,7 @@ internal CommandOptionBuilder(List<CommandOption> parent, CommandOptionType type

if (type == CommandOptionType.SubCommand || type == CommandOptionType.SubCommandGroup)
{
throw new Exception($"{type} is not allowed to be used here. Valid types are any non command type.");
throw new InvalidApplicationCommandException($"{type} is not allowed to be used here. Valid types are any non command type.");
}

_option = new CommandOption
Expand Down Expand Up @@ -66,7 +67,7 @@ public CommandOptionBuilder SetMinValue(int minValue)
{
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
{
throw new Exception("Can only set min value for Integer or Number Type");
throw new InvalidApplicationCommandException("Can only set min value for Integer or Number Type");
}

_option.MinValue = minValue;
Expand All @@ -82,7 +83,7 @@ public CommandOptionBuilder SetMinValue(double minValue)
{
if (_option.Type != CommandOptionType.Number)
{
throw new Exception("Can only set min value for Number Type");
throw new InvalidApplicationCommandException("Can only set min value for Number Type");
}

_option.MinValue = minValue;
Expand All @@ -98,7 +99,7 @@ public CommandOptionBuilder SetMaxValue(int maxValue)
{
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
{
throw new Exception("Can only set max value for Integer or Number Type");
throw new InvalidApplicationCommandException("Can only set max value for Integer or Number Type");
}

_option.MaxValue = maxValue;
Expand All @@ -114,7 +115,7 @@ public CommandOptionBuilder SetMaxValue(double maxValue)
{
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
{
throw new Exception("Can only set max value for Number Type");
throw new InvalidApplicationCommandException("Can only set max value for Number Type");
}

_option.MaxValue = maxValue;
Expand All @@ -131,7 +132,7 @@ public CommandOptionBuilder SetChannelTypes(List<ChannelType> types)
{
if (_option.Type != CommandOptionType.Channel)
{
throw new Exception("Can only set ChannelTypes for CommandOptionType.Channel");
throw new InvalidApplicationCommandException("Can only set ChannelTypes for CommandOptionType.Channel");
}

_option.ChannelTypes = types;
Expand All @@ -154,7 +155,7 @@ public CommandOptionBuilder AddChoice(string name, string value)

if (_option.Type != CommandOptionType.String)
{
throw new Exception($"Cannot add a string choice to non string type: {_option.Type}");
throw new InvalidApplicationCommandException($"Cannot add a string choice to non string type: {_option.Type}");
}

return AddChoice(name, (object)value);
Expand All @@ -175,7 +176,7 @@ public CommandOptionBuilder AddChoice(string name, int value)

if (_option.Type != CommandOptionType.Integer)
{
throw new Exception($"Cannot add a integer choice to non integer type: {_option.Type}");
throw new InvalidApplicationCommandException($"Cannot add a integer choice to non integer type: {_option.Type}");
}

return AddChoice(name, (object)value);
Expand All @@ -195,7 +196,7 @@ public CommandOptionBuilder AddChoice(string name, double value)

if (_option.Type != CommandOptionType.Number)
{
throw new Exception($"Cannot add a number choice to non number type: {_option.Type}");
throw new InvalidApplicationCommandException($"Cannot add a number choice to non number type: {_option.Type}");
}

return AddChoice(name, (object)value);
Expand Down
21 changes: 11 additions & 10 deletions Oxide.Ext.Discord/Builders/DiscordEmbedBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using Oxide.Ext.Discord.Entities.Messages.Embeds;
using Oxide.Ext.Discord.Entities.Permissions;
using Oxide.Ext.Discord.Exceptions;

namespace Oxide.Ext.Discord.Builders
{
Expand All @@ -22,7 +23,7 @@ public DiscordEmbedBuilder AddTitle(string title)
{
if (title != null && title.Length > 256)
{
throw new Exception("Title cannot be more than 256 characters");
throw new InvalidEmbedException("Title cannot be more than 256 characters");
}

_embed.Title = title;
Expand All @@ -39,7 +40,7 @@ public DiscordEmbedBuilder AddDescription(string description)
if (description == null) throw new ArgumentNullException(nameof(description));
if (description.Length > 4096)
{
throw new Exception("Description cannot be more than 4096 characters");
throw new InvalidEmbedException("Description cannot be more than 4096 characters");
}

_embed.Description = description;
Expand Down Expand Up @@ -70,7 +71,7 @@ public DiscordEmbedBuilder AddAuthor(string name, string iconUrl = null, string
if (name == null) throw new ArgumentNullException(nameof(name));
if (name.Length > 256)
{
throw new Exception("Author name cannot be more than 256 characters");
throw new InvalidEmbedException("Author name cannot be more than 256 characters");
}

_embed.Author = new EmbedAuthor(name, iconUrl, url, proxyIconUrl);
Expand All @@ -89,7 +90,7 @@ public DiscordEmbedBuilder AddFooter(string text, string iconUrl = null, string
if (text == null) throw new ArgumentNullException(nameof(text));
if (text.Length > 2048)
{
throw new Exception("Author name cannot be more than 2048 characters");
throw new InvalidEmbedException("Footer text cannot be more than 2048 characters");
}

_embed.Footer = new EmbedFooter(text, iconUrl, proxyIconUrl);
Expand Down Expand Up @@ -222,7 +223,7 @@ public DiscordEmbedBuilder AddBlankField(bool inline)

if ( _embed.Fields.Count >= 25)
{
throw new Exception("Embeds cannot have more than 25 fields");
throw new InvalidEmbedException("Embeds cannot have more than 25 fields");
}

_embed.Fields.Add(new EmbedField("\u200b", "\u200b", inline));
Expand All @@ -246,27 +247,27 @@ public DiscordEmbedBuilder AddField(string name, string value, bool inline)

if (_embed.Fields.Count >= 25)
{
throw new Exception("Embeds cannot have more than 25 fields");
throw new InvalidEmbedException("Embeds cannot have more than 25 fields");
}

if (string.IsNullOrEmpty(name))
{
throw new Exception("Embed Fields cannot have a null or empty name");
throw new InvalidEmbedException("Embed Fields cannot have a null or empty name");
}

if (string.IsNullOrEmpty(value))
{
throw new Exception("Embed Fields cannot have a null or empty value");
throw new InvalidEmbedException("Embed Fields cannot have a null or empty value");
}

if (name.Length > 256)
{
throw new Exception("Field name cannot be more than 256 characters");
throw new InvalidEmbedException("Field name cannot be more than 256 characters");
}

if (value.Length > 1024)
{
throw new Exception("Field value cannot be more than 1024 characters");
throw new InvalidEmbedException("Field value cannot be more than 1024 characters");
}

_embed.Fields.Add(new EmbedField(name, value, inline));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Oxide.Ext.Discord.Entities.Emojis;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Exceptions;
namespace Oxide.Ext.Discord.Builders.MessageComponents
{
/// <summary>
Expand Down Expand Up @@ -37,7 +38,7 @@ public MessageComponentBuilder AddActionButton(ButtonStyle style, string label,
{
if (style == ButtonStyle.Link)
{
throw new Exception($"Cannot add link button as action button. Please use {nameof(AddLinkButton)} instead");
throw new InvalidMessageComponentException($"Cannot add link button as action button. Please use {nameof(AddLinkButton)} instead");
}

UpdateActionRow<ButtonComponent>();
Expand Down Expand Up @@ -123,11 +124,13 @@ public SelectMenuComponentBuilder AddSelectMenu(string customId, string placehol
/// <param name="customId">Unique ID for the select menu</param>
/// <param name="label">Label for the input text</param>
/// <param name="style">Style of the Input Text</param>
/// <param name="value">Default value for the Input Text</param>
/// <param name="required">Is the Input Text Required to be filled out</param>
/// <param name="placeholder">Text to display if no value is selected yet</param>
/// <param name="minValues">The min number of options you must select</param>
/// <param name="maxValues">The max number of options you can select</param>
/// <param name="minLength">The min number of options you must select</param>
/// <param name="maxLength">The max number of options you can select</param>
/// <returns><see cref="MessageComponentBuilder"/></returns>
public MessageComponentBuilder AddInputText(string customId, string label, InputTextStyles style, string placeholder = null, int minValues = 1, int maxValues = 1)
public MessageComponentBuilder AddInputText(string customId, string label, InputTextStyles style, string value = null, bool? required = null, string placeholder = null, int? minLength = null, int? maxLength = null)
{
if (string.IsNullOrEmpty(customId))
throw new ArgumentException("Value cannot be null or empty.", nameof(customId));
Expand All @@ -138,9 +141,11 @@ public MessageComponentBuilder AddInputText(string customId, string label, Input
CustomId = customId,
Label = label,
Style = style,
Value = value,
Required = required,
Placeholder = placeholder,
MinLength = minValues,
MaxLength = maxValues,
MinLength = minLength,
MaxLength = maxLength,
};
_current.Components.Add(menu);
return this;
Expand All @@ -162,7 +167,7 @@ private void UpdateActionRow<T>() where T : BaseComponent
//Max of 5 action rows allowed
if (_components.Count >= 5)
{
throw new Exception("Cannot have more than 5 action rows");
throw new InvalidMessageComponentException("Cannot have more than 5 action rows");
}

//All other components are only 1 per action row so add a new row.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Oxide.Ext.Discord.Entities.Emojis;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Exceptions;

namespace Oxide.Ext.Discord.Builders.MessageComponents
{
/// <summary>
Expand Down Expand Up @@ -35,7 +37,7 @@ public SelectMenuComponentBuilder AddOption(string label, string value, string d

if (_menu.Options.Count >= 25)
{
throw new Exception("Select Menu Options cannot have more than 25 options");
throw new InvalidMessageComponentException("Select Menu Options cannot have more than 25 options");
}

_menu.Options.Add(new SelectMenuOption
Expand Down
2 changes: 1 addition & 1 deletion Oxide.Ext.Discord/DiscordExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DiscordExtension : Extension
/// <summary>
/// Version number of the extension
/// </summary>
private static readonly VersionNumber ExtensionVersion = new VersionNumber(2, 1, 0);
private static readonly VersionNumber ExtensionVersion = new VersionNumber(2, 1, 1);

/// <summary>
/// Global logger for areas that aren't part of a client connection
Expand Down
Loading

0 comments on commit c1bd7b8

Please sign in to comment.