Skip to content

Commit ac9025a

Browse files
committed
feature: finish writing guild properties
1 parent 30e5cbc commit ac9025a

File tree

11 files changed

+227
-8
lines changed

11 files changed

+227
-8
lines changed

src/Discord.Net/Discord.Net.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>7.1</LangVersion>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<PackageReference Include="Wumpus.Net.Gateway" Version="0.2.2-build-00031" />
910
<PackageReference Include="Wumpus.Net.Rest" Version="0.2.2-build-00031" />
1011
</ItemGroup>
1112

12-
<ItemGroup>
13-
<Folder Include="Models\Guilds\" />
14-
</ItemGroup>
15-
1613
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Discord
6+
{
7+
public interface IEmote
8+
{
9+
string Name { get; }
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Discord
2+
{
3+
public interface IGuildEmote : IEmote
4+
{
5+
// TODO
6+
}
7+
}

src/Discord.Net/Entities/Guilds/IGuild.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,40 @@ public interface IGuild : IDeletable, ISnowflakeEntity
142142
/// A string containing the identifier for the voice region that this guild uses (e.g. <c>eu-central</c>).
143143
/// </returns>
144144
string VoiceRegionId { get; }
145+
/// <summary>
146+
/// Gets the <see cref="IAudioClient"/> currently associated with this guild.
147+
/// </summary>
148+
/// <returns>
149+
/// An <see cref="IAudioClient"/> currently associated with this guild.
150+
/// </returns>
151+
//IAudioClient AudioClient { get; } // TODO: how do we want to handle audio?
152+
/// <summary>
153+
/// Gets the built-in role containing all users in this guild.
154+
/// </summary>
155+
/// <returns>
156+
/// A role object that represents an <c>@everyone</c> role in this guild.
157+
/// </returns>
158+
IRole EveryoneRole { get; }
159+
/// <summary>
160+
/// Gets a collection of all custom emotes for this guild.
161+
/// </summary>
162+
/// <returns>
163+
/// A read-only collection of all custom emotes for this guild.
164+
/// </returns>
165+
IReadOnlyCollection<IGuildEmote> Emotes { get; }
166+
/// <summary>
167+
/// Gets a collection of all extra features added to this guild.
168+
/// </summary>
169+
/// <returns>
170+
/// A read-only collection of enabled features in this guild.
171+
/// </returns>
172+
IReadOnlyCollection<string> Features { get; }
173+
/// <summary>
174+
/// Gets a collection of all roles in this guild.
175+
/// </summary>
176+
/// <returns>
177+
/// A read-only collection of roles found within this guild.
178+
/// </returns>
179+
IReadOnlyCollection<IRole> Roles { get; }
145180
}
146181
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Discord
2+
{
3+
public interface IMentionable
4+
{
5+
string Mention { get; }
6+
}
7+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Color = Wumpus.Entities.Color; // TODO: do we need to impl our own color struct?
4+
using GuildPermissions = Wumpus.Entities.GuildPermissions; // TODO: permissions
5+
6+
namespace Discord
7+
{
8+
/// <summary>
9+
/// Represents a generic role object to be given to a guild user.
10+
/// </summary>
11+
public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable<IRole>
12+
{
13+
/// <summary>
14+
/// Gets the guild that owns this role.
15+
/// </summary>
16+
/// <returns>
17+
/// A guild representing the parent guild of this role.
18+
/// </returns>
19+
IGuild Guild { get; }
20+
21+
/// <summary>
22+
/// Gets the color given to users of this role.
23+
/// </summary>
24+
/// <returns>
25+
/// A <see cref="Color"/> struct representing the color of this role.
26+
/// </returns>
27+
Color Color { get; }
28+
/// <summary>
29+
/// Gets a value that indicates whether the role can be separated in the user list.
30+
/// </summary>
31+
/// <returns>
32+
/// <c>true</c> if users of this role are separated in the user list; otherwise <c>false</c>.
33+
/// </returns>
34+
bool IsHoisted { get; }
35+
/// <summary>
36+
/// Gets a value that indicates whether the role is managed by Discord.
37+
/// </summary>
38+
/// <returns>
39+
/// <c>true</c> if this role is automatically managed by Discord; otherwise <c>false</c>.
40+
/// </returns>
41+
bool IsManaged { get; }
42+
/// <summary>
43+
/// Gets a value that indicates whether the role is mentionable.
44+
/// </summary>
45+
/// <returns>
46+
/// <c>true</c> if this role may be mentioned in messages; otherwise <c>false</c>.
47+
/// </returns>
48+
bool IsMentionable { get; }
49+
/// <summary>
50+
/// Gets the name of this role.
51+
/// </summary>
52+
/// <returns>
53+
/// A string containing the name of this role.
54+
/// </returns>
55+
string Name { get; }
56+
/// <summary>
57+
/// Gets the permissions granted to members of this role.
58+
/// </summary>
59+
/// <returns>
60+
/// A <see cref="GuildPermissions"/> struct that this role possesses.
61+
/// </returns>
62+
GuildPermissions Permissions { get; }
63+
/// <summary>
64+
/// Gets this role's position relative to other roles in the same guild.
65+
/// </summary>
66+
/// <returns>
67+
/// An <see cref="int"/> representing the position of the role in the role list of the guild.
68+
/// </returns>
69+
int Position { get; }
70+
71+
/// <summary>
72+
/// Modifies this role.
73+
/// </summary>
74+
/// <remarks>
75+
/// This method modifies this role with the specified properties. To see an example of this
76+
/// method and what properties are available, please refer to <see cref="RoleProperties"/>.
77+
/// </remarks>
78+
/// <param name="func">A delegate containing the properties to modify the role with.</param>
79+
/// <param name="options">The options to be used when sending the request.</param>
80+
/// <returns>
81+
/// A task that represents the asynchronous modification operation.
82+
/// </returns>
83+
Task ModifyAsync(); // TODO: stub out request properties
84+
}
85+
}

src/Discord.Net/IDiscordClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace Discord
66
{
77
public interface IDiscordClient
88
{
9+
event Action Ready;
10+
911
WumpusGatewayClient Gateway { get; }
1012
WumpusRestClient Rest { get; }
1113

1214
Task StartAsync();
1315
Task StopAsync();
14-
15-
event Action Ready;
1616
}
1717
}

src/Discord.Net/Models/Guilds/Guild.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Discord
99
{
1010
internal class Guild : SnowflakeEntity, IGuild
1111
{
12-
public Guild(Model model, IDiscordClient client) : base(client)
12+
public Guild(Model model, IDiscordClient discord) : base(discord)
1313
{
1414
Name = model.Name.ToString();
1515
AFKTimeout = model.AfkTimeout;
@@ -35,6 +35,23 @@ public Guild(Model model, IDiscordClient client) : base(client)
3535
OwnerId = model.OwnerId;
3636
ApplicationId = model.ApplicationId;
3737
VoiceRegionId = null; // TODO?
38+
39+
Role[] roles = new Role[model.Roles.Length];
40+
Role role;
41+
for (int i = 0; i < model.Roles.Length; i++)
42+
{
43+
role = new Role(model.Roles[i], this, Discord);
44+
if (role.Id == Id) // EveryoneRole has the same ID as the guild
45+
EveryoneRole = role;
46+
roles[i] = role;
47+
}
48+
Roles = roles;
49+
50+
// TODO: emotes
51+
string[] features = new string[model.Features.Length];
52+
for (int i = 0; i < model.Features.Length; i++)
53+
features[i] = model.Features[i].ToString();
54+
Features = features;
3855
}
3956

4057
public string Name { get; set; }
@@ -61,6 +78,12 @@ public Guild(Model model, IDiscordClient client) : base(client)
6178
public ulong? ApplicationId { get; set; }
6279
public string VoiceRegionId { get; set; }
6380

64-
public Task DeleteAsync() => throw new NotImplementedException();
81+
public IRole EveryoneRole { get; set; }
82+
public IReadOnlyCollection<IGuildEmote> Emotes { get; set; }
83+
public IReadOnlyCollection<string> Features { get; set; }
84+
public IReadOnlyCollection<IRole> Roles { get; set; }
85+
86+
public Task DeleteAsync()
87+
=> Discord.Rest.DeleteGuildAsync(Id);
6588
}
6689
}

src/Discord.Net/Models/Roles/Role.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Wumpus.Entities;
6+
using Model = Wumpus.Entities.Role;
7+
8+
namespace Discord
9+
{
10+
internal class Role : SnowflakeEntity, IRole
11+
{
12+
public Role(Model model, IGuild guild, IDiscordClient discord) : base(discord)
13+
{
14+
Guild = guild;
15+
16+
Color = model.Color;
17+
IsHoisted = model.IsHoisted;
18+
IsManaged = model.Managed;
19+
IsMentionable = model.IsMentionable;
20+
Name = model.Name.ToString();
21+
Permissions = model.Permissions;
22+
Position = model.Position;
23+
}
24+
25+
public IGuild Guild { get; set; }
26+
27+
public Color Color { get; set; }
28+
public bool IsHoisted { get; set; }
29+
public bool IsManaged { get; set; }
30+
public bool IsMentionable { get; set; }
31+
public string Name { get; set; }
32+
public GuildPermissions Permissions { get; set; }
33+
public int Position { get; set; }
34+
public string Mention => throw new NotImplementedException(); // TODO: MentionUtils
35+
36+
public Task DeleteAsync()
37+
=> Discord.Rest.DeleteGuildRoleAsync(Guild.Id, Id);
38+
39+
public Task ModifyAsync()
40+
{
41+
throw new NotImplementedException();
42+
}
43+
44+
// IComparable
45+
public int CompareTo(IRole other)
46+
{
47+
return Id.CompareTo(other.Id);
48+
}
49+
}
50+
}

test/Discord.Tests.Integration/Discord.Tests.Integration.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7+
8+
<LangVersion>7.1</LangVersion>
79
</PropertyGroup>
810

911
<ItemGroup>

0 commit comments

Comments
 (0)