Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 42a4368

Browse files
committed
tdlib updated to 1.8.37
1 parent 0695602 commit 42a4368

File tree

2,461 files changed

+127332
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,461 files changed

+127332
-33
lines changed

TdLib.Api/Client.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-FileCopyrightText: 2024 tdsharp contributors <https://github.com/egramtel/tdsharp>
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
using System.Threading.Tasks;
6+
7+
namespace TdLib
8+
{
9+
public static partial class TdApi
10+
{
11+
/// <summary>
12+
/// Base class for API client
13+
/// </summary>
14+
public abstract class Client : Object
15+
{
16+
public abstract void Send<TResut>(Function<TResut> function);
17+
18+
public abstract TResult Execute<TResult>(Function<TResult> function)
19+
where TResult : Object;
20+
21+
public abstract Task<TResult> ExecuteAsync<TResult>(Function<TResult> function)
22+
where TResult : Object;
23+
}
24+
}
25+
}

TdLib.Api/Converter.cs

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-FileCopyrightText: 2024 tdsharp contributors <https://github.com/egramtel/tdsharp>
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Reflection;
9+
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Linq;
11+
12+
namespace TdLib
13+
{
14+
public class Converter : JsonConverter
15+
{
16+
private static Assembly _assembly;
17+
private static Dictionary<string, Type> _mapper;
18+
19+
static Converter()
20+
{
21+
_assembly = typeof(Converter).Assembly;
22+
_mapper = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
23+
24+
foreach (var type in _assembly.GetExportedTypes())
25+
{
26+
_mapper.Add(type.Name, type);
27+
}
28+
}
29+
30+
public override bool CanRead => true;
31+
32+
public override bool CanWrite => false;
33+
34+
public override bool CanConvert(Type type)
35+
{
36+
return _mapper.ContainsKey(type.Name);
37+
}
38+
39+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
40+
JsonSerializer serializer)
41+
{
42+
var jToken = JToken.Load(reader);
43+
44+
if (jToken.Type == JTokenType.Object)
45+
{
46+
var jObject = (JObject) jToken;
47+
48+
var typeProp = jObject["@type"];
49+
if (typeProp != null)
50+
{
51+
var typeName = (string) typeProp;
52+
if (typeName != null && _mapper.TryGetValue(typeName, out var type))
53+
{
54+
return jObject.ToObject(type);
55+
}
56+
}
57+
}
58+
59+
return jToken.ToObject(objectType);
60+
}
61+
62+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
63+
{
64+
throw new NotImplementedException();
65+
}
66+
67+
public class Int64 : JsonConverter
68+
{
69+
public override bool CanRead => true;
70+
71+
public override bool CanWrite => true;
72+
73+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
74+
JsonSerializer serializer)
75+
{
76+
var token = JToken.ReadFrom(reader);
77+
if (token.Type == JTokenType.Array)
78+
{
79+
var arr = (JArray) token;
80+
var res = new long[arr.Count];
81+
82+
for (int i = 0; i < arr.Count; i++)
83+
{
84+
res[i] = arr[i].Value<long>();
85+
}
86+
87+
return res;
88+
}
89+
90+
if (token.Type == JTokenType.Integer || token.Type == JTokenType.String)
91+
{
92+
return token.Value<long>();
93+
}
94+
95+
return null;
96+
}
97+
98+
public override bool CanConvert(Type objectType)
99+
{
100+
return objectType == typeof(long)
101+
|| objectType == typeof(long[]);
102+
}
103+
104+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
105+
{
106+
if (value is long val)
107+
{
108+
serializer.Serialize(writer, val.ToString());
109+
}
110+
else if (value is long[] arr)
111+
{
112+
serializer.Serialize(writer, arr.Select(v => v.ToString()).ToArray());
113+
}
114+
}
115+
}
116+
}
117+
}

