Skip to content

Commit

Permalink
Merge pull request #693 from pangeachat/689-fix-bot-dialog-kicks-the-…
Browse files Browse the repository at this point in the history
…bot-undesirably

fix bot dialog confirm kicks the bot undesirably
  • Loading branch information
wcjord authored Sep 20, 2024
2 parents da3a936 + bbe7ca7 commit 09e15c3
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 45 deletions.
1 change: 1 addition & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4014,6 +4014,7 @@
"conversationBotModeSelectOption_custom": "Custom",
"conversationBotModeSelectOption_conversation": "Conversation",
"conversationBotModeSelectOption_textAdventure": "Text Adventure",
"conversationBotModeSelectOption_storyGame": "Story Game",
"conversationBotDiscussionZone_title": "Discussion Settings",
"conversationBotDiscussionZone_discussionTopicLabel": "Discussion Topic",
"conversationBotDiscussionZone_discussionTopicPlaceholder": "Set Discussion Topic",
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/new_group/new_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:typed_data';

import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/pages/new_group/new_group_view.dart';
import 'package:fluffychat/pangea/constants/bot_mode.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
import 'package:fluffychat/pangea/models/chat_topic_model.dart';
Expand Down Expand Up @@ -108,7 +109,7 @@ class NewGroupController extends State<NewGroup> {
final addBot = addConversationBotKey.currentState?.addBot ?? false;
if (addBot) {
final botOptions = addConversationBotKey.currentState!.botOptions;
if (botOptions.mode == "custom") {
if (botOptions.mode == BotMode.custom) {
if (botOptions.customSystemPrompt == null ||
botOptions.customSystemPrompt!.isEmpty) {
setState(() {
Expand All @@ -118,7 +119,7 @@ class NewGroupController extends State<NewGroup> {
});
return;
}
} else if (botOptions.mode == "text_adventure") {
} else if (botOptions.mode == BotMode.textAdventure) {
if (botOptions.textAdventureGameMasterInstructions == null ||
botOptions.textAdventureGameMasterInstructions!.isEmpty) {
setState(() {
Expand Down
6 changes: 6 additions & 0 deletions lib/pangea/constants/bot_mode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class BotMode {
static const discussion = "discussion";
static const custom = "custom";
static const storyGame = "story_game";
static const textAdventure = "text_adventure";
}
8 changes: 4 additions & 4 deletions lib/pangea/models/bot_options_model.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'dart:developer';

import 'package:fluffychat/pangea/constants/bot_mode.dart';
import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:flutter/foundation.dart';
import 'package:matrix/matrix.dart';

import '../constants/pangea_event_types.dart';

class BotOptionsModel {
int? languageLevel;
String topic;
Expand All @@ -30,7 +30,7 @@ class BotOptionsModel {
this.topic = "General Conversation",
this.keywords = const [],
this.safetyModeration = true,
this.mode = "discussion",
this.mode = BotMode.discussion,

////////////////////////////////////////////////////////////////////////////
// Discussion Mode Options
Expand Down Expand Up @@ -62,7 +62,7 @@ class BotOptionsModel {
? json[ModelKey.languageLevel]
: null,
safetyModeration: json[ModelKey.safetyModeration] ?? true,
mode: json[ModelKey.mode] ?? "discussion",
mode: json[ModelKey.mode] ?? BotMode.discussion,

//////////////////////////////////////////////////////////////////////////
// Discussion Mode Options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fluffychat/pangea/constants/bot_mode.dart';
import 'package:fluffychat/pangea/models/bot_options_model.dart';
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_custom_zone.dart';
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_text_adventure_zone.dart';
import 'package:flutter/material.dart';

import 'conversation_bot_discussion_zone.dart';
Expand All @@ -18,20 +18,18 @@ class ConversationBotModeDynamicZone extends StatelessWidget {
@override
Widget build(BuildContext context) {
final zoneMap = {
'discussion': ConversationBotDiscussionZone(
BotMode.discussion: ConversationBotDiscussionZone(
initialBotOptions: initialBotOptions,
onChanged: onChanged,
),
"custom": ConversationBotCustomZone(
initialBotOptions: initialBotOptions,
onChanged: onChanged,
),
// "conversation": const ConversationBotConversationZone(),
"text_adventure": ConversationBotTextAdventureZone(
BotMode.custom: ConversationBotCustomZone(
initialBotOptions: initialBotOptions,
onChanged: onChanged,
),
};
if (!zoneMap.containsKey(initialBotOptions.mode)) {
return Container();
}
return Container(
decoration: BoxDecoration(
border: Border.all(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fluffychat/pangea/constants/bot_mode.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

Expand All @@ -14,13 +15,13 @@ class ConversationBotModeSelect extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Map<String, String> options = {
"discussion":
BotMode.discussion:
L10n.of(context)!.conversationBotModeSelectOption_discussion,
"custom": L10n.of(context)!.conversationBotModeSelectOption_custom,
// "conversation":
// L10n.of(context)!.conversationBotModeSelectOption_conversation,
"text_adventure":
L10n.of(context)!.conversationBotModeSelectOption_textAdventure,
BotMode.custom: L10n.of(context)!.conversationBotModeSelectOption_custom,
// BotMode.textAdventure:
// L10n.of(context)!.conversationBotModeSelectOption_textAdventure,
// BotMode.storyGame:
// L10n.of(context)!.conversationBotModeSelectOption_storyGame,
};

return Padding(
Expand All @@ -38,7 +39,7 @@ class ConversationBotModeSelect extends StatelessWidget {
hint: Padding(
padding: const EdgeInsets.only(left: 15),
child: Text(
options[initialMode ?? "discussion"]!,
options[initialMode ?? BotMode.discussion]!,
style: const TextStyle().copyWith(
color: Theme.of(context).textTheme.bodyLarge!.color,
fontSize: 14,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ class ConversationBotSettingsState extends State<ConversationBotSettings> {
},
);
if (confirm == true) {
if (addBot) {
await widget.room?.invite(BotName.byEnvironment);
} else {
await widget.room?.kick(BotName.byEnvironment);
}
updateBotOption(() {
botOptions = botOptions;
});
final bool isBotRoomMember =
await widget.room?.isBotRoom ?? false;
if (addBot && !isBotRoomMember) {
await widget.room?.invite(BotName.byEnvironment);
} else if (!addBot && isBotRoomMember) {
await widget.room?.kick(BotName.byEnvironment);
}
}
},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fluffychat/pangea/constants/bot_mode.dart';
import 'package:fluffychat/pangea/models/bot_options_model.dart';
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_mode_dynamic_zone.dart';
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_mode_select.dart';
Expand Down Expand Up @@ -65,7 +66,7 @@ class ConversationBotSettingsFormState
initialMode: botOptions.mode,
onChanged: (String? mode) => {
setState(() {
botOptions.mode = mode ?? "discussion";
botOptions.mode = mode ?? BotMode.discussion;
}),
},
),
Expand Down
36 changes: 18 additions & 18 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1305,18 +1305,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -1417,10 +1417,10 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.8.0"
material_symbols_icons:
dependency: "direct main"
description:
Expand All @@ -1442,10 +1442,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.12.0"
mgrs_dart:
dependency: transitive
description:
Expand Down Expand Up @@ -1682,10 +1682,10 @@ packages:
dependency: transitive
description:
name: platform
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
version: "3.1.4"
platform_detect:
dependency: transitive
description:
Expand Down Expand Up @@ -2303,26 +2303,26 @@ packages:
dependency: transitive
description:
name: test
sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e"
sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073"
url: "https://pub.dev"
source: hosted
version: "1.25.7"
version: "1.25.2"
test_api:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.0"
test_core:
dependency: transitive
description:
name: test_core
sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696"
sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4"
url: "https://pub.dev"
source: hosted
version: "0.6.4"
version: "0.6.0"
timezone:
dependency: transitive
description:
Expand Down Expand Up @@ -2615,10 +2615,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.2.1"
wakelock_plus:
dependency: "direct main"
description:
Expand Down

0 comments on commit 09e15c3

Please sign in to comment.