Skip to content

Commit a9e8024

Browse files
initial commit
0 parents  commit a9e8024

16 files changed

+735
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
obj/
3+
bin/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\FosscordSharp\FosscordSharp.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
14+
</ItemGroup>
15+
16+
</Project>

FosscordSharp.Test/Program.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
namespace FosscordSharp.Test
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("Hello World!");
12+
run();
13+
14+
Thread.Sleep(int.MaxValue);
15+
}
16+
17+
static async Task run()
18+
{
19+
Random rnd = new Random();
20+
FosscordClient client = new(new()
21+
{
22+
Email = $"FosscordSharp{rnd.Next()}@test.bot",
23+
Password = "SomePassword",
24+
Endpoint = "https://fosscord.thearcanebrony.net",
25+
RegistrationOptions =
26+
{
27+
Username = "FosscordSharp Test Bot"
28+
}
29+
});
30+
// await client.Login();
31+
32+
FosscordClient fc = new FosscordClient(new()
33+
{
34+
Email = "[email protected]",
35+
Password = "SomePassword",
36+
Endpoint = "https://fosscord.thearcanebrony.net"
37+
});
38+
await fc.Login();
39+
var gs = await fc.GetGuilds();
40+
Util.Log("Got guilds!");
41+
foreach (var g in gs)
42+
{
43+
Util.Log($"{g.Name}: ");
44+
foreach (var c in await g.GetChannels())
45+
{
46+
Util.Log($"- {c.Name}");
47+
48+
}
49+
}
50+
Util.Log(client.GetGuilds().Result.Length + " guilds");
51+
}
52+
}
53+
}

