Skip to content

Commit

Permalink
Merge pull request #34 from Kirollos/develop
Browse files Browse the repository at this point in the history
Merge 2.0.2 Develop -> Main
  • Loading branch information
dassjosh authored Sep 15, 2021
2 parents 8825b69 + 44c5238 commit d04a405
Show file tree
Hide file tree
Showing 33 changed files with 2,758 additions and 1,105 deletions.
16 changes: 10 additions & 6 deletions Docs/Plugins/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ namespace Oxide.Plugins
["SavedSteamId"] = new Snowflake(12321321)
};
}

public void RegisterEvents(Action<IPlayer, DiscordUser> onLinked, Action<IPlayer, DiscordUser> onUnlinked)

//Method in your plugin should call _link.OnLinked whenever a player and discord are linked
public void OnLinked(IPlayer player, DiscordUser user)
{
_link.OnLinked(player, user);
}

//Method in your plugin should call _link.OnUnlinked whenever a player and discord are unlinked
public void OnUnlinked(IPlayer player, DiscordUser user)
{
//Saves these actions which are to be called when a user links or unlinks.
//Failure to call these will cause the DiscordLink data to become outdated.
_onLinked = onLinked;
_onUnlinked = onUnlinked;
_link.OnUnlinked(player, user);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Oxide.Ext.Discord/BotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ public void AddClient(DiscordClient client)
if (ReadyData != null)
{
ReadyData.Guilds = Servers.Copy();
client.CallHook(DiscordHooks.OnDiscordGatewayReady, ReadyData);
client.CallHook(DiscordExtHooks.OnDiscordGatewayReady, ReadyData);

foreach (DiscordGuild guild in Servers.Values)
{
if (guild.IsAvailable)
{
client.CallHook(DiscordHooks.OnDiscordGuildCreated, guild);
client.CallHook(DiscordExtHooks.OnDiscordGuildCreated, guild);
}

if (guild.HasLoadedAllMembers)
{
client.CallHook(DiscordHooks.OnDiscordGuildMembersLoaded, guild);
client.CallHook(DiscordExtHooks.OnDiscordGuildMembersLoaded, guild);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Oxide.Ext.Discord.Builders.ApplicationCommands
/// <summary>
/// Builder to use when building application commands
/// </summary>
public class ApplicationCommandBuilder
public class ApplicationCommandBuilder : IApplicationCommandBuilder
{
internal readonly CommandCreate Command;
private readonly List<CommandOption> _options;
Expand Down Expand Up @@ -83,9 +83,9 @@ public SubCommandGroupBuilder AddSubCommandGroup(string name, string description
/// </summary>
/// <param name="name">Name of the sub command</param>
/// <param name="description">Description for the sub command</param>
/// <returns><see cref="SubCommandBuilder{T}"/></returns>
/// <returns><see cref="SubCommandBuilder"/></returns>
/// <exception cref="Exception">Thrown if previous type was not SubCommand or Creation type is not ChatInput</exception>
public SubCommandBuilder<ApplicationCommandBuilder> AddSubCommand(string name, string description)
public SubCommandBuilder AddSubCommand(string name, string description)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Value cannot be null or empty.", nameof(name));
Expand All @@ -104,7 +104,7 @@ public SubCommandBuilder<ApplicationCommandBuilder> AddSubCommand(string name, s

_chosenType = CommandOptionType.SubCommand;

return new SubCommandBuilder<ApplicationCommandBuilder>(_options, name, description, this);
return new SubCommandBuilder(_options, name, description, this);
}

/// <summary>
Expand All @@ -113,15 +113,15 @@ public SubCommandBuilder<ApplicationCommandBuilder> AddSubCommand(string name, s
/// <param name="type">The type of option. Cannot be SubCommand or SubCommandGroup</param>
/// <param name="name">Name of the option</param>
/// <param name="description">Description for the option</param>
/// <returns><see cref="CommandOptionBuilder{T}"/></returns>
public CommandOptionBuilder<ApplicationCommandBuilder> AddOption(CommandOptionType type, string name, string description)
/// <returns><see cref="CommandOptionBuilder"/></returns>
public CommandOptionBuilder AddOption(CommandOptionType type, 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");
}

return new CommandOptionBuilder<ApplicationCommandBuilder>(_options, type, name, description, this);
return new CommandOptionBuilder(_options, type, name, description, this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System;
using System.Collections.Generic;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Interactions.ApplicationCommands;

namespace Oxide.Ext.Discord.Builders.ApplicationCommands
{
/// <summary>
/// Builder for command options
/// </summary>
/// <typeparam name="T">Type we're building options for.</typeparam>
public class CommandOptionBuilder<T>
public class CommandOptionBuilder : IApplicationCommandBuilder
{
private readonly CommandOption _option;
private readonly T _builder;
private readonly IApplicationCommandBuilder _builder;

internal CommandOptionBuilder(List<CommandOption> parent, CommandOptionType type, string name, string description, T builder)
internal CommandOptionBuilder(List<CommandOption> parent, CommandOptionType type, string name, string description, IApplicationCommandBuilder builder)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Value cannot be null or empty.", nameof(name));
Expand All @@ -40,11 +40,28 @@ internal CommandOptionBuilder(List<CommandOption> parent, CommandOptionType type
/// </summary>
/// <param name="required">If the option is required (Default: true)</param>
/// <returns>This</returns>
public CommandOptionBuilder<T> Required(bool required = true)
public CommandOptionBuilder Required(bool required = true)
{
_option.Required = required;
return this;
}

/// <summary>
/// Set's the channel types for the option
/// </summary>
/// <param name="types">Types of channels the option allows</param>
/// <returns>This</returns>
/// <exception cref="Exception">Thrown if <see cref="CommandOptionType"/> is not Channel</exception>
public CommandOptionBuilder SetChannelTypes(List<ChannelType> types)
{
if (_option.Type != CommandOptionType.Channel)
{
throw new Exception("Can only set ChannelTypes for CommandOptionType.Channel");
}

_option.ChannelTypes = types;
return this;
}

/// <summary>
/// Adds a choice to this option of type string
Expand All @@ -53,7 +70,7 @@ public CommandOptionBuilder<T> Required(bool required = true)
/// <param name="value">Value of the choice</param>
/// <returns>This</returns>
/// <exception cref="Exception">Thrown if option type is not string</exception>
public CommandOptionBuilder<T> AddChoice(string name, string value)
public CommandOptionBuilder AddChoice(string name, string value)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Value cannot be null or empty.", nameof(name));
Expand All @@ -76,7 +93,7 @@ public CommandOptionBuilder<T> AddChoice(string name, string value)
/// <param name="value">Value of the choice</param>
/// <returns>This</returns>
/// <exception cref="Exception">Thrown if option type is not int</exception>
public CommandOptionBuilder<T> AddChoice(string name, int value)
public CommandOptionBuilder AddChoice(string name, int value)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Value cannot be null or empty.", nameof(name));
Expand All @@ -96,7 +113,7 @@ public CommandOptionBuilder<T> AddChoice(string name, int value)
/// <param name="value">Value of the choice</param>
/// <returns>This</returns>
/// <exception cref="Exception">Thrown if option type is not double</exception>
public CommandOptionBuilder<T> AddChoice(string name, double value)
public CommandOptionBuilder AddChoice(string name, double value)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Value cannot be null or empty.", nameof(name));
Expand All @@ -109,7 +126,7 @@ public CommandOptionBuilder<T> AddChoice(string name, double value)
return AddChoice(name, (object)value);
}

private CommandOptionBuilder<T> AddChoice(string name, object value)
private CommandOptionBuilder AddChoice(string name, object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
Expand All @@ -131,12 +148,21 @@ private CommandOptionBuilder<T> AddChoice(string name, object value)
}

/// <summary>
/// Builds the option and returns the T previous builder
/// Builds the option for ApplicationCommandBuilder builder
/// </summary>
/// <returns></returns>
public ApplicationCommandBuilder BuildForApplicationCommand()
{
return (ApplicationCommandBuilder)_builder;
}

/// <summary>
/// Builds the option for ApplicationCommandBuilder builder
/// </summary>
/// <returns></returns>
public T Build()
public SubCommandBuilder BuildForSubCommand()
{
return _builder;
return (SubCommandBuilder)_builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Oxide.Ext.Discord.Builders.ApplicationCommands
{
/// <summary>
/// Represents a type that is an Application Command Builder
/// </summary>
public interface IApplicationCommandBuilder
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Oxide.Ext.Discord.Builders.ApplicationCommands
/// <summary>
/// Base Sub Command builder
/// </summary>
public class SubCommandBuilder<T>
public class SubCommandBuilder : IApplicationCommandBuilder
{
private readonly T _builder;
private readonly IApplicationCommandBuilder _builder;
/// <summary>
/// Options list to have options added to
/// </summary>
private readonly List<CommandOption> _options;

internal SubCommandBuilder(List<CommandOption> parent, string name, string description, T builder)
internal SubCommandBuilder(List<CommandOption> parent, string name, string description, IApplicationCommandBuilder builder)
{
_builder = builder;
_options = new List<CommandOption>();
Expand All @@ -35,18 +35,27 @@ internal SubCommandBuilder(List<CommandOption> parent, string name, string descr
/// <param name="description">Description of the option</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public CommandOptionBuilder<SubCommandBuilder<T>> AddOption(CommandOptionType type, string name, string description)
public CommandOptionBuilder AddOption(CommandOptionType type, string name, string description)
{
return new CommandOptionBuilder<SubCommandBuilder<T>>(_options, type, name, description, this);
return new CommandOptionBuilder(_options, type, name, description, this);
}

/// <summary>
/// Returns the built sub command
/// </summary>
/// <returns></returns>
public T Build()
public ApplicationCommandBuilder BuildForApplicationCommand()
{
return _builder;
return (ApplicationCommandBuilder)_builder;
}

/// <summary>
/// Returns the built sub command
/// </summary>
/// <returns></returns>
public SubCommandGroupBuilder BuildForSubCommandGroup()
{
return (SubCommandGroupBuilder)_builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Oxide.Ext.Discord.Builders.ApplicationCommands
/// <summary>
/// Builder for Sub Command Groups
/// </summary>
public class SubCommandGroupBuilder
public class SubCommandGroupBuilder : IApplicationCommandBuilder
{
private readonly CommandOption _option;

Expand All @@ -26,10 +26,10 @@ internal SubCommandGroupBuilder(string name, string description, ApplicationComm
/// </summary>
/// <param name="name">Name of the command</param>
/// <param name="description">Description of the command</param>
/// <returns><see cref="SubCommandBuilder{T}"/></returns>
public SubCommandBuilder<SubCommandGroupBuilder> AddSubCommand(string name, string description)
/// <returns><see cref="SubCommandBuilder"/></returns>
public SubCommandBuilder AddSubCommand(string name, string description)
{
return new SubCommandBuilder<SubCommandGroupBuilder>(_option.Options, name, description, this);
return new SubCommandBuilder(_option.Options, name, description, this);
}
}
}
Loading

0 comments on commit d04a405

Please sign in to comment.