Macro chat bot command.

This commit is contained in:
copilot-swe-agent[bot]
2026-05-09 09:42:55 +00:00
committed by Erik Moqvist
parent 8865b2886a
commit cbc4564ab1
5 changed files with 84 additions and 0 deletions
+20
View File
@@ -2169,6 +2169,18 @@
}
}
},
"!moblin macro <run/cancel> <name>" : {
"comment" : "Command to run or cancel a macro.",
"isCommentAutoGenerated" : true
},
"!moblin macro cancel <name>" : {
"comment" : "A command to cancel a macro.",
"isCommentAutoGenerated" : true
},
"!moblin macro run <name>" : {
"comment" : "A command to run a macro.",
"isCommentAutoGenerated" : true
},
"!moblin reaction <reaction>" : {
"localizations" : {
"de" : {
@@ -46985,6 +46997,10 @@
}
}
},
"Cancel given macro." : {
"comment" : "A description of the cancel macro command.",
"isCommentAutoGenerated" : true
},
"Cancelling raid" : {
"localizations" : {
"de" : {
@@ -165775,6 +165791,10 @@
}
}
},
"Run given macro." : {
"comment" : "A description of the action of running a macro.",
"isCommentAutoGenerated" : true
},
"Run macro" : {
"comment" : "Text for a button that runs a macro.",
"isCommentAutoGenerated" : true,
+34
View File
@@ -149,6 +149,8 @@ extension Model {
handleChatBotMessageTwitch(command: command)
case "gimbal":
handleChatBotMessageGimbal(command: command)
case "macro":
handleChatBotMessageMacro(command: command)
default:
break
}
@@ -436,6 +438,38 @@ extension Model {
moveToGimbalPreset(id: preset.id)
}
private func handleChatBotMessageMacro(command: ChatBotCommand) {
executeIfUserAllowedToUseChatBot(
permissions: database.chat.botCommandPermissions.macro,
command: command
) {
guard let subcommand = command.popFirst(),
let macroName = command.popFirst(),
let macro = self.database.macros.macros.first(where: {
$0.name.lowercased() == macroName.lowercased()
})
else {
return
}
switch subcommand {
case "run":
self.handleChatBotMessageMacroRun(macro: macro)
case "cancel":
self.handleChatBotMessageMacroCancel(macro: macro)
default:
break
}
}
}
private func handleChatBotMessageMacroRun(macro: SettingsMacrosMacro) {
startMacro(macro: macro)
}
private func handleChatBotMessageMacroCancel(macro: SettingsMacrosMacro) {
stopMacro(macro: macro)
}
private func handleChatBotMessageReaction(command: ChatBotCommand) {
guard #available(iOS 17, *) else {
return
@@ -168,6 +168,7 @@ class SettingsChatBotPermissions: Codable {
var ai: SettingsChatBotPermissionsCommand = .init()
var twitch: SettingsChatBotPermissionsCommand = .init()
var gimbal: SettingsChatBotPermissionsCommand = .init()
var macro: SettingsChatBotPermissionsCommand = .init(moderatorsEnabled: false)
var migrated: Bool = false
enum CodingKeys: CodingKey {
@@ -189,6 +190,7 @@ class SettingsChatBotPermissions: Codable {
ai,
twitch,
gimbal,
macro,
migrated
}
@@ -212,6 +214,7 @@ class SettingsChatBotPermissions: Codable {
try container.encode(.ai, ai)
try container.encode(.twitch, twitch)
try container.encode(.gimbal, gimbal)
try container.encode(.macro, macro)
try container.encode(.migrated, migrated)
}
@@ -237,6 +240,9 @@ class SettingsChatBotPermissions: Codable {
ai = container.decode(.ai, SettingsChatBotPermissionsCommand.self, .init())
twitch = container.decode(.twitch, SettingsChatBotPermissionsCommand.self, .init())
gimbal = container.decode(.gimbal, SettingsChatBotPermissionsCommand.self, .init())
macro = container.decode(.macro,
SettingsChatBotPermissionsCommand.self,
.init(moderatorsEnabled: false))
migrated = container.decode(.migrated, Bool.self, false)
if !migrated {
scene.moderatorsEnabled = false
@@ -401,6 +401,27 @@ private struct TeslaPermissionsSettingsView: View {
}
}
private struct MacroPermissionsSettingsView: View {
let permissions: SettingsChatBotPermissionsCommand
var body: some View {
Section {
PermissionsSettingsView(
title: String(localized: "!moblin macro <run/cancel> <name>"),
permissions: permissions
)
} footer: {
VStack(alignment: .leading) {
Text("!moblin macro run <name>")
Text("Run given macro.")
Text("")
Text("!moblin macro cancel <name>")
Text("Cancel given macro.")
}
}
}
}
private struct ChatBotCommandsSettingsView: View {
@EnvironmentObject var model: Model
@@ -417,6 +438,7 @@ private struct ChatBotCommandsSettingsView: View {
FixPermissionsSettingsView(permissions: permissions.fix)
GimbalPermissionsSettingsView(permissions: permissions.gimbal)
LocationPermissionsSettingsView(permissions: permissions.location)
MacroPermissionsSettingsView(permissions: permissions.macro)
MapPermissionsSettingsView(permissions: permissions.map)
MuteUnmutePermissionsSettingsView(permissions: permissions.audio)
ReactionPermissionsSettingsView(permissions: permissions.reaction)
+2
View File
@@ -50,3 +50,5 @@
| !moblin reaction rain | Trigger Apple rain reaction. |
| !moblin reaction glasses | Trigger glasses reaction. |
| !moblin reaction sparkle | Trigger sparkle reaction. |
| !moblin macro run \<name> | Run given macro. |
| !moblin macro cancel \<name> | Cancel given macro. |