From d227e9a01112abaa0622a7f878c552fabeb72fba Mon Sep 17 00:00:00 2001 From: Andrew Glaze Date: Sat, 28 Feb 2026 21:11:32 -0500 Subject: [PATCH] feat: hug command --- Sources/zundamon/Actions.swift | 66 +++++++++++++++++++++++++++ Sources/zundamon/MessageHandler.swift | 1 + choices/hug.txt | 21 +++++++++ 3 files changed, 88 insertions(+) create mode 100644 Sources/zundamon/Actions.swift create mode 100644 choices/hug.txt diff --git a/Sources/zundamon/Actions.swift b/Sources/zundamon/Actions.swift new file mode 100644 index 0000000..88ed151 --- /dev/null +++ b/Sources/zundamon/Actions.swift @@ -0,0 +1,66 @@ +import DiscordBM + +struct Actions { + static func getUserFromMention(_ mention: MentionUser) -> String { + mention.member?.nick ?? mention.global_name ?? mention.username + } + + static let hugRes = (try? String(contentsOfFile: "choices/hug.txt", encoding: .utf8))? + .split(separator: "\n") + .map({ $0.trimmingCharacters(in: .whitespacesAndNewlines) }) + + static func hug( + _ args: ArraySlice, + client: DiscordClient, + ctx: Gateway.MessageCreate + ) async throws { + guard let hugRes = hugRes else { print("hug.txt not loaded"); return } + let author = "**\(ctx.member?.nick ?? ctx.author?.global_name ?? ctx.author?.username ?? "Zundamon")**" + let dests = ctx.mentions.map(getUserFromMention).map({ "**\($0)**" }) + + let retMsg: String + + if dests.count > 1 { + let groupHugs = [ + "{subjects} all huddled together.", + "{subjects} hugged each other pairwise, generating a total of **{total}** hugs.", + "{subjects} hugged each other at the same time in the same place (although I'm not sure how that works with the current understanding of spacetime).", + ] + + let group = [author] + dests + let total = String(group.count) + let subjects = String(group.joined(by: ", ")) + + guard let res = groupHugs.randomElement()? + .replacingOccurrences(of: "{subjects}", with: subjects) + .replacingOccurrences(of: "{total}", with: total) + else { print("groupHugs.randomElement() returned null"); return } + + retMsg = res + } else { + let orig: String + let dest: String + if let firstDest = dests.first { + orig = "**\(author)**" + dest = "**\(firstDest)**" + } else { + orig = "**Zundamon**" + dest = "**\(author)**" + } + + guard let res = hugRes.randomElement()? + .replacingOccurrences(of: "{orig}", with: orig) + .replacingOccurrences(of: "{dest}", with: dest) + else { print("hug.txt empty"); return } + + retMsg = res + } + + try await client.createMessage( + channelId: ctx.channel_id, + payload: .init( + embeds: [.init(description: retMsg)], + ) + ).guardSuccess() + } +} diff --git a/Sources/zundamon/MessageHandler.swift b/Sources/zundamon/MessageHandler.swift index 12fe6d9..cef176b 100644 --- a/Sources/zundamon/MessageHandler.swift +++ b/Sources/zundamon/MessageHandler.swift @@ -19,6 +19,7 @@ struct MessageHandler { switch command { case "wow": try await handleWow(args) case "domath": try await Wolfram.handleMath(args, client: client, ctx: ctx) + case "hug": try await Actions.hug(args, client: client, ctx: ctx) default: break } } else if ctx.mentions.contains(where: { $0.id == Zundamon.ownID }) { diff --git a/choices/hug.txt b/choices/hug.txt new file mode 100644 index 0000000..dd09dc1 --- /dev/null +++ b/choices/hug.txt @@ -0,0 +1,21 @@ +{orig} squeezes {dest} tightly. +{orig} squeezes {dest} tightly in their arms. +{orig} squeezes {dest} tightly in their arms, usually with fondness. +{orig} squeezes {dest} tightly, probably to express affection. +{orig} holds {dest} in a tight or amorous embrace. +{orig} holds {dest} tightly in their arms. +{orig} holds {dest} tightly in their arms as a sign of affection. +{orig} holds {dest} close to their body. +{orig} holds {dest} close to their body, probably to express affection. +{orig} holds {dest} close to their body, likely to show that they like, love, or value them. +{orig} puts their arms around {dest} and hold them tightly, because {orig} likes {dest} or is pleased to see {dest}. +{dest} is trapped with {orig}'s arms wrapped around their back. +{orig} wraps their arms around {dest}'s back in a warm embrace. +{orig} wraps their arms around {dest}'s back in a warm embrace. +{orig} clings onto {dest}. +{orig} clings onto {dest} affectionately. +{orig} clasps {dest} tightly in their arms. +{orig} sneaks up from behind {dest} and puts their arms around {dest}'s waist. +{orig} sneaks up from behind {dest} and puts their arms around {dest}'s waist while saying nothing. +heheehehehe {orig} hugs {dest} <3<3<##<#,3,33<#3,#3,,3,3,#<... +{orig}'s arms consume {dest}'s body, mind, and soul in a comforting and personal spectacle.