Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nerzh/telegram-vapor-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Jul 1, 2024
2 parents 62fa499 + be5a524 commit 7d77718
Show file tree
Hide file tree
Showing 36 changed files with 52 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Api/generate_wrappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,25 @@ def generate_enum_type(type_name, custom_type_description, type_description)
out.write " */\n\n"

out.write "public enum #{custom_type_name}: String, Codable {\n"
descr = custom_type_description
regexp = /(“.+?”|".+?")/
while descr[regexp] do
enum_case = $1
enum_case.gsub!(/(“|”|")/, '')
descr.sub!(regexp, '')
reserved_names = ['private', 'public']
case_name = "#{enum_case.camel_case_lower}"
if reserved_names.include?(enum_case)
case_name = "`#{enum_case.camel_case_lower}`"

cases = search_cases_for_enum_type_of_variable_with_type_name(custom_type_description)
reserved_names = [
'associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate', 'func', 'import', 'init',
'inout', 'internal', 'let', 'open', 'operator', 'private', 'precedencegroup', 'protocol', 'public',
'rethrows', 'static', 'struct', 'subscript', 'typealias', 'var', 'break', 'case', 'catch', 'continue',
'default', 'defer', 'do', 'else', 'fallthrough', 'for', 'guard', 'if', 'in', 'repeat', 'return',
'throw', 'switch', 'where', 'while', 'any', 'as', 'await', 'catch', 'false', 'is', 'nil', 'rethrows',
'self', 'super', 'throw', 'throws', 'true', 'try'
]
cases.each do |case_name|
case_value = case_name.clone
case_name = "#{case_name.camel_case_lower}"
if reserved_names.include?(case_name)
case_name = "`#{case_name.camel_case_lower}`"
end
case_value = enum_case
out.write "#{ONE}case #{case_name} = \"#{case_value}\"\n"
end

out.write "#{ONE}case undefined\n"
out.write "\n"
out.write "#{ONE}public init(from decoder: Decoder) throws {\n"
Expand Down Expand Up @@ -584,6 +589,7 @@ def make_getter_name(type_name, var_name, var_type, var_desc)
private def search_cases_for_enum_type_of_variable_with_type_name(var_description)
var_desc = var_description.clone
result_types = []
# p var_desc
if var_desc[/must be\s+(.+)/]
case_name = $1
result_types << case_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeAllChatAdministratorsType: String, Codable {
case allChatAdministrators = "all_chat_administrators"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeAllGroupChatsType: String, Codable {
case allGroupChats = "all_group_chats"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeAllPrivateChatsType: String, Codable {
case allPrivateChats = "all_private_chats"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeChatAdministratorsType: String, Codable {
case chatAdministrators = "chat_administrators"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeChatMemberType: String, Codable {
case chatMember = "chat_member"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeChatType: String, Codable {
case chat = "chat"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGBotCommandScopeDefaultType: String, Codable {
case `default` = "default"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultArticleType: String, Codable {
case article = "article"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultAudioType: String, Codable {
case audio = "audio"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedAudioType: String, Codable {
case audio = "audio"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedDocumentType: String, Codable {
case document = "document"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedGifType: String, Codable {
case gif = "gif"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedMpeg4GifType: String, Codable {
case mpeg4Gif = "mpeg4_gif"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedPhotoType: String, Codable {
case photo = "photo"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedStickerType: String, Codable {
case sticker = "sticker"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedVideoType: String, Codable {
case video = "video"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultCachedVoiceType: String, Codable {
case voice = "voice"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultContactType: String, Codable {
case contact = "contact"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultDocumentType: String, Codable {
case document = "document"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultGameType: String, Codable {
case game = "game"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultGifType: String, Codable {
case gif = "gif"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultLocationType: String, Codable {
case location = "location"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultMpeg4GifType: String, Codable {
case mpeg4Gif = "mpeg4_gif"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultPhotoType: String, Codable {
case photo = "photo"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultVenueType: String, Codable {
case venue = "venue"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

public enum TGInlineQueryResultVideoType: String, Codable {
case video = "video"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInlineQueryResultVoiceType: String, Codable {
case voice = "voice"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInputMediaAnimationType: String, Codable {
case animation = "animation"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInputMediaAudioType: String, Codable {
case audio = "audio"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInputMediaDocumentType: String, Codable {
case document = "document"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInputMediaPhotoType: String, Codable {
case photo = "photo"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGInputMediaVideoType: String, Codable {
case video = "video"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGMenuButtonCommandsType: String, Codable {
case commands = "commands"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGMenuButtonDefaultType: String, Codable {
case `default` = "default"
case undefined

public init(from decoder: Decoder) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

public enum TGMenuButtonWebAppType: String, Codable {
case webApp = "web_app"
case undefined

public init(from decoder: Decoder) throws {
Expand Down

0 comments on commit 7d77718

Please sign in to comment.