Browse Source

Merge branch 'dev' into docs/pre-release

pull/1161/head
Still Hsu 7 years ago
parent
commit
3876bd79e6
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
6 changed files with 40 additions and 22 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Builders/ModuleBuilder.cs
  2. +13
    -11
      src/Discord.Net.Commands/Builders/ParameterBuilder.cs
  3. +1
    -0
      src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs
  4. +9
    -2
      src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs
  5. +7
    -6
      src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs
  6. +9
    -2
      src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs

+ 1
- 1
src/Discord.Net.Commands/Builders/ModuleBuilder.cs View File

@@ -120,7 +120,7 @@ namespace Discord.Commands.Builders
if (Name == null)
Name = _aliases[0];

if (TypeInfo != null)
if (TypeInfo != null && !TypeInfo.IsAbstract)
{
var moduleInstance = ReflectionUtils.CreateObject<IModuleBase>(TypeInfo, service, services);
moduleInstance.OnModuleBuilding(service, this);


+ 13
- 11
src/Discord.Net.Commands/Builders/ParameterBuilder.cs View File

@@ -45,14 +45,7 @@ namespace Discord.Commands.Builders

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)
DefaultValue = Activator.CreateInstance(type);
@@ -60,7 +53,16 @@ namespace Discord.Commands.Builders
type = ParameterType.GetElementType();
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)
{
Summary = summary;
@@ -100,10 +102,10 @@ namespace Discord.Commands.Builders

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");

return new ParameterInfo(this, info, Command.Module.Service);
}
}
}
}

+ 1
- 0
src/Discord.Net.Core/Entities/Permissions/ChannelPermission.cs View File

@@ -89,6 +89,7 @@ namespace Discord
/// Allows for using voice-activity-detection in a voice channel.
/// </summary>
UseVAD = 0x02_00_00_00,
PrioritySpeaker = 0x00_00_01_00,

// More General
/// <summary>


+ 9
- 2
src/Discord.Net.Core/Entities/Permissions/ChannelPermissions.cs View File

@@ -13,7 +13,7 @@ namespace Discord
/// <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);
/// <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>
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>
@@ -80,6 +80,8 @@ namespace Discord
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>
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>
public bool ManageRoles => Permissions.GetValue(RawValue, ChannelPermission.ManageRoles);
@@ -108,6 +110,7 @@ namespace Discord
bool? deafenMembers = null,
bool? moveMembers = null,
bool? useVoiceActivation = null,
bool? prioritySpeaker = null,
bool? manageRoles = null,
bool? manageWebhooks = null)
{
@@ -131,6 +134,7 @@ namespace Discord
Permissions.SetValue(ref value, deafenMembers, ChannelPermission.DeafenMembers);
Permissions.SetValue(ref value, moveMembers, ChannelPermission.MoveMembers);
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, manageWebhooks, ChannelPermission.ManageWebhooks);

@@ -157,11 +161,12 @@ namespace Discord
bool deafenMembers = false,
bool moveMembers = false,
bool useVoiceActivation = false,
bool prioritySpeaker = false,
bool manageRoles = false,
bool manageWebhooks = false)
: this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages,
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>
@@ -184,6 +189,7 @@ namespace Discord
bool? deafenMembers = null,
bool? moveMembers = null,
bool? useVoiceActivation = null,
bool? prioritySpeaker = null,
bool? manageRoles = null,
bool? manageWebhooks = null)
=> new ChannelPermissions(RawValue,
@@ -205,6 +211,7 @@ namespace Discord
deafenMembers,
moveMembers,
useVoiceActivation,
prioritySpeaker,
manageRoles,
manageWebhooks);



+ 7
- 6
src/Discord.Net.Core/Entities/Permissions/GuildPermission.cs View File

@@ -80,27 +80,28 @@ namespace Discord
/// <summary>
/// Allows for joining of a voice channel.
/// </summary>
Connect = 0x00_10_00_00,
Connect = 0x00_10_00_00,
/// <summary>
/// Allows for speaking in a voice channel.
/// </summary>
Speak = 0x00_20_00_00,
Speak = 0x00_20_00_00,
/// <summary>
/// Allows for muting members in a voice channel.
/// </summary>
MuteMembers = 0x00_40_00_00,
MuteMembers = 0x00_40_00_00,
/// <summary>
/// Allows for deafening of members in a voice channel.
/// </summary>
DeafenMembers = 0x00_80_00_00,
DeafenMembers = 0x00_80_00_00,
/// <summary>
/// Allows for moving of members between voice channels.
/// </summary>
MoveMembers = 0x01_00_00_00,
MoveMembers = 0x01_00_00_00,
/// <summary>
/// Allows for using voice-activity-detection in a voice channel.
/// </summary>
UseVAD = 0x02_00_00_00,
UseVAD = 0x02_00_00_00,
PrioritySpeaker = 0x00_00_01_00,

// General 2
/// <summary>


+ 9
- 2
src/Discord.Net.Core/Entities/Permissions/GuildPermissions.cs View File

@@ -12,7 +12,7 @@ namespace Discord
/// <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);
/// <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>
public ulong RawValue { get; }
@@ -69,6 +69,8 @@ namespace Discord
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>
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>
public bool ChangeNickname => Permissions.GetValue(RawValue, GuildPermission.ChangeNickname);
@@ -108,6 +110,7 @@ namespace Discord
bool? deafenMembers = null,
bool? moveMembers = null,
bool? useVoiceActivation = null,
bool? prioritySpeaker = null,
bool? changeNickname = null,
bool? manageNicknames = null,
bool? manageRoles = null,
@@ -139,6 +142,7 @@ namespace Discord
Permissions.SetValue(ref value, deafenMembers, GuildPermission.DeafenMembers);
Permissions.SetValue(ref value, moveMembers, GuildPermission.MoveMembers);
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, manageNicknames, GuildPermission.ManageNicknames);
Permissions.SetValue(ref value, manageRoles, GuildPermission.ManageRoles);
@@ -173,6 +177,7 @@ namespace Discord
bool deafenMembers = false,
bool moveMembers = false,
bool useVoiceActivation = false,
bool prioritySpeaker = false,
bool changeNickname = false,
bool manageNicknames = false,
bool manageRoles = false,
@@ -203,6 +208,7 @@ namespace Discord
deafenMembers: deafenMembers,
moveMembers: moveMembers,
useVoiceActivation: useVoiceActivation,
prioritySpeaker: prioritySpeaker,
changeNickname: changeNickname,
manageNicknames: manageNicknames,
manageWebhooks: manageWebhooks,
@@ -234,6 +240,7 @@ namespace Discord
bool? deafenMembers = null,
bool? moveMembers = null,
bool? useVoiceActivation = null,
bool? prioritySpeaker = null,
bool? changeNickname = null,
bool? manageNicknames = null,
bool? manageRoles = null,
@@ -242,7 +249,7 @@ namespace Discord
=> new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions,
viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles,
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);



Loading…
Cancel
Save