Skip to content

Commit

Permalink
use enum in menu button
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 31, 2024
1 parent e46f659 commit c48e834
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## unreleased

- support Telegram API 6.9
- **Breaking** Updated class `Dice`, function `telegram:Telegram.sendDice` and function `teledart:Message.replyDice` to accept enum of `DiceEmoji` instead of emoji string
- **Breaking** Updated class `InlineQueryResult` to use enum for `type`
- **Breaking** Updated function `telegram:Telegram.sendDice` and function `teledart:Message.replyDice` to accept enum of `DiceEmoji` instead of emoji string
- **Breaking** Updated class `Dice`, `InlineQueryResult`, `MenuButton` to use enum for `type`

## 0.6.1

Expand Down
51 changes: 25 additions & 26 deletions lib/src/telegram/models/inline_query_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@

part of '../model.dart';

/// This object represents one result of an inline query.
///
/// Telegram clients currently support results of the following 20 types:
/// * [InlineQueryResultCachedAudio](https://core.telegram.org/bots/api#inlinequeryresultcachedaudio)
/// * [InlineQueryResultCachedDocument](https://core.telegram.org/bots/api#inlinequeryresultcacheddocument)
/// * [InlineQueryResultCachedGif](https://core.telegram.org/bots/api#inlinequeryresultcachedgif)
/// * [InlineQueryResultCachedMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif)
/// * [InlineQueryResultCachedPhoto](https://core.telegram.org/bots/api#inlinequeryresultcachedphoto)
/// * [InlineQueryResultCachedSticker](https://core.telegram.org/bots/api#inlinequeryresultcachedsticker)
/// * [InlineQueryResultCachedVideo](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo)
/// * [InlineQueryResultCachedVoice](https://core.telegram.org/bots/api#inlinequeryresultcachedvoice)
/// * [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle)
/// * [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio)
/// * [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact)
/// * [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame)
/// * [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument)
/// * [InlineQueryResultGif](https://core.telegram.org/bots/api#inlinequeryresultgif)
/// * [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation)
/// * [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif)
/// * [InlineQueryResultPhoto](https://core.telegram.org/bots/api#inlinequeryresultphoto)
/// * [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue)
/// * [InlineQueryResultVideo](https://core.telegram.org/bots/api#inlinequeryresultvideo)
/// * [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice)
///
/// https://core.telegram.org/bots/api#inlinequeryresult
@JsonEnum()
enum InlineQueryResultType {
@JsonValue('article')
Expand Down Expand Up @@ -78,6 +52,31 @@ extension InlineQueryResultTypeExtenson on InlineQueryResultType {
String value() => _$InlineQueryResultTypeEnumMap[this]!;
}

/// This object represents one result of an inline query.
///
/// Telegram clients currently support results of the following 20 types:
/// * [InlineQueryResultCachedAudio](https://core.telegram.org/bots/api#inlinequeryresultcachedaudio)
/// * [InlineQueryResultCachedDocument](https://core.telegram.org/bots/api#inlinequeryresultcacheddocument)
/// * [InlineQueryResultCachedGif](https://core.telegram.org/bots/api#inlinequeryresultcachedgif)
/// * [InlineQueryResultCachedMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif)
/// * [InlineQueryResultCachedPhoto](https://core.telegram.org/bots/api#inlinequeryresultcachedphoto)
/// * [InlineQueryResultCachedSticker](https://core.telegram.org/bots/api#inlinequeryresultcachedsticker)
/// * [InlineQueryResultCachedVideo](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo)
/// * [InlineQueryResultCachedVoice](https://core.telegram.org/bots/api#inlinequeryresultcachedvoice)
/// * [InlineQueryResultArticle](https://core.telegram.org/bots/api#inlinequeryresultarticle)
/// * [InlineQueryResultAudio](https://core.telegram.org/bots/api#inlinequeryresultaudio)
/// * [InlineQueryResultContact](https://core.telegram.org/bots/api#inlinequeryresultcontact)
/// * [InlineQueryResultGame](https://core.telegram.org/bots/api#inlinequeryresultgame)
/// * [InlineQueryResultDocument](https://core.telegram.org/bots/api#inlinequeryresultdocument)
/// * [InlineQueryResultGif](https://core.telegram.org/bots/api#inlinequeryresultgif)
/// * [InlineQueryResultLocation](https://core.telegram.org/bots/api#inlinequeryresultlocation)
/// * [InlineQueryResultMpeg4Gif](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif)
/// * [InlineQueryResultPhoto](https://core.telegram.org/bots/api#inlinequeryresultphoto)
/// * [InlineQueryResultVenue](https://core.telegram.org/bots/api#inlinequeryresultvenue)
/// * [InlineQueryResultVideo](https://core.telegram.org/bots/api#inlinequeryresultvideo)
/// * [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice)
///
/// https://core.telegram.org/bots/api#inlinequeryresult
@JsonSerializable(fieldRename: FieldRename.snake)
class InlineQueryResult {
static const typeArticle = 'article';
Expand Down
20 changes: 15 additions & 5 deletions lib/src/telegram/models/menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@

part of '../model.dart';

@JsonEnum()
enum MenuButtonType {
@JsonValue('commands')
commands,
@JsonValue('web_app')
webApp,
@JsonValue('default')
defaultButton,
}

extension MenuButtonTypeExtenson on MenuButtonType {
String value() => _$MenuButtonTypeEnumMap[this]!;
}

/// This object describes the bot's menu button in a private chat. It should be one of
/// - [MenuButtonCommands]
/// - [MenuButtonWebApp]
Expand All @@ -30,11 +44,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class MenuButton {
static const typeCommands = 'commands';
static const typeWebApp = 'web_app';
static const typeDefault = 'default';

String type;
MenuButtonType type;
MenuButton({required this.type});
factory MenuButton.fromJson(Map<String, dynamic> json) =>
_$MenuButtonFromJson(json);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/menu_button_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class MenuButtonCommands implements MenuButton {
@override
String type;
MenuButtonCommands({this.type = MenuButton.typeCommands});
MenuButtonType type;
MenuButtonCommands({this.type = MenuButtonType.commands});
factory MenuButtonCommands.fromJson(Map<String, dynamic> json) =>
_$MenuButtonCommandsFromJson(json);
@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/menu_button_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class MenuButtonDefault implements MenuButton {
@override
String type;
MenuButtonDefault({this.type = MenuButton.typeDefault});
MenuButtonType type;
MenuButtonDefault({this.type = MenuButtonType.defaultButton});
factory MenuButtonDefault.fromJson(Map<String, dynamic> json) =>
_$MenuButtonDefaultFromJson(json);
@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/menu_button_web_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class MenuButtonWebApp implements MenuButton {
@override
String type;
MenuButtonType type;
String text;
WebAppInfo webApp;
MenuButtonWebApp(
{this.type = MenuButton.typeWebApp,
{this.type = MenuButtonType.webApp,
required this.text,
required this.webApp});
factory MenuButtonWebApp.fromJson(Map<String, dynamic> json) =>
Expand Down

0 comments on commit c48e834

Please sign in to comment.