Files
zunda-bot/Sources/zundamon/MessageHandler.swift
Andrew Glaze 6a48936f6c Image attach
2026-03-20 19:13:45 -04:00

116 lines
3.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import DiscordKit
struct MessageHandler {
let ctx: MessageCreate
let client: DiscordClient
static let prefix = ":"
static let zundaGifData = try? Data(contentsOf: URL(filePath: "resources/media/zundamone.gif"))
func handle() async throws {
guard !(ctx.author?.bot ?? false) else { return }
if (ctx.content.hasPrefix(MessageHandler.prefix)) {
let split = ctx.content.split(separator: " ")
let command = split.first?.trimmingPrefix(MessageHandler.prefix)
let args = split[1...]
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)
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 }) {
if ctx.content
.replacingOccurrences(of: "<@\(Zundamon.ownID!)>", with: "")
.trimmingCharacters(in: .whitespacesAndNewlines)
.count == 0
{
try await client.createMessage(
channelId: ctx.channel_id,
payload: .init(
message_reference: .init(
type: 0,
message_id: ctx.id,
channel_id: ctx.channel_id,
guild_id: ctx.guild_id,
),
embeds: [.init(image: .init(url: "https://candy123.moe/tetrio/zundamone.gif"))],
)
)
} else {
try await handle8Ball()
}
}
}
static let ballResponses = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Dont count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful.",
"Ui beam",
"We are Shigure Ui",
"We are Shigure Ux",
]
func handle8Ball() async throws {
print("yo wuddup")
try await client.createMessage(
channelId: ctx.channel_id,
payload: .init(
content: MessageHandler.ballResponses.randomElement(),
message_reference: .init(
type: 0,
message_id: ctx.id,
channel_id: ctx.channel_id,
guild_id: ctx.guild_id,
),
)
)
}
static let wows = [
"<:wow:1477062414913634334>",
"<:wow2:1477062432357875948>",
"<:wow4:1477062471746588713>",
"<:wow5:1477062452804849845>"
]
func handleWow(_ args: ArraySlice<String.SubSequence>) async throws {
try await client.createMessage(
channelId: ctx.channel_id,
payload: .init(
content: MessageHandler.wows.randomElement(),
message_reference: .init(
type: 0,
message_id: ctx.id,
channel_id: ctx.channel_id,
guild_id: ctx.guild_id,
),
)
)
}
}