FosscordSharp.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FosscordSharp", "FosscordSharp\FosscordSharp.csproj", "{507A2104-26E2-4FA9-86D4-7915425F46E7}"
4+
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FosscordSharp.Test", "FosscordSharp.Test\FosscordSharp.Test.csproj", "{71933DC6-2039-4203-927C-E8A39C56AACB}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{507A2104-26E2-4FA9-86D4-7915425F46E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{507A2104-26E2-4FA9-86D4-7915425F46E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{507A2104-26E2-4FA9-86D4-7915425F46E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{507A2104-26E2-4FA9-86D4-7915425F46E7}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{71933DC6-2039-4203-927C-E8A39C56AACB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{71933DC6-2039-4203-927C-E8A39C56AACB}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{71933DC6-2039-4203-927C-E8A39C56AACB}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{71933DC6-2039-4203-927C-E8A39C56AACB}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

FosscordSharp/Entities/Channel.cs

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net.Http;
4+
using System.Net.Http.Json;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
7+
8+
namespace FosscordSharp.Entities
9+
{
10+
public class Channel
11+
{
12+
private FosscordClient _client;
13+
14+
[JsonProperty("id")]
15+
public string Id { get; set; }
16+
17+
[JsonProperty("created_at")]
18+
public DateTime CreatedAt { get; set; }
19+
20+
[JsonProperty("name")]
21+
public string Name { get; set; }
22+
23+
[JsonProperty("icon")]
24+
public object Icon { get; set; }
25+
26+
[JsonProperty("type")]
27+
public int Type { get; set; }
28+
29+
[JsonProperty("last_message_id")]
30+
public object LastMessageId { get; set; }
31+
32+
[JsonProperty("guild_id")]
33+
public string GuildId { get; set; }
34+
35+
[JsonProperty("parent_id")]
36+
public object ParentId { get; set; }
37+
38+
[JsonProperty("owner_id")]
39+
public object OwnerId { get; set; }
40+
41+
[JsonProperty("last_pin_timestamp")]
42+
public object LastPinTimestamp { get; set; }
43+
44+
[JsonProperty("default_auto_archive_duration")]
45+
public object DefaultAutoArchiveDuration { get; set; }
46+
47+
[JsonProperty("position")]
48+
public int Position { get; set; }
49+
50+
[JsonProperty("permission_overwrites")]
51+
public List<object> PermissionOverwrites { get; set; }
52+
53+
[JsonProperty("video_quality_mode")]
54+
public object VideoQualityMode { get; set; }
55+
56+
[JsonProperty("bitrate")]
57+
public object Bitrate { get; set; }
58+
59+
[JsonProperty("user_limit")]
60+
public object UserLimit { get; set; }
61+
62+
[JsonProperty("nsfw")]
63+
public object Nsfw { get; set; }
64+
65+
[JsonProperty("rate_limit_per_user")]
66+
public object RateLimitPerUser { get; set; }
67+
68+
[JsonProperty("topic")]
69+
public object Topic { get; set; }
70+
71+
public async Task<Invite> CreateInvite(int duration = 0, int max_uses = 0, bool temporary_membership = true)
72+
{
73+
Util.Log($"Creating invite for {Id}/{Name}");
74+
HttpResponseMessage resp = await _client._httpClient.PostAsJsonAsync($"/api/v9/channels/{Id}/invites",
75+
new { max_age = duration, max_uses = max_uses, temporary = temporary_membership });
76+
77+
Util.Log(resp.ToString());
78+
Util.Log(await resp.Content.ReadAsStringAsync());
79+
return await resp.Content.ReadFromJsonAsync<Invite>();
80+
}
81+
}
82+
}

FosscordSharp/Entities/Guild.cs

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System.Collections.Generic;
2+
using System.Net.Http.Json;
3+
using System.Threading.Tasks;
4+
using Newtonsoft.Json;
5+
6+
namespace FosscordSharp.Entities
7+
{
8+
public class Guild
9+
{
10+
internal FosscordClient _client;
11+
[JsonProperty("id")]
12+
public string Id { get; set; }
13+
14+
[JsonProperty("afk_channel_id")]
15+
public object AfkChannelId { get; set; }
16+
17+
[JsonProperty("afk_timeout")]
18+
public int AfkTimeout { get; set; }
19+
20+
[JsonProperty("banner")]
21+
public object Banner { get; set; }
22+
23+
[JsonProperty("default_message_notifications")]
24+
public int DefaultMessageNotifications { get; set; }
25+
26+
[JsonProperty("description")]
27+
public object Description { get; set; }
28+
29+
[JsonProperty("discovery_splash")]
30+
public object DiscoverySplash { get; set; }
31+
32+
[JsonProperty("explicit_content_filter")]
33+
public int ExplicitContentFilter { get; set; }
34+
35+
[JsonProperty("features")]
36+
public List<object> Features { get; set; }
37+
38+
[JsonProperty("icon")]
39+
public object Icon { get; set; }
40+
41+
[JsonProperty("large")]
42+
public object Large { get; set; }
43+
44+
[JsonProperty("max_members")]
45+
public int MaxMembers { get; set; }
46+
47+
[JsonProperty("max_presences")]
48+
public int MaxPresences { get; set; }
49+
50+
[JsonProperty("max_video_channel_users")]
51+
public int MaxVideoChannelUsers { get; set; }
52+
53+
[JsonProperty("member_count")]
54+
public int MemberCount { get; set; }
55+
56+
[JsonProperty("presence_count")]
57+
public int PresenceCount { get; set; }
58+
59+
[JsonProperty("template_id")]
60+
public object TemplateId { get; set; }
61+
62+
[JsonProperty("mfa_level")]
63+
public int MfaLevel { get; set; }
64+
65+
[JsonProperty("name")]
66+
public string Name { get; set; }
67+
68+
[JsonProperty("owner_id")]
69+
public string OwnerId { get; set; }
70+
71+
[JsonProperty("preferred_locale")]
72+
public string PreferredLocale { get; set; }
73+
74+
[JsonProperty("premium_subscription_count")]
75+
public int PremiumSubscriptionCount { get; set; }
76+
77+
[JsonProperty("premium_tier")]
78+
public int PremiumTier { get; set; }
79+
80+
[JsonProperty("public_updates_channel_id")]
81+
public object PublicUpdatesChannelId { get; set; }
82+
83+
[JsonProperty("rules_channel_id")]
84+
public object RulesChannelId { get; set; }
85+
86+
[JsonProperty("region")]
87+
public string Region { get; set; }
88+
89+
[JsonProperty("splash")]
90+
public object Splash { get; set; }
91+
92+
[JsonProperty("system_channel_id")]
93+
public object SystemChannelId { get; set; }
94+
95+
[JsonProperty("system_channel_flags")]
96+
public int SystemChannelFlags { get; set; }
97+
98+
[JsonProperty("unavailable")]
99+
public bool Unavailable { get; set; }
100+
101+
[JsonProperty("verification_level")]
102+
public int VerificationLevel { get; set; }
103+
104+
// [JsonProperty("welcome_screen")]
105+
// public WelcomeScreen WelcomeScreen { get; set; }
106+
107+
[JsonProperty("widget_channel_id")]
108+
public object WidgetChannelId { get; set; }
109+
110+
[JsonProperty("widget_enabled")]
111+
public bool WidgetEnabled { get; set; }
112+
113+
[JsonProperty("nsfw_level")]
114+
public int NsfwLevel { get; set; }
115+
116+
[JsonProperty("nsfw")]
117+
public bool Nsfw { get; set; }
118+
119+
public Guild()
120+
{
121+
122+
}
123+
public Guild(FosscordClient client)
124+
{
125+
_client = client;
126+
}
127+
128+
public ulong id = 0;
129+
public async Task<Channel[]> GetChannels()
130+
{
131+
Util.Log("GetChannels called on guild " + id);
132+
// await _client._httpClient.GetAsync($"");
133+
// Util.LogDebug($"/guilds/{id}/channels");
134+
// Util.LogDebug(await _client._httpClient.GetStringAsync($"/guilds/{id}/channels"));
135+
var a = await _client._httpClient.GetFromJsonAsync<Channel[]>($"/api/guilds/{id}/channels");
136+
Util.Log(a.Length+ " channels");
137+
return a;
138+
}
139+
}
140+
}

FosscordSharp/Entities/Invite.cs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace FosscordSharp.Entities
5+
{
6+
public class Invite
7+
{
8+
[JsonProperty("code")]
9+
public string Code { get; set; }
10+
11+
[JsonProperty("temporary")]
12+
public bool Temporary { get; set; }
13+
14+
[JsonProperty("uses")]
15+
public int Uses { get; set; }
16+
17+
[JsonProperty("max_uses")]
18+
public int MaxUses { get; set; }
19+
20+
[JsonProperty("max_age")]
21+
public int MaxAge { get; set; }
22+
23+
[JsonProperty("created_at")]
24+
public DateTime CreatedAt { get; set; }
25+
26+
[JsonProperty("expires_at")]
27+
public DateTime ExpiresAt { get; set; }
28+
29+
[JsonProperty("guild_id")]
30+
public string GuildId { get; set; }
31+
32+
[JsonProperty("channel_id")]
33+
public string ChannelId { get; set; }
34+
35+
[JsonProperty("inviter_id")]
36+
public string InviterId { get; set; }
37+
38+
[JsonProperty("target_user_id")]
39+
public object TargetUserId { get; set; }
40+
41+
[JsonProperty("target_user_type")]
42+
public object TargetUserType { get; set; }
43+
44+
[JsonProperty("vanity_url")]
45+
public object VanityUrl { get; set; }
46+
47+
[JsonProperty("guild")]
48+
public Guild Guild { get; set; }
49+
50+
[JsonProperty("channel")]
51+
public Channel Channel { get; set; }
52+
53+
// [JsonProperty("inviter")]
54+
// public Inviter Inviter { get; set; }
55+
}
56+
}

0 commit comments

Comments
 (0)