Skip to content

Commit

Permalink
Merge pull request #38 from Kirollos/develop
Browse files Browse the repository at this point in the history
Merge 2.1.0 -> Main
  • Loading branch information
dassjosh authored Jan 5, 2022
2 parents d04a405 + e08d9f1 commit 2538510
Show file tree
Hide file tree
Showing 78 changed files with 3,438 additions and 423 deletions.
6 changes: 6 additions & 0 deletions Docs/GatewayIntents.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ This is a list of all intents and which hooks become available when using a spec
* Direct Message Typing (`GatewayIntents.DirectMessageTyping`)
* [OnDiscordDirectTypingStarted](Hooks.md#ondiscorddirecttypingstarted)

* Guild Scheduled Events (`GatewayIntents.GuildScheduledEvents`)
* [OnDiscordGuildScheduledEventCreated](Hooks.md#OnDiscordGuildScheduledEventCreated)
* [OnDiscordGuildScheduledEventUpdated](Hooks.md#OnDiscordGuildScheduledEventUpdated)
* [OnDiscordGuildScheduledEventDeleted](Hooks.md#OnDiscordGuildScheduledEventDeleted)
* [OnDiscordGuildScheduledEventUserAdded](Hooks.md#OnDiscordGuildScheduledEventUserAdded)
* [OnDiscordGuildScheduledEventUserRemoved](Hooks.md#OnDiscordGuildScheduledEventUserRemoved)

## Building Intents
You can build your intents in the following manner
Expand Down
64 changes: 62 additions & 2 deletions Docs/Hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ DiscordClient client = DiscordClient.GetClient(pluginName);
+ [OnDiscordGuildRoleCreated](#ondiscordguildrolecreated)
+ [OnDiscordGuildRoleUpdated](#ondiscordguildroleupdated)
+ [OnDiscordGuildRoleDeleted](#ondiscordguildroledeleted)
+ [OnDiscordGuildScheduledEventCreated](#OnDiscordGuildScheduledEventCreated)
+ [OnDiscordGuildScheduledEventUpdated](#OnDiscordGuildScheduledEventUpdated)
+ [OnDiscordGuildScheduledEventDeleted](#OnDiscordGuildScheduledEventDeleted)
+ [OnDiscordGuildScheduledEventUserAdded](#OnDiscordGuildScheduledEventUserAdded)
+ [OnDiscordGuildScheduledEventUserRemoved](#OnDiscordGuildScheduledEventUserRemoved)
+ [OnDiscordDirectMessageCreated](#ondiscorddirectmessagecreated)
+ [OnDiscordGuildMessageCreated](#ondiscordguildmessagecreated)
+ [OnDiscordDirectMessageUpdated](#ondiscorddirectmessageupdated)
Expand Down Expand Up @@ -434,7 +439,7 @@ void OnDiscordGuildIntegrationsUpdated(GuildIntegrationsUpdatedEvent integration
- Called when a guild member has been added to the guild

```c#
void OnDiscordGuildMemberRemoved(GuildMemberRemovedEvent member, DiscordGuild guild)
void OnDiscordGuildMemberAdded(GuildMemberRemovedEvent member, DiscordGuild guild)
{
Puts("OnDiscordGuildMemberRemoved Works!");
}
Expand All @@ -457,7 +462,7 @@ void OnDiscordGuildMemberRemoved(GuildMemberRemovedEvent member, DiscordGuild gu
- This also include when the DiscordUser is updated as well

```c#
void OnDiscordGuildMemberUpdated(GuildMemberUpdatedEvent member, DiscordGuild guild)
void OnDiscordGuildMemberUpdated(GuildMember update, GuildMember previous, DiscordGuild guild)
{
Puts("OnDiscordGuildMemberUpdated Works!");
}
Expand Down Expand Up @@ -519,6 +524,61 @@ void OnDiscordGuildRoleDeleted(Role role, DiscordGuild guild)
}
```

### OnDiscordGuildScheduledEventCreated

- Called when a discord guild scheduled event is created

```c#
void OnDiscordGuildScheduledEventCreated(GuildScheduledEvent guildEvent, DiscordGuild guild)
{
Puts("OnDiscordGuildScheduledEventCreated Works!");
}
```

### OnDiscordGuildScheduledEventUpdated

- Called when a discord guild scheduled event is update

```c#
void OnDiscordGuildScheduledEventUpdated(GuildScheduledEvent guildEvent, DiscordGuild guild)
{
Puts("OnDiscordGuildScheduledEventUpdated Works!");
}
```

### OnDiscordGuildScheduledEventDeleted

- Called when a discord guild scheduled event is deleted

```c#
void OnDiscordGuildScheduledEventDeleted(GuildScheduledEvent guildEvent, DiscordGuild guild)
{
Puts("OnDiscordGuildScheduledEventDeleted Works!");
}
```

### OnDiscordGuildScheduledEventUserAdded

- Called when a discord user is added to a guild scheduled event

```c#
void OnDiscordGuildScheduledEventUserAdded(GuildScheduleEventUserAddedEvent added, GuildScheduledEvent, scheduledEvent, DiscordGuild guild)
{
Puts("OnDiscordGuildScheduledEventUserAdded Works!");
}
```

### OnDiscordGuildScheduledEventUserRemoved

- Called when a discord user is removed from a guild scheduled event

```c#
void OnDiscordGuildScheduledEventUserRemoved(GuildScheduleEventUserRemovedEvent removed, GuildScheduledEvent, scheduledEvent, DiscordGuild guild)
{
Puts("OnDiscordGuildScheduledEventUserRemoved Works!");
}
```

### OnDiscordDirectMessageCreated

- Called when a message is created in a direct message channel
Expand Down
64 changes: 34 additions & 30 deletions Oxide.Ext.Discord/BotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class BotClient
/// </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 Expand Up @@ -135,13 +140,13 @@ public void ConnectWebSocket()
/// <summary>
/// Close the websocket with discord
/// </summary>
/// <param name="attemptReconnect">Should we attempt to reconnect to discord after closing</param>
/// <param name="attemptResume">Should we attempt to resume the previous session</param>
public void DisconnectWebsocket(bool attemptReconnect = false, bool attemptResume = false)
/// <param name="reconnect">Should we attempt to reconnect to discord after closing</param>
/// <param name="resume">Should we attempt to resume the previous session</param>
public void DisconnectWebsocket(bool reconnect = false, bool resume = false)
{
if (Initialized)
{
_webSocket.Disconnect(attemptReconnect, attemptResume);
_webSocket.Disconnect(reconnect, resume);
}
}

Expand Down Expand Up @@ -180,40 +185,39 @@ public void AddClient(DiscordClient client)
{
Logger.Debug($"{nameof(BotClient)}.{nameof(AddClient)} Clients.Count == 1 connecting bot");
ConnectWebSocket();
return;
}
else

if (client.Settings.LogLevel < Settings.LogLevel)
{
if (client.Settings.LogLevel < Settings.LogLevel)
{
UpdateLogLevel(client.Settings.LogLevel);
}
UpdateLogLevel(client.Settings.LogLevel);
}

GatewayIntents intents = Settings.Intents | client.Settings.Intents;
GatewayIntents intents = Settings.Intents | client.Settings.Intents;

//Our intents have changed. Disconnect websocket and reconnect with new intents.
if (intents != Settings.Intents)
{
Logger.Info("New intents have been requested for the bot. Reconnecting with updated intents.");
Settings.Intents = intents;
DisconnectWebsocket(true);
}
//Our intents have changed. Disconnect websocket and reconnect with new intents.
if (intents != Settings.Intents)
{
Logger.Info("New intents have been requested for the bot. Reconnecting with updated intents.");
Settings.Intents = intents;
DisconnectWebsocket(true);
}

if (ReadyData != null)
if (ReadyData != null)
{
ReadyData.Guilds = Servers.Copy();
client.CallHook(DiscordExtHooks.OnDiscordGatewayReady, ReadyData);

foreach (DiscordGuild guild in Servers.Values)
{
ReadyData.Guilds = Servers.Copy();
client.CallHook(DiscordExtHooks.OnDiscordGatewayReady, ReadyData);
if (guild.IsAvailable)
{
client.CallHook(DiscordExtHooks.OnDiscordGuildCreated, guild);
}

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

if (guild.HasLoadedAllMembers)
{
client.CallHook(DiscordExtHooks.OnDiscordGuildMembersLoaded, guild);
}
client.CallHook(DiscordExtHooks.OnDiscordGuildMembersLoaded, guild);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,81 @@ public CommandOptionBuilder Required(bool required = true)
return this;
}

/// <summary>
/// Enable auto complete for the option
/// </summary>
/// <param name="autoComplete">If the option support auto complete (Default: true)</param>
/// <returns>This</returns>
public CommandOptionBuilder AutoComplete(bool autoComplete = true)
{
_option.Autocomplete = autoComplete;
return this;
}

/// <summary>
/// Min Value for Integer Option
/// </summary>
/// <param name="minValue">Min Value</param>
/// <returns>This</returns>
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");
}

_option.MinValue = minValue;
return this;
}

/// <summary>
/// Min Value for Number Option
/// </summary>
/// <param name="minValue">Min Value</param>
/// <returns>This</returns>
public CommandOptionBuilder SetMinValue(double minValue)
{
if (_option.Type != CommandOptionType.Number)
{
throw new Exception("Can only set min value for Number Type");
}

_option.MinValue = minValue;
return this;
}

/// <summary>
/// Max Value for Integer Option
/// </summary>
/// <param name="maxValue">Min Value</param>
/// <returns>This</returns>
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");
}

_option.MaxValue = maxValue;
return this;
}

/// <summary>
/// Max Value for Number Option
/// </summary>
/// <param name="maxValue">Min Value</param>
/// <returns>This</returns>
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");
}

_option.MaxValue = maxValue;
return this;
}

/// <summary>
/// Set's the channel types for the option
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Oxide.Ext.Discord/Builders/DiscordEmbedBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,14 @@ public DiscordEmbed Build()
{
return _embed;
}

/// <summary>
/// Returns the built embed in a list
/// </summary>
/// <returns>List of <see cref="DiscordEmbed"/></returns>
public List<DiscordEmbed> BuildList()
{
return new List<DiscordEmbed> {_embed};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MessageComponentBuilder AddActionButton(ButtonStyle style, string label,
throw new Exception($"Cannot add link button as action button. Please use {nameof(AddLinkButton)} instead");
}

UpdateActionRow();
UpdateActionRow<ButtonComponent>();
_current.Components.Add(new ButtonComponent
{
Style = style,
Expand Down Expand Up @@ -78,7 +78,7 @@ public MessageComponentBuilder AddLinkButton(string label, string url, bool disa
if (url == null)
throw new ArgumentNullException(nameof(url));

UpdateActionRow();
UpdateActionRow<ButtonComponent>();
_current.Components.Add(new ButtonComponent
{
Style = ButtonStyle.Link,
Expand All @@ -104,7 +104,7 @@ public SelectMenuComponentBuilder AddSelectMenu(string customId, string placehol
if (string.IsNullOrEmpty(customId))
throw new ArgumentException("Value cannot be null or empty.", nameof(customId));

UpdateActionRow();
UpdateActionRow<SelectMenuComponent>();
SelectMenuComponent menu = new SelectMenuComponent
{
CustomId = customId,
Expand All @@ -117,23 +117,55 @@ public SelectMenuComponentBuilder AddSelectMenu(string customId, string placehol
return new SelectMenuComponentBuilder(menu, this);
}

private void UpdateActionRow()
/// <summary>
/// Adds a select menu to a new action row
/// </summary>
/// <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="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>
/// <returns><see cref="MessageComponentBuilder"/></returns>
public MessageComponentBuilder AddInputText(string customId, string label, InputTextStyles style, string placeholder = null, int minValues = 1, int maxValues = 1)
{
if (string.IsNullOrEmpty(customId))
throw new ArgumentException("Value cannot be null or empty.", nameof(customId));

UpdateActionRow<InputTextComponent>();
InputTextComponent menu = new InputTextComponent
{
CustomId = customId,
Label = label,
Style = style,
Placeholder = placeholder,
MinLength = minValues,
MaxLength = maxValues,
};
_current.Components.Add(menu);
return this;
}

private void UpdateActionRow<T>() where T : BaseComponent
{
if (_current.Components.Count == 0)
{
return;
}

if (!(_current.Components[0] is SelectMenuComponent) && _current.Components.Count != 5)
//5 buttons allowed per row
if (typeof(T) == typeof(ButtonComponent) && _current.Components.Count < 5)
{
return;
}

//Max of 5 action rows allowed
if (_components.Count >= 5)
{
throw new Exception("Cannot have more than 5 action rows");
}

//All other components are only 1 per action row so add a new row.
_current = new ActionRowComponent();
_components.Add(_current);
}
Expand Down
Loading

0 comments on commit 2538510

Please sign in to comment.