Archived
1
0
Fork 0
This repository has been archived on 2024-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
maki/Maki/DiscordServer.cs

49 lines
1.7 KiB
C#

using Maki.Rest;
using Maki.Structures.Guilds;
using Maki.Structures.Rest;
using Maki.Structures.Roles;
using System;
using System.Linq;
namespace Maki
{
public class DiscordServer
{
public readonly ulong Id;
private readonly Discord client;
public string Name { get; internal set; }
public ulong OwnerId { get; internal set; }
public DiscordMember Owner => Members.Where(x => x.User.Id == OwnerId).FirstOrDefault();
public DiscordMember[] Members => client.members.Where(x => x.Server == this).ToArray();
public DiscordRole[] Roles => client.roles.Where(x => x.Server == this).ToArray();
internal DiscordServer(Discord discord, Guild guild)
{
client = discord;
Id = guild.Id;
Name = guild.Name;
OwnerId = guild.OwnerId ?? ulong.MinValue;
}
public DiscordRole CreateRole(string name = null, DiscordPermission perms = DiscordPermission.None, DiscordColour colour = null, bool hoist = false, bool mentionable = false)
{
RestResponse<Role> roleResp = client.RestClient.Request<Role>(RestRequestMethod.POST, RestEndpoints.GuildRoles(Id), new RoleCreate
{
Name = name,
Perms = perms,
Colour = colour == null ? 0 : colour.Raw,
Hoist = hoist,
Mentionable = mentionable
});
if (roleResp.ErrorCode != RestErrorCode.Ok)
throw new Exception($"{roleResp.ErrorCode}: {roleResp.ErrorMessage}");
DiscordRole role = new DiscordRole(client, roleResp.Response, this);
client.roles.Add(role);
return role;
}
}
}