Skip to content

Commit

Permalink
use enum in bot command scope
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 31, 2024
1 parent bba3764 commit 8a8655b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- support Telegram API 6.9
- **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`, `PassportElementError` to use enum for `type`
- **Breaking** Updated class `Dice`, `InlineQueryResult`, `MenuButton`, `PassportElementError`, `InputMedia`, `InputMediaWithThumbnail`, `BotCommandScope` to use enum for `type`

## 0.6.1

Expand Down
32 changes: 23 additions & 9 deletions lib/src/telegram/models/bot_command_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@

part of '../model.dart';

@JsonEnum()
enum BotCommandScopeType {
@JsonValue('default')
defaultCommand,
@JsonValue('all_private_chats')
allPrivateChats,
@JsonValue('all_group_chats')
allGroupChats,
@JsonValue('all_chat_administrators')
allChatAdministrators,
@JsonValue('chat')
chat,
@JsonValue('chat_administrators')
chatAdministrators,
@JsonValue('chat_member')
chatMember,
}

extension BotCommandScopeTypeExtenson on BotCommandScopeType {
String value() => _$BotCommandScopeTypeEnumMap[this]!;
}

/// This object represents the scope to which bot commands are applied.
///
/// Currently, the following 7 scopes are supported:
Expand All @@ -32,15 +54,7 @@ part of '../model.dart';
/// https://core.telegram.org/bots/api#botcommandscope
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScope {
static const typeDefault = 'default';
static const typeAllPrivateChats = 'all_private_chats';
static const typeAllGroupChats = 'all_group_chats';
static const typeAllChatAdministrators = 'all_chat_administrators';
static const typeChat = 'chat';
static const typeChatAdministrators = 'chat_administrators';
static const typeChatMember = 'chat_member';

String type;
BotCommandScopeType type;

BotCommandScope({required this.type});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeAllChatAdministrators implements BotCommandScope {
@override
String type;
BotCommandScopeType type;

BotCommandScopeAllChatAdministrators(
{this.type = BotCommandScope.typeAllChatAdministrators});
{this.type = BotCommandScopeType.allChatAdministrators});

factory BotCommandScopeAllChatAdministrators.fromJson(
Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeAllGroupChats implements BotCommandScope {
@override
String type;
BotCommandScopeType type;

BotCommandScopeAllGroupChats({this.type = BotCommandScope.typeAllGroupChats});
BotCommandScopeAllGroupChats({this.type = BotCommandScopeType.allGroupChats});

factory BotCommandScopeAllGroupChats.fromJson(Map<String, dynamic> json) =>
_$BotCommandScopeAllGroupChatsFromJson(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeAllPrivateChats implements BotCommandScope {
@override
String type;
BotCommandScopeType type;

BotCommandScopeAllPrivateChats(
{this.type = BotCommandScope.typeAllPrivateChats});
{this.type = BotCommandScopeType.allPrivateChats});

factory BotCommandScopeAllPrivateChats.fromJson(Map<String, dynamic> json) =>
_$BotCommandScopeAllPrivateChatsFromJson(json);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/bot_command_scope_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeChat implements BotCommandScope {
@override
String type;
BotCommandScopeType type;
dynamic chatId;

BotCommandScopeChat({
this.type = BotCommandScope.typeChat,
this.type = BotCommandScopeType.chat,
required this.chatId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeChatAdministrators implements BotCommandScope {
@override
String type;
BotCommandScopeType type;
dynamic chatId;

BotCommandScopeChatAdministrators({
this.type = BotCommandScope.typeAllChatAdministrators,
this.type = BotCommandScopeType.allChatAdministrators,
required this.chatId,
});

Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/bot_command_scope_chat_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeChatMember implements BotCommandScope {
@override
String type;
BotCommandScopeType type;
dynamic chatId;

BotCommandScopeChatMember({
this.type = BotCommandScope.typeChatMember,
this.type = BotCommandScopeType.chatMember,
required this.chatId,
});

Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/bot_command_scope_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class BotCommandScopeDefault implements BotCommandScope {
@override
String type;
BotCommandScopeType type;

BotCommandScopeDefault({this.type = BotCommandScope.typeDefault});
BotCommandScopeDefault({this.type = BotCommandScopeType.defaultCommand});

factory BotCommandScopeDefault.fromJson(Map<String, dynamic> json) =>
_$BotCommandScopeDefaultFromJson(json);
Expand Down

0 comments on commit 8a8655b

Please sign in to comment.