mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[quote] Crappy chat quote implementation.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#nullable enable
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Telegram.Bot.Types;
|
||||
using File = Telegram.Bot.Types.File;
|
||||
|
||||
namespace West.TelegramBot.ChatQuotes.Model;
|
||||
|
||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
||||
public class QuoteRequest
|
||||
{
|
||||
public QuoteRequest(Message msg)
|
||||
{
|
||||
// TODO: move default values to config
|
||||
Format = "webp";
|
||||
BackgroundColor = "#1b1429";
|
||||
Width = 512;
|
||||
Height = 768;
|
||||
Scale = 2;
|
||||
|
||||
Messages = new List<QuoteMessage> {QuoteMessage.FromMessage(msg)};
|
||||
}
|
||||
|
||||
public QuoteType Type { get; set; }
|
||||
public string Format { get; set; }
|
||||
public string BackgroundColor { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public int Scale { get; set; }
|
||||
public List<QuoteMessage>? Messages { get; set; }
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, ChatQuotes.SerializerSettings);
|
||||
}
|
||||
}
|
||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
||||
public class QuoteMessage
|
||||
{
|
||||
public List<File>? Media { get; set; }
|
||||
public QuoteMediaType? MediaType { get; set; }
|
||||
public long ChatId { get; set; }
|
||||
public bool Avatar { get; set; } = true;
|
||||
public User? From { get; set; }
|
||||
public string? Text { get; set; }
|
||||
public Message? ReplyMessage { get; set; }
|
||||
|
||||
public static QuoteMessage FromMessage(Message msg)
|
||||
{
|
||||
var quoteMessage = new QuoteMessage();
|
||||
|
||||
if (msg.Text != null)
|
||||
{
|
||||
quoteMessage.Text = msg.Text;
|
||||
}
|
||||
|
||||
var sticker = msg.Sticker;
|
||||
if (sticker != null)
|
||||
{
|
||||
var file = new File
|
||||
{
|
||||
FileId = sticker.FileId,
|
||||
FileSize = sticker.FileSize,
|
||||
FileUniqueId = sticker.FileUniqueId
|
||||
};
|
||||
quoteMessage.Media = new List<File> {file};
|
||||
quoteMessage.MediaType = QuoteMediaType.Sticker;
|
||||
}
|
||||
|
||||
quoteMessage.ChatId = msg.Chat.Id;
|
||||
quoteMessage.ReplyMessage = msg.ReplyToMessage;
|
||||
quoteMessage.From = User.FromTgUser(msg.From!);
|
||||
|
||||
return quoteMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public enum QuoteMediaType
|
||||
{
|
||||
Sticker = 0
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#nullable disable
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace West.TelegramBot.ChatQuotes.Model;
|
||||
|
||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
||||
public class QuoteResponse
|
||||
{
|
||||
public bool Ok { get; set; }
|
||||
|
||||
public Result Result { get; set; }
|
||||
public static QuoteResponse FromJson(string json)
|
||||
=> JsonConvert.DeserializeObject<QuoteResponse>(json, ChatQuotes.SerializerSettings);
|
||||
}
|
||||
|
||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
||||
public class Result
|
||||
{
|
||||
public string Image { get; set; }
|
||||
|
||||
public QuoteType Type { get; set; }
|
||||
|
||||
public long Width { get; set; }
|
||||
|
||||
public long Height { get; set; }
|
||||
}
|
||||
|
||||
public enum QuoteType
|
||||
{
|
||||
Quote = 0,
|
||||
Image,
|
||||
Null
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace West.TelegramBot.ChatQuotes.Model;
|
||||
|
||||
public class User : Telegram.Bot.Types.User
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Name => LastName != null ? $"{FirstName} {LastName}" : FirstName;
|
||||
|
||||
public static User FromTgUser(Telegram.Bot.Types.User user)
|
||||
{
|
||||
return new User
|
||||
{
|
||||
Id = user.Id,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
Username = user.Username,
|
||||
LanguageCode = user.LanguageCode,
|
||||
IsBot = user.IsBot
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user