TdLib.Api/Function.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-FileCopyrightText: 2024 tdsharp contributors <https://github.com/egramtel/tdsharp>
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
using System.Threading.Tasks;
6+
7+
namespace TdLib
8+
{
9+
public static partial class TdApi
10+
{
11+
/// <summary>
12+
/// Base class for all functions
13+
/// </summary>
14+
/// <typeparam name="T">Return type for this function</typeparam>
15+
public abstract class Function<T> : Object
16+
{
17+
}
18+
}
19+
}

TdLib.Api/Functions/AcceptCall.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Newtonsoft.Json;
4+
5+
// REUSE-IgnoreStart
6+
namespace TdLib
7+
{
8+
/// <summary>
9+
/// Autogenerated TDLib APIs
10+
/// </summary>
11+
public static partial class TdApi
12+
{
13+
/// <summary>
14+
/// Accepts an incoming call
15+
/// </summary>
16+
public class AcceptCall : Function<Ok>
17+
{
18+
/// <summary>
19+
/// Data type for serialization
20+
/// </summary>
21+
[JsonProperty("@type")]
22+
public override string DataType { get; set; } = "acceptCall";
23+
24+
/// <summary>
25+
/// Extra data attached to the function
26+
/// </summary>
27+
[JsonProperty("@extra")]
28+
public override string Extra { get; set; }
29+
30+
/// <summary>
31+
/// Call identifier
32+
/// </summary>
33+
[JsonConverter(typeof(Converter))]
34+
[JsonProperty("call_id")]
35+
public int CallId { get; set; }
36+
37+
/// <summary>
38+
/// The call protocols supported by the application
39+
/// </summary>
40+
[JsonConverter(typeof(Converter))]
41+
[JsonProperty("protocol")]
42+
public CallProtocol Protocol { get; set; }
43+
}
44+
45+
/// <summary>
46+
/// Accepts an incoming call
47+
/// </summary>
48+
public static Task<Ok> AcceptCallAsync(
49+
this Client client, int callId = default, CallProtocol protocol = default)
50+
{
51+
return client.ExecuteAsync(new AcceptCall
52+
{
53+
CallId = callId, Protocol = protocol
54+
});
55+
}
56+
}
57+
}
58+
// REUSE-IgnoreEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Newtonsoft.Json;
4+
5+
// REUSE-IgnoreStart
6+
namespace TdLib
7+
{
8+
/// <summary>
9+
/// Autogenerated TDLib APIs
10+
/// </summary>
11+
public static partial class TdApi
12+
{
13+
/// <summary>
14+
/// Accepts Telegram terms of services
15+
/// </summary>
16+
public class AcceptTermsOfService : Function<Ok>
17+
{
18+
/// <summary>
19+
/// Data type for serialization
20+
/// </summary>
21+
[JsonProperty("@type")]
22+
public override string DataType { get; set; } = "acceptTermsOfService";
23+
24+
/// <summary>
25+
/// Extra data attached to the function
26+
/// </summary>
27+
[JsonProperty("@extra")]
28+
public override string Extra { get; set; }
29+
30+
/// <summary>
31+
/// Terms of service identifier
32+
/// </summary>
33+
[JsonConverter(typeof(Converter))]
34+
[JsonProperty("terms_of_service_id")]
35+
public string TermsOfServiceId { get; set; }
36+
}
37+
38+
/// <summary>
39+
/// Accepts Telegram terms of services
40+
/// </summary>
41+
public static Task<Ok> AcceptTermsOfServiceAsync(
42+
this Client client, string termsOfServiceId = default)
43+
{
44+
return client.ExecuteAsync(new AcceptTermsOfService
45+
{
46+
TermsOfServiceId = termsOfServiceId
47+
});
48+
}
49+
}
50+
}
51+
// REUSE-IgnoreEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Newtonsoft.Json;
4+
5+
// REUSE-IgnoreStart
6+
namespace TdLib
7+
{
8+
/// <summary>
9+
/// Autogenerated TDLib APIs
10+
/// </summary>
11+
public static partial class TdApi
12+
{
13+
/// <summary>
14+
/// Activates stealth mode for stories, which hides all views of stories from the current user in the last "story_stealth_mode_past_period" seconds
15+
/// and for the next "story_stealth_mode_future_period" seconds; for Telegram Premium users only
16+
/// </summary>
17+
public class ActivateStoryStealthMode : Function<Ok>
18+
{
19+
/// <summary>
20+
/// Data type for serialization
21+
/// </summary>
22+
[JsonProperty("@type")]
23+
public override string DataType { get; set; } = "activateStoryStealthMode";
24+
25+
/// <summary>
26+
/// Extra data attached to the function
27+
/// </summary>
28+
[JsonProperty("@extra")]
29+
public override string Extra { get; set; }
30+
31+
32+
}
33+
34+
/// <summary>
35+
/// Activates stealth mode for stories, which hides all views of stories from the current user in the last "story_stealth_mode_past_period" seconds
36+
/// and for the next "story_stealth_mode_future_period" seconds; for Telegram Premium users only
37+
/// </summary>
38+
public static Task<Ok> ActivateStoryStealthModeAsync(
39+
this Client client)
40+
{
41+
return client.ExecuteAsync(new ActivateStoryStealthMode
42+
{
43+
44+
});
45+
}
46+
}
47+
}
48+
// REUSE-IgnoreEnd
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Newtonsoft.Json;
4+
5+
// REUSE-IgnoreStart
6+
namespace TdLib
7+
{
8+
/// <summary>
9+
/// Autogenerated TDLib APIs
10+
/// </summary>
11+
public static partial class TdApi
12+
{
13+
/// <summary>
14+
/// Adds a new media preview to the beginning of the list of media previews of a bot. Returns the added preview after addition is completed server-side. The total number of previews must not exceed getOption("bot_media_preview_count_max") for the given language
15+
/// </summary>
16+
public class AddBotMediaPreview : Function<BotMediaPreview>
17+
{
18+
/// <summary>
19+
/// Data type for serialization
20+
/// </summary>
21+
[JsonProperty("@type")]
22+
public override string DataType { get; set; } = "addBotMediaPreview";
23+
24+
/// <summary>
25+
/// Extra data attached to the function
26+
/// </summary>
27+
[JsonProperty("@extra")]
28+
public override string Extra { get; set; }
29+
30+
/// <summary>
31+
/// Identifier of the target bot. The bot must be owned and must have the main Web App
32+
/// </summary>
33+
[JsonConverter(typeof(Converter))]
34+
[JsonProperty("bot_user_id")]
35+
public long BotUserId { get; set; }
36+
37+
/// <summary>
38+
/// A two-letter ISO 639-1 language code for which preview is added. If empty, then the preview will be shown to all users for whose languages there are no dedicated previews.
39+
/// If non-empty, then there must be an official language pack of the same name, which is returned by getLocalizationTargetInfo
40+
/// </summary>
41+
[JsonConverter(typeof(Converter))]
42+
[JsonProperty("language_code")]
43+
public string LanguageCode { get; set; }
44+
45+
/// <summary>
46+
/// Content of the added preview
47+
/// </summary>
48+
[JsonConverter(typeof(Converter))]
49+
[JsonProperty("content")]
50+
public InputStoryContent Content { get; set; }
51+
}
52+
53+
/// <summary>
54+
/// Adds a new media preview to the beginning of the list of media previews of a bot. Returns the added preview after addition is completed server-side. The total number of previews must not exceed getOption("bot_media_preview_count_max") for the given language
55+
/// </summary>
56+
public static Task<BotMediaPreview> AddBotMediaPreviewAsync(
57+
this Client client, long botUserId = default, string languageCode = default, InputStoryContent content = default)
58+
{
59+
return client.ExecuteAsync(new AddBotMediaPreview
60+
{
61+
BotUserId = botUserId, LanguageCode = languageCode, Content = content
62+
});
63+
}
64+
}
65+
}
66+
// REUSE-IgnoreEnd

0 commit comments

Comments
 (0)