Skip to content

Commit 2538510

Browse files
authored
Merge pull request #38 from Kirollos/develop
Merge 2.1.0 -> Main
2 parents d04a405 + e08d9f1 commit 2538510

File tree

78 files changed

+3438
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3438
-423
lines changed

Docs/GatewayIntents.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ This is a list of all intents and which hooks become available when using a spec
9696
* Direct Message Typing (`GatewayIntents.DirectMessageTyping`)
9797
* [OnDiscordDirectTypingStarted](Hooks.md#ondiscorddirecttypingstarted)
9898

99+
* Guild Scheduled Events (`GatewayIntents.GuildScheduledEvents`)
100+
* [OnDiscordGuildScheduledEventCreated](Hooks.md#OnDiscordGuildScheduledEventCreated)
101+
* [OnDiscordGuildScheduledEventUpdated](Hooks.md#OnDiscordGuildScheduledEventUpdated)
102+
* [OnDiscordGuildScheduledEventDeleted](Hooks.md#OnDiscordGuildScheduledEventDeleted)
103+
* [OnDiscordGuildScheduledEventUserAdded](Hooks.md#OnDiscordGuildScheduledEventUserAdded)
104+
* [OnDiscordGuildScheduledEventUserRemoved](Hooks.md#OnDiscordGuildScheduledEventUserRemoved)
99105

100106
## Building Intents
101107
You can build your intents in the following manner

Docs/Hooks.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ DiscordClient client = DiscordClient.GetClient(pluginName);
5959
+ [OnDiscordGuildRoleCreated](#ondiscordguildrolecreated)
6060
+ [OnDiscordGuildRoleUpdated](#ondiscordguildroleupdated)
6161
+ [OnDiscordGuildRoleDeleted](#ondiscordguildroledeleted)
62+
+ [OnDiscordGuildScheduledEventCreated](#OnDiscordGuildScheduledEventCreated)
63+
+ [OnDiscordGuildScheduledEventUpdated](#OnDiscordGuildScheduledEventUpdated)
64+
+ [OnDiscordGuildScheduledEventDeleted](#OnDiscordGuildScheduledEventDeleted)
65+
+ [OnDiscordGuildScheduledEventUserAdded](#OnDiscordGuildScheduledEventUserAdded)
66+
+ [OnDiscordGuildScheduledEventUserRemoved](#OnDiscordGuildScheduledEventUserRemoved)
6267
+ [OnDiscordDirectMessageCreated](#ondiscorddirectmessagecreated)
6368
+ [OnDiscordGuildMessageCreated](#ondiscordguildmessagecreated)
6469
+ [OnDiscordDirectMessageUpdated](#ondiscorddirectmessageupdated)
@@ -434,7 +439,7 @@ void OnDiscordGuildIntegrationsUpdated(GuildIntegrationsUpdatedEvent integration
434439
- Called when a guild member has been added to the guild
435440

436441
```c#
437-
void OnDiscordGuildMemberRemoved(GuildMemberRemovedEvent member, DiscordGuild guild)
442+
void OnDiscordGuildMemberAdded(GuildMemberRemovedEvent member, DiscordGuild guild)
438443
{
439444
Puts("OnDiscordGuildMemberRemoved Works!");
440445
}
@@ -457,7 +462,7 @@ void OnDiscordGuildMemberRemoved(GuildMemberRemovedEvent member, DiscordGuild gu
457462
- This also include when the DiscordUser is updated as well
458463

459464
```c#
460-
void OnDiscordGuildMemberUpdated(GuildMemberUpdatedEvent member, DiscordGuild guild)
465+
void OnDiscordGuildMemberUpdated(GuildMember update, GuildMember previous, DiscordGuild guild)
461466
{
462467
Puts("OnDiscordGuildMemberUpdated Works!");
463468
}
@@ -519,6 +524,61 @@ void OnDiscordGuildRoleDeleted(Role role, DiscordGuild guild)
519524
}
520525
```
521526

527+
### OnDiscordGuildScheduledEventCreated
528+
529+
- Called when a discord guild scheduled event is created
530+
531+
```c#
532+
void OnDiscordGuildScheduledEventCreated(GuildScheduledEvent guildEvent, DiscordGuild guild)
533+
{
534+
Puts("OnDiscordGuildScheduledEventCreated Works!");
535+
}
536+
```
537+
538+
### OnDiscordGuildScheduledEventUpdated
539+
540+
- Called when a discord guild scheduled event is update
541+
542+
```c#
543+
void OnDiscordGuildScheduledEventUpdated(GuildScheduledEvent guildEvent, DiscordGuild guild)
544+
{
545+
Puts("OnDiscordGuildScheduledEventUpdated Works!");
546+
}
547+
```
548+
549+
### OnDiscordGuildScheduledEventDeleted
550+
551+
- Called when a discord guild scheduled event is deleted
552+
553+
```c#
554+
void OnDiscordGuildScheduledEventDeleted(GuildScheduledEvent guildEvent, DiscordGuild guild)
555+
{
556+
Puts("OnDiscordGuildScheduledEventDeleted Works!");
557+
}
558+
```
559+
560+
### OnDiscordGuildScheduledEventUserAdded
561+
562+
- Called when a discord user is added to a guild scheduled event
563+
564+
```c#
565+
void OnDiscordGuildScheduledEventUserAdded(GuildScheduleEventUserAddedEvent added, GuildScheduledEvent, scheduledEvent, DiscordGuild guild)
566+
{
567+
Puts("OnDiscordGuildScheduledEventUserAdded Works!");
568+
}
569+
```
570+
571+
### OnDiscordGuildScheduledEventUserRemoved
572+
573+
- Called when a discord user is removed from a guild scheduled event
574+
575+
```c#
576+
void OnDiscordGuildScheduledEventUserRemoved(GuildScheduleEventUserRemovedEvent removed, GuildScheduledEvent, scheduledEvent, DiscordGuild guild)
577+
{
578+
Puts("OnDiscordGuildScheduledEventUserRemoved Works!");
579+
}
580+
```
581+
522582
### OnDiscordDirectMessageCreated
523583

524584
- Called when a message is created in a direct message channel

Oxide.Ext.Discord/BotClient.cs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public class BotClient
5353
/// </summary>
5454
public bool Initialized { get; private set; }
5555

56+
/// <summary>
57+
/// If the bot has successfully connected to the websocket at least once
58+
/// </summary>
59+
public bool ConnectedSuccessfully { get; internal set; }
60+
5661
/// <summary>
5762
/// Application reference for this bot
5863
/// </summary>
@@ -135,13 +140,13 @@ public void ConnectWebSocket()
135140
/// <summary>
136141
/// Close the websocket with discord
137142
/// </summary>
138-
/// <param name="attemptReconnect">Should we attempt to reconnect to discord after closing</param>
139-
/// <param name="attemptResume">Should we attempt to resume the previous session</param>
140-
public void DisconnectWebsocket(bool attemptReconnect = false, bool attemptResume = false)
143+
/// <param name="reconnect">Should we attempt to reconnect to discord after closing</param>
144+
/// <param name="resume">Should we attempt to resume the previous session</param>
145+
public void DisconnectWebsocket(bool reconnect = false, bool resume = false)
141146
{
142147
if (Initialized)
143148
{
144-
_webSocket.Disconnect(attemptReconnect, attemptResume);
149+
_webSocket.Disconnect(reconnect, resume);
145150
}
146151
}
147152

@@ -180,40 +185,39 @@ public void AddClient(DiscordClient client)
180185
{
181186
Logger.Debug($"{nameof(BotClient)}.{nameof(AddClient)} Clients.Count == 1 connecting bot");
182187
ConnectWebSocket();
188+
return;
183189
}
184-
else
190+
191+
if (client.Settings.LogLevel < Settings.LogLevel)
185192
{
186-
if (client.Settings.LogLevel < Settings.LogLevel)
187-
{
188-
UpdateLogLevel(client.Settings.LogLevel);
189-
}
193+
UpdateLogLevel(client.Settings.LogLevel);
194+
}
190195

191-
GatewayIntents intents = Settings.Intents | client.Settings.Intents;
196+
GatewayIntents intents = Settings.Intents | client.Settings.Intents;
192197

193-
//Our intents have changed. Disconnect websocket and reconnect with new intents.
194-
if (intents != Settings.Intents)
195-
{
196-
Logger.Info("New intents have been requested for the bot. Reconnecting with updated intents.");
197-
Settings.Intents = intents;
198-
DisconnectWebsocket(true);
199-
}
198+
//Our intents have changed. Disconnect websocket and reconnect with new intents.
199+
if (intents != Settings.Intents)
200+
{
201+
Logger.Info("New intents have been requested for the bot. Reconnecting with updated intents.");
202+
Settings.Intents = intents;
203+
DisconnectWebsocket(true);
204+
}
200205

201-
if (ReadyData != null)
206+
if (ReadyData != null)
207+
{
208+
ReadyData.Guilds = Servers.Copy();
209+
client.CallHook(DiscordExtHooks.OnDiscordGatewayReady, ReadyData);
210+
211+
foreach (DiscordGuild guild in Servers.Values)
202212
{
203-
ReadyData.Guilds = Servers.Copy();
204-
client.CallHook(DiscordExtHooks.OnDiscordGatewayReady, ReadyData);
213+
if (guild.IsAvailable)
214+
{
215+
client.CallHook(DiscordExtHooks.OnDiscordGuildCreated, guild);
216+
}
205217

206-
foreach (DiscordGuild guild in Servers.Values)
218+
if (guild.HasLoadedAllMembers)
207219
{
208-
if (guild.IsAvailable)
209-
{
210-
client.CallHook(DiscordExtHooks.OnDiscordGuildCreated, guild);
211-
}
212-
213-
if (guild.HasLoadedAllMembers)
214-
{
215-
client.CallHook(DiscordExtHooks.OnDiscordGuildMembersLoaded, guild);
216-
}
220+
client.CallHook(DiscordExtHooks.OnDiscordGuildMembersLoaded, guild);
217221
}
218222
}
219223
}

Oxide.Ext.Discord/Builders/ApplicationCommands/CommandOptionBuilder.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,81 @@ public CommandOptionBuilder Required(bool required = true)
4646
return this;
4747
}
4848

49+
/// <summary>
50+
/// Enable auto complete for the option
51+
/// </summary>
52+
/// <param name="autoComplete">If the option support auto complete (Default: true)</param>
53+
/// <returns>This</returns>
54+
public CommandOptionBuilder AutoComplete(bool autoComplete = true)
55+
{
56+
_option.Autocomplete = autoComplete;
57+
return this;
58+
}
59+
60+
/// <summary>
61+
/// Min Value for Integer Option
62+
/// </summary>
63+
/// <param name="minValue">Min Value</param>
64+
/// <returns>This</returns>
65+
public CommandOptionBuilder SetMinValue(int minValue)
66+
{
67+
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
68+
{
69+
throw new Exception("Can only set min value for Integer or Number Type");
70+
}
71+
72+
_option.MinValue = minValue;
73+
return this;
74+
}
75+
76+
/// <summary>
77+
/// Min Value for Number Option
78+
/// </summary>
79+
/// <param name="minValue">Min Value</param>
80+
/// <returns>This</returns>
81+
public CommandOptionBuilder SetMinValue(double minValue)
82+
{
83+
if (_option.Type != CommandOptionType.Number)
84+
{
85+
throw new Exception("Can only set min value for Number Type");
86+
}
87+
88+
_option.MinValue = minValue;
89+
return this;
90+
}
91+
92+
/// <summary>
93+
/// Max Value for Integer Option
94+
/// </summary>
95+
/// <param name="maxValue">Min Value</param>
96+
/// <returns>This</returns>
97+
public CommandOptionBuilder SetMaxValue(int maxValue)
98+
{
99+
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
100+
{
101+
throw new Exception("Can only set max value for Integer or Number Type");
102+
}
103+
104+
_option.MaxValue = maxValue;
105+
return this;
106+
}
107+
108+
/// <summary>
109+
/// Max Value for Number Option
110+
/// </summary>
111+
/// <param name="maxValue">Min Value</param>
112+
/// <returns>This</returns>
113+
public CommandOptionBuilder SetMaxValue(double maxValue)
114+
{
115+
if (_option.Type != CommandOptionType.Integer && _option.Type != CommandOptionType.Number)
116+
{
117+
throw new Exception("Can only set max value for Number Type");
118+
}
119+
120+
_option.MaxValue = maxValue;
121+
return this;
122+
}
123+
49124
/// <summary>
50125
/// Set's the channel types for the option
51126
/// </summary>

Oxide.Ext.Discord/Builders/DiscordEmbedBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,14 @@ public DiscordEmbed Build()
340340
{
341341
return _embed;
342342
}
343+
344+
/// <summary>
345+
/// Returns the built embed in a list
346+
/// </summary>
347+
/// <returns>List of <see cref="DiscordEmbed"/></returns>
348+
public List<DiscordEmbed> BuildList()
349+
{
350+
return new List<DiscordEmbed> {_embed};
351+
}
343352
}
344353
}

Oxide.Ext.Discord/Builders/MessageComponents/MessageComponentBuilder.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public MessageComponentBuilder AddActionButton(ButtonStyle style, string label,
4040
throw new Exception($"Cannot add link button as action button. Please use {nameof(AddLinkButton)} instead");
4141
}
4242

43-
UpdateActionRow();
43+
UpdateActionRow<ButtonComponent>();
4444
_current.Components.Add(new ButtonComponent
4545
{
4646
Style = style,
@@ -78,7 +78,7 @@ public MessageComponentBuilder AddLinkButton(string label, string url, bool disa
7878
if (url == null)
7979
throw new ArgumentNullException(nameof(url));
8080

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

107-
UpdateActionRow();
107+
UpdateActionRow<SelectMenuComponent>();
108108
SelectMenuComponent menu = new SelectMenuComponent
109109
{
110110
CustomId = customId,
@@ -117,23 +117,55 @@ public SelectMenuComponentBuilder AddSelectMenu(string customId, string placehol
117117
return new SelectMenuComponentBuilder(menu, this);
118118
}
119119

120-
private void UpdateActionRow()
120+
/// <summary>
121+
/// Adds a select menu to a new action row
122+
/// </summary>
123+
/// <param name="customId">Unique ID for the select menu</param>
124+
/// <param name="label">Label for the input text</param>
125+
/// <param name="style">Style of the Input Text</param>
126+
/// <param name="placeholder">Text to display if no value is selected yet</param>
127+
/// <param name="minValues">The min number of options you must select</param>
128+
/// <param name="maxValues">The max number of options you can select</param>
129+
/// <returns><see cref="MessageComponentBuilder"/></returns>
130+
public MessageComponentBuilder AddInputText(string customId, string label, InputTextStyles style, string placeholder = null, int minValues = 1, int maxValues = 1)
131+
{
132+
if (string.IsNullOrEmpty(customId))
133+
throw new ArgumentException("Value cannot be null or empty.", nameof(customId));
134+
135+
UpdateActionRow<InputTextComponent>();
136+
InputTextComponent menu = new InputTextComponent
137+
{
138+
CustomId = customId,
139+
Label = label,
140+
Style = style,
141+
Placeholder = placeholder,
142+
MinLength = minValues,
143+
MaxLength = maxValues,
144+
};
145+
_current.Components.Add(menu);
146+
return this;
147+
}
148+
149+
private void UpdateActionRow<T>() where T : BaseComponent
121150
{
122151
if (_current.Components.Count == 0)
123152
{
124153
return;
125154
}
126155

127-
if (!(_current.Components[0] is SelectMenuComponent) && _current.Components.Count != 5)
156+
//5 buttons allowed per row
157+
if (typeof(T) == typeof(ButtonComponent) && _current.Components.Count < 5)
128158
{
129159
return;
130160
}
131161

162+
//Max of 5 action rows allowed
132163
if (_components.Count >= 5)
133164
{
134165
throw new Exception("Cannot have more than 5 action rows");
135166
}
136167

168+
//All other components are only 1 per action row so add a new row.
137169
_current = new ActionRowComponent();
138170
_components.Add(_current);
139171
}

0 commit comments

Comments
 (0)