Skip to content

Commit

Permalink
testing with enum
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 30, 2024
1 parent 4cf85d2 commit 54b5a07
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Future<void> main() async {
// Sick of boilerplates? Reply messages like below, nice and tidy
// Short hands also available for answer query methods
teledart.onCommand('glory').listen((message) => message.reply('to Ukraine!'));
teledart.onCommand('dice').listen((message) => message.replyDice(emoji: DiceEmoji.slotMachine));

// You can also utilise regular expressions
teledart
Expand Down
3 changes: 2 additions & 1 deletion lib/src/teledart/model/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ class TeleDartMessage extends Message {
Future<Message> replyDice({
int? messageThreadId,
bool withQuote = false,
String emoji = Dice.emojiDice,
// String emoji = Dice.emojiDice,
DiceEmoji emoji = DiceEmoji.dice,
bool? disableNotification,
bool? allowSendingWithoutReply,
ReplyMarkup? replyMarkup,
Expand Down
13 changes: 11 additions & 2 deletions lib/src/telegram/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion lib/src/telegram/models/dice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ part of '../model.dart';
/// This object represents an animated emoji that displays a random value.
///
/// https://core.telegram.org/bots/api#dice
@JsonEnum()
enum DiceEmoji {
@JsonValue('🎲')
dice,
@JsonValue('🎯')
dart,
@JsonValue('🎳')
bowling,
@JsonValue('🏀')
basketball,
@JsonValue('⚽')
football,
@JsonValue('🎰')
slotMachine
}

extension DiceEmojiExtenson on DiceEmoji {
String getEmoji() => _$DiceEmojiEnumMap[this] ?? '🎲';
}

@JsonSerializable(fieldRename: FieldRename.snake)
class Dice {
static const emojiDice = '🎲';
Expand All @@ -31,7 +51,8 @@ class Dice {
static const emojiSlotMachine = '🎰';

int value;
String emoji;
// String emoji;
DiceEmoji emoji;
Dice({
required this.value,
required this.emoji,
Expand Down
5 changes: 3 additions & 2 deletions lib/src/telegram/telegram.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,8 @@ class Telegram {
/// On success, the sent [Message] is returned.
Future<Message> sendDice(dynamic chatId,
{int? messageThreadId,
String emoji = Dice.emojiDice,
// String emoji = Dice.emojiDice,
DiceEmoji emoji = DiceEmoji.dice,
bool? disableNotification,
bool? protectContent,
int? replyToMessageId,
Expand All @@ -1065,7 +1066,7 @@ class Telegram {
var body = <String, dynamic>{
'chat_id': chatId,
'message_thread_id': messageThreadId,
'emoji': emoji,
'emoji': emoji.getEmoji(),
'disable_notification': disableNotification,
'protect_content': protectContent,
'reply_to_message_id': replyToMessageId,
Expand Down

0 comments on commit 54b5a07

Please sign in to comment.