From cc489fccb6e3d8cbab8ad27991a03f069e2b6596 Mon Sep 17 00:00:00 2001 From: Andrew Glaze Date: Sun, 1 Mar 2026 14:32:18 -0500 Subject: [PATCH] feat: pat command --- .gitignore | 2 + Sources/zundamon/Actions.swift | 45 ++++++++++++++++++++++- Sources/zundamon/MessageHandler.swift | 4 +- {choices => resources/choices}/hug.txt | 0 resources/choices/pat.txt | 10 +++++ {media => resources/media}/zundamone.gif | Bin zundamon.service | 11 ++++++ 7 files changed, 69 insertions(+), 3 deletions(-) rename {choices => resources/choices}/hug.txt (100%) create mode 100644 resources/choices/pat.txt rename {media => resources/media}/zundamone.gif (100%) create mode 100644 zundamon.service diff --git a/.gitignore b/.gitignore index ec833f3..3665c63 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ DerivedData/ .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc .env +dep/ +deploy.sh diff --git a/Sources/zundamon/Actions.swift b/Sources/zundamon/Actions.swift index 490aa1b..8a3e433 100644 --- a/Sources/zundamon/Actions.swift +++ b/Sources/zundamon/Actions.swift @@ -5,7 +5,35 @@ struct Actions { mention.member?.nick ?? mention.global_name ?? mention.username } - static let hugRes = (try? String(contentsOfFile: "choices/hug.txt", encoding: .utf8))? + static func performAction(ctx: Gateway.MessageCreate, client: DiscordClient, resOpts: [String]) async throws { + let author = "**\(ctx.member?.nick ?? ctx.author?.global_name ?? ctx.author?.username ?? "Zundamon")**" + let dests = ctx.mentions.map(getUserFromMention).map({ "**\($0)**" }) + let orig: String + let dest: String + if let firstDest = dests.first { + orig = "\(author)" + dest = "\(firstDest)" + } else { + orig = "**Zundamon**" + dest = "\(author)" + } + + guard let res = resOpts.randomElement()? + .replacingOccurrences(of: "{orig}", with: orig) + .replacingOccurrences(of: "{dest}", with: dest) + else { print("retOptions empty"); return } + + let retMsg = res + + try await client.createMessage( + channelId: ctx.channel_id, + payload: .init( + embeds: [.init(description: retMsg)], + ) + ).guardSuccess() + } + + static let hugRes = (try? String(contentsOfFile: "resources/choices/hug.txt", encoding: .utf8))? .split(separator: "\n") .map({ $0.trimmingCharacters(in: .whitespacesAndNewlines) }) @@ -44,7 +72,7 @@ struct Actions { orig = "\(author)" dest = "\(firstDest)" } else { - orig = "Zundamon" + orig = "**Zundamon**" dest = "\(author)" } @@ -63,4 +91,17 @@ struct Actions { ) ).guardSuccess() } + + static let patRes = (try? String(contentsOfFile: "resources/choices/pat.txt", encoding: .utf8))? + .split(separator: "\n") + .map({ $0.trimmingCharacters(in: .whitespacesAndNewlines) }) + + static func pat( + _ args: ArraySlice, + client: DiscordClient, + ctx: Gateway.MessageCreate + ) async throws { + guard let patRes = patRes else { print("pat.txt not loaded"); return } + try await performAction(ctx: ctx, client: client, resOpts: patRes) + } } diff --git a/Sources/zundamon/MessageHandler.swift b/Sources/zundamon/MessageHandler.swift index cef176b..4afb467 100644 --- a/Sources/zundamon/MessageHandler.swift +++ b/Sources/zundamon/MessageHandler.swift @@ -7,7 +7,7 @@ struct MessageHandler { let client: any DiscordClient static let prefix = ":" - static let zundaGifData = try? Data(contentsOf: URL(filePath: "media/zundamone.gif")) + static let zundaGifData = try? Data(contentsOf: URL(filePath: "resources/media/zundamone.gif")) func handle() async throws { guard !(ctx.author?.bot ?? false) else { return } @@ -20,6 +20,8 @@ struct MessageHandler { 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) + case "pat": try await Actions.pat(args, client: client, ctx: ctx) + case "pet": try await Actions.pat(args, client: client, ctx: ctx) default: break } } else if ctx.mentions.contains(where: { $0.id == Zundamon.ownID }) { diff --git a/choices/hug.txt b/resources/choices/hug.txt similarity index 100% rename from choices/hug.txt rename to resources/choices/hug.txt diff --git a/resources/choices/pat.txt b/resources/choices/pat.txt new file mode 100644 index 0000000..d640cc8 --- /dev/null +++ b/resources/choices/pat.txt @@ -0,0 +1,10 @@ +{orig} moves their hand over to {dest}'s head and gave it a pleasure feeling. +{orig} gently strokes {dest}'s head. +{orig} softly strokes {dest}'s head as a sign of affection. +{dest} timidly placed {orig}'s hand on their head. +{dest} timidly placed {orig}'s hand on their head while blushing intensely. +{orig} runs their finger through {dest}'s hair, lightly scratches {dest}'s head and caressing their hair strands. +{orig} lightly scratches {dest}'s cheeks just behind the whiskers. +{dest} lets out a quiet purr as {orig}'s fingers gently scratches {dest}'s head. +{dest} smiled, slightly blushing, as {orig} playfully taps {dest}'s head. +{orig} reaches over and lightly taps {dest}'s head. diff --git a/media/zundamone.gif b/resources/media/zundamone.gif similarity index 100% rename from media/zundamone.gif rename to resources/media/zundamone.gif diff --git a/zundamon.service b/zundamon.service new file mode 100644 index 0000000..29f7e06 --- /dev/null +++ b/zundamon.service @@ -0,0 +1,11 @@ +[Unit] +Description=Zundamon Discord Bot +After=network-online.target + +[Service] +User=zundamon +ExecStart=/usr/local/share/zundabot/zundamon +WorkingDirectory=/usr/local/share/zundabot + +[Install] +WantedBy=multi-user.target