| @@ -120,7 +120,7 @@ namespace Discord.Commands.Builders | |||||
| if (Name == null) | if (Name == null) | ||||
| Name = _aliases[0]; | Name = _aliases[0]; | ||||
| if (TypeInfo != null) | |||||
| if (TypeInfo != null && !TypeInfo.IsAbstract) | |||||
| { | { | ||||
| var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, services); | var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, services); | ||||
| moduleInstance.OnModuleBuilding(service, this); | moduleInstance.OnModuleBuilding(service, this); | ||||
| @@ -45,14 +45,7 @@ namespace Discord.Commands.Builders | |||||
| internal void SetType(Type type) | internal void SetType(Type type) | ||||
| { | { | ||||
| var readers = Command.Module.Service.GetTypeReaders(type); | |||||
| if (readers != null) | |||||
| TypeReader = readers.FirstOrDefault().Value; | |||||
| else | |||||
| TypeReader = Command.Module.Service.GetDefaultTypeReader(type); | |||||
| if (TypeReader == null) | |||||
| throw new InvalidOperationException($"{type} does not have a TypeReader registered for it. Parameter: {Name} in {Command.PrimaryAlias}"); | |||||
| TypeReader = GetReader(type); | |||||
| if (type.GetTypeInfo().IsValueType) | if (type.GetTypeInfo().IsValueType) | ||||
| DefaultValue = Activator.CreateInstance(type); | DefaultValue = Activator.CreateInstance(type); | ||||
| @@ -60,7 +53,16 @@ namespace Discord.Commands.Builders | |||||
| type = ParameterType.GetElementType(); | type = ParameterType.GetElementType(); | ||||
| ParameterType = type; | ParameterType = type; | ||||
| } | } | ||||
| private TypeReader GetReader(Type type) | |||||
| { | |||||
| var readers = Command.Module.Service.GetTypeReaders(type); | |||||
| if (readers != null) | |||||
| return readers.FirstOrDefault().Value; | |||||
| else | |||||
| return Command.Module.Service.GetDefaultTypeReader(type); | |||||
| } | |||||
| public ParameterBuilder WithSummary(string summary) | public ParameterBuilder WithSummary(string summary) | ||||
| { | { | ||||
| Summary = summary; | Summary = summary; | ||||
| @@ -100,10 +102,10 @@ namespace Discord.Commands.Builders | |||||
| internal ParameterInfo Build(CommandInfo info) | internal ParameterInfo Build(CommandInfo info) | ||||
| { | { | ||||
| if (TypeReader == null) | |||||
| if ((TypeReader ?? (TypeReader = GetReader(ParameterType))) == null) | |||||
| throw new InvalidOperationException($"No type reader found for type {ParameterType.Name}, one must be specified"); | throw new InvalidOperationException($"No type reader found for type {ParameterType.Name}, one must be specified"); | ||||
| return new ParameterInfo(this, info, Command.Module.Service); | return new ParameterInfo(this, info, Command.Module.Service); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -89,6 +89,7 @@ namespace Discord | |||||
| /// Allows for using voice-activity-detection in a voice channel. | /// Allows for using voice-activity-detection in a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| UseVAD = 0x02_00_00_00, | UseVAD = 0x02_00_00_00, | ||||
| PrioritySpeaker = 0x00_00_01_00, | |||||
| // More General | // More General | ||||
| /// <summary> | /// <summary> | ||||
| @@ -13,7 +13,7 @@ namespace Discord | |||||
| /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for text channels. </summary> | /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for text channels. </summary> | ||||
| public static readonly ChannelPermissions Text = new ChannelPermissions(0b01100_0000000_1111111110001_010001); | public static readonly ChannelPermissions Text = new ChannelPermissions(0b01100_0000000_1111111110001_010001); | ||||
| /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for voice channels. </summary> | /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for voice channels. </summary> | ||||
| public static readonly ChannelPermissions Voice = new ChannelPermissions(0b00100_1111110_0000000010000_010001); | |||||
| public static readonly ChannelPermissions Voice = new ChannelPermissions(0b00100_1111110_0000000010100_010001); | |||||
| /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels. </summary> | /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for category channels. </summary> | ||||
| public static readonly ChannelPermissions Category = new ChannelPermissions(0b01100_1111110_1111111110001_010001); | public static readonly ChannelPermissions Category = new ChannelPermissions(0b01100_1111110_1111111110001_010001); | ||||
| /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for direct message channels. </summary> | /// <summary> Gets a <see cref="ChannelPermissions"/> that grants all permissions for direct message channels. </summary> | ||||
| @@ -80,6 +80,8 @@ namespace Discord | |||||
| public bool MoveMembers => Permissions.GetValue(RawValue, ChannelPermission.MoveMembers); | public bool MoveMembers => Permissions.GetValue(RawValue, ChannelPermission.MoveMembers); | ||||
| /// <summary> If <c>true</c>, a user may use voice-activity-detection rather than push-to-talk. </summary> | /// <summary> If <c>true</c>, a user may use voice-activity-detection rather than push-to-talk. </summary> | ||||
| public bool UseVAD => Permissions.GetValue(RawValue, ChannelPermission.UseVAD); | public bool UseVAD => Permissions.GetValue(RawValue, ChannelPermission.UseVAD); | ||||
| /// <summary> If True, a user may use priority speaker in a voice channel. </summary> | |||||
| public bool PrioritySpeaker => Permissions.GetValue(RawValue, ChannelPermission.PrioritySpeaker); | |||||
| /// <summary> If <c>true</c>, a user may adjust role permissions. This also implictly grants all other permissions. </summary> | /// <summary> If <c>true</c>, a user may adjust role permissions. This also implictly grants all other permissions. </summary> | ||||
| public bool ManageRoles => Permissions.GetValue(RawValue, ChannelPermission.ManageRoles); | public bool ManageRoles => Permissions.GetValue(RawValue, ChannelPermission.ManageRoles); | ||||
| @@ -108,6 +110,7 @@ namespace Discord | |||||
| bool? deafenMembers = null, | bool? deafenMembers = null, | ||||
| bool? moveMembers = null, | bool? moveMembers = null, | ||||
| bool? useVoiceActivation = null, | bool? useVoiceActivation = null, | ||||
| bool? prioritySpeaker = null, | |||||
| bool? manageRoles = null, | bool? manageRoles = null, | ||||
| bool? manageWebhooks = null) | bool? manageWebhooks = null) | ||||
| { | { | ||||
| @@ -131,6 +134,7 @@ namespace Discord | |||||
| Permissions.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers); | Permissions.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers); | ||||
| Permissions.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers); | Permissions.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers); | ||||
| Permissions.SetValue(ref value, useVoiceActivation, ChannelPermission.UseVAD); | Permissions.SetValue(ref value, useVoiceActivation, ChannelPermission.UseVAD); | ||||
| Permissions.SetValue(ref value, prioritySpeaker, ChannelPermission.PrioritySpeaker); | |||||
| Permissions.SetValue(ref value, manageRoles, ChannelPermission.ManageRoles); | Permissions.SetValue(ref value, manageRoles, ChannelPermission.ManageRoles); | ||||
| Permissions.SetValue(ref value, manageWebhooks, ChannelPermission.ManageWebhooks); | Permissions.SetValue(ref value, manageWebhooks, ChannelPermission.ManageWebhooks); | ||||
| @@ -157,11 +161,12 @@ namespace Discord | |||||
| bool deafenMembers = false, | bool deafenMembers = false, | ||||
| bool moveMembers = false, | bool moveMembers = false, | ||||
| bool useVoiceActivation = false, | bool useVoiceActivation = false, | ||||
| bool prioritySpeaker = false, | |||||
| bool manageRoles = false, | bool manageRoles = false, | ||||
| bool manageWebhooks = false) | bool manageWebhooks = false) | ||||
| : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | ||||
| embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | ||||
| speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks) | |||||
| speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, prioritySpeaker, manageRoles, manageWebhooks) | |||||
| { } | { } | ||||
| /// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions. </summary> | /// <summary> Creates a new <see cref="ChannelPermissions"/> from this one, changing the provided non-null permissions. </summary> | ||||
| @@ -184,6 +189,7 @@ namespace Discord | |||||
| bool? deafenMembers = null, | bool? deafenMembers = null, | ||||
| bool? moveMembers = null, | bool? moveMembers = null, | ||||
| bool? useVoiceActivation = null, | bool? useVoiceActivation = null, | ||||
| bool? prioritySpeaker = null, | |||||
| bool? manageRoles = null, | bool? manageRoles = null, | ||||
| bool? manageWebhooks = null) | bool? manageWebhooks = null) | ||||
| => new ChannelPermissions(RawValue, | => new ChannelPermissions(RawValue, | ||||
| @@ -205,6 +211,7 @@ namespace Discord | |||||
| deafenMembers, | deafenMembers, | ||||
| moveMembers, | moveMembers, | ||||
| useVoiceActivation, | useVoiceActivation, | ||||
| prioritySpeaker, | |||||
| manageRoles, | manageRoles, | ||||
| manageWebhooks); | manageWebhooks); | ||||
| @@ -80,27 +80,28 @@ namespace Discord | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for joining of a voice channel. | /// Allows for joining of a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| Connect = 0x00_10_00_00, | |||||
| Connect = 0x00_10_00_00, | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for speaking in a voice channel. | /// Allows for speaking in a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| Speak = 0x00_20_00_00, | |||||
| Speak = 0x00_20_00_00, | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for muting members in a voice channel. | /// Allows for muting members in a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| MuteMembers = 0x00_40_00_00, | |||||
| MuteMembers = 0x00_40_00_00, | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for deafening of members in a voice channel. | /// Allows for deafening of members in a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| DeafenMembers = 0x00_80_00_00, | |||||
| DeafenMembers = 0x00_80_00_00, | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for moving of members between voice channels. | /// Allows for moving of members between voice channels. | ||||
| /// </summary> | /// </summary> | ||||
| MoveMembers = 0x01_00_00_00, | |||||
| MoveMembers = 0x01_00_00_00, | |||||
| /// <summary> | /// <summary> | ||||
| /// Allows for using voice-activity-detection in a voice channel. | /// Allows for using voice-activity-detection in a voice channel. | ||||
| /// </summary> | /// </summary> | ||||
| UseVAD = 0x02_00_00_00, | |||||
| UseVAD = 0x02_00_00_00, | |||||
| PrioritySpeaker = 0x00_00_01_00, | |||||
| // General 2 | // General 2 | ||||
| /// <summary> | /// <summary> | ||||
| @@ -12,7 +12,7 @@ namespace Discord | |||||
| /// <summary> Gets a <see cref="GuildPermissions"/> that grants all guild permissions for webhook users. </summary> | /// <summary> Gets a <see cref="GuildPermissions"/> that grants all guild permissions for webhook users. </summary> | ||||
| public static readonly GuildPermissions Webhook = new GuildPermissions(0b00000_0000000_0001101100000_000000); | public static readonly GuildPermissions Webhook = new GuildPermissions(0b00000_0000000_0001101100000_000000); | ||||
| /// <summary> Gets a <see cref="GuildPermissions"/> that grants all guild permissions. </summary> | /// <summary> Gets a <see cref="GuildPermissions"/> that grants all guild permissions. </summary> | ||||
| public static readonly GuildPermissions All = new GuildPermissions(0b11111_1111110_1111111110011_111111); | |||||
| public static readonly GuildPermissions All = new GuildPermissions(0b11111_1111110_1111111110111_111111); | |||||
| /// <summary> Gets a packed value representing all the permissions in this <see cref="GuildPermissions"/>. </summary> | /// <summary> Gets a packed value representing all the permissions in this <see cref="GuildPermissions"/>. </summary> | ||||
| public ulong RawValue { get; } | public ulong RawValue { get; } | ||||
| @@ -69,6 +69,8 @@ namespace Discord | |||||
| public bool MoveMembers => Permissions.GetValue(RawValue, GuildPermission.MoveMembers); | public bool MoveMembers => Permissions.GetValue(RawValue, GuildPermission.MoveMembers); | ||||
| /// <summary> If <c>true</c>, a user may use voice-activity-detection rather than push-to-talk. </summary> | /// <summary> If <c>true</c>, a user may use voice-activity-detection rather than push-to-talk. </summary> | ||||
| public bool UseVAD => Permissions.GetValue(RawValue, GuildPermission.UseVAD); | public bool UseVAD => Permissions.GetValue(RawValue, GuildPermission.UseVAD); | ||||
| /// <summary> If True, a user may use priority speaker in a voice channel. </summary> | |||||
| public bool PrioritySpeaker => Permissions.GetValue(RawValue, ChannelPermission.PrioritySpeaker); | |||||
| /// <summary> If <c>true</c>, a user may change their own nickname. </summary> | /// <summary> If <c>true</c>, a user may change their own nickname. </summary> | ||||
| public bool ChangeNickname => Permissions.GetValue(RawValue, GuildPermission.ChangeNickname); | public bool ChangeNickname => Permissions.GetValue(RawValue, GuildPermission.ChangeNickname); | ||||
| @@ -108,6 +110,7 @@ namespace Discord | |||||
| bool? deafenMembers = null, | bool? deafenMembers = null, | ||||
| bool? moveMembers = null, | bool? moveMembers = null, | ||||
| bool? useVoiceActivation = null, | bool? useVoiceActivation = null, | ||||
| bool? prioritySpeaker = null, | |||||
| bool? changeNickname = null, | bool? changeNickname = null, | ||||
| bool? manageNicknames = null, | bool? manageNicknames = null, | ||||
| bool? manageRoles = null, | bool? manageRoles = null, | ||||
| @@ -139,6 +142,7 @@ namespace Discord | |||||
| Permissions.SetValue(ref value, deafenMembers, GuildPermission.DeafenMembers); | Permissions.SetValue(ref value, deafenMembers, GuildPermission.DeafenMembers); | ||||
| Permissions.SetValue(ref value, moveMembers, GuildPermission.MoveMembers); | Permissions.SetValue(ref value, moveMembers, GuildPermission.MoveMembers); | ||||
| Permissions.SetValue(ref value, useVoiceActivation, GuildPermission.UseVAD); | Permissions.SetValue(ref value, useVoiceActivation, GuildPermission.UseVAD); | ||||
| Permissions.SetValue(ref value, prioritySpeaker, GuildPermission.PrioritySpeaker); | |||||
| Permissions.SetValue(ref value, changeNickname, GuildPermission.ChangeNickname); | Permissions.SetValue(ref value, changeNickname, GuildPermission.ChangeNickname); | ||||
| Permissions.SetValue(ref value, manageNicknames, GuildPermission.ManageNicknames); | Permissions.SetValue(ref value, manageNicknames, GuildPermission.ManageNicknames); | ||||
| Permissions.SetValue(ref value, manageRoles, GuildPermission.ManageRoles); | Permissions.SetValue(ref value, manageRoles, GuildPermission.ManageRoles); | ||||
| @@ -173,6 +177,7 @@ namespace Discord | |||||
| bool deafenMembers = false, | bool deafenMembers = false, | ||||
| bool moveMembers = false, | bool moveMembers = false, | ||||
| bool useVoiceActivation = false, | bool useVoiceActivation = false, | ||||
| bool prioritySpeaker = false, | |||||
| bool changeNickname = false, | bool changeNickname = false, | ||||
| bool manageNicknames = false, | bool manageNicknames = false, | ||||
| bool manageRoles = false, | bool manageRoles = false, | ||||
| @@ -203,6 +208,7 @@ namespace Discord | |||||
| deafenMembers: deafenMembers, | deafenMembers: deafenMembers, | ||||
| moveMembers: moveMembers, | moveMembers: moveMembers, | ||||
| useVoiceActivation: useVoiceActivation, | useVoiceActivation: useVoiceActivation, | ||||
| prioritySpeaker: prioritySpeaker, | |||||
| changeNickname: changeNickname, | changeNickname: changeNickname, | ||||
| manageNicknames: manageNicknames, | manageNicknames: manageNicknames, | ||||
| manageWebhooks: manageWebhooks, | manageWebhooks: manageWebhooks, | ||||
| @@ -234,6 +240,7 @@ namespace Discord | |||||
| bool? deafenMembers = null, | bool? deafenMembers = null, | ||||
| bool? moveMembers = null, | bool? moveMembers = null, | ||||
| bool? useVoiceActivation = null, | bool? useVoiceActivation = null, | ||||
| bool? prioritySpeaker = null, | |||||
| bool? changeNickname = null, | bool? changeNickname = null, | ||||
| bool? manageNicknames = null, | bool? manageNicknames = null, | ||||
| bool? manageRoles = null, | bool? manageRoles = null, | ||||
| @@ -242,7 +249,7 @@ namespace Discord | |||||
| => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, | => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, | ||||
| viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | ||||
| readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, | readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, | ||||
| useVoiceActivation, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); | |||||
| useVoiceActivation, prioritySpeaker, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); | |||||
| public bool Has(GuildPermission permission) => Permissions.GetValue(RawValue, permission); | public bool Has(GuildPermission permission) => Permissions.GetValue(RawValue, permission); | ||||