From cd08ed9ae487815594de54813ae343a259cf749b Mon Sep 17 00:00:00 2001 From: nin0dev Date: Fri, 29 Nov 2024 21:44:45 -0500 Subject: [PATCH] okay, so apparently, committing your token with admin in nin0Corp is not a good idea. --- .gitignore | 1 + .vscode/launch.json | 22 ++++++++++++++++++++++ .vscode/settings.json | 1 + Package.resolved | 11 ++++++++++- Package.swift | 4 +++- Sources/Bot.swift | 14 ++++++++++++-- 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 0023a53..d811c90 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ DerivedData/ .swiftpm/configuration/registries.json .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata .netrc +.env \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..16ce130 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "type": "lldb", + "request": "launch", + "args": [], + "cwd": "${workspaceFolder:fj-admin-switfie}", + "name": "Debug fj-admin", + "program": "${workspaceFolder:fj-admin-switfie}/.build/debug/fj-admin", + "preLaunchTask": "swift: Build Debug fj-admin" + }, + { + "type": "lldb", + "request": "launch", + "args": [], + "cwd": "${workspaceFolder:fj-admin-switfie}", + "name": "Release fj-admin", + "program": "${workspaceFolder:fj-admin-switfie}/.build/release/fj-admin", + "preLaunchTask": "swift: Build Release fj-admin" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Package.resolved b/Package.resolved index 75dbf58..16ef3d3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "3d28c07a9322f4b5113beb449558e3d98bbcd18d5e1f793fce74c088e5e32263", + "originHash" : "376b28dbeb8d6abd83240216351c27a3bfd2a448dc29c9c10156125bce6469e7", "pins" : [ { "identity" : "async-http-client", @@ -28,6 +28,15 @@ "version" : "1.12.1" } }, + { + "identity" : "dotenv", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swiftpackages/DotEnv.git", + "state" : { + "revision" : "1f15bb9de727d694af1d003a1a5d7a553752850f", + "version" : "3.0.0" + } + }, { "identity" : "multipart-kit", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index ddd988c..45c2171 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,8 @@ import PackageDescription let package = Package( name: "fj-admin", dependencies: [ - .package(url: "https://github.com/DDBKit/DDBKit", exact: "0.2.4"), // change this to latest ver + .package(url: "https://github.com/DDBKit/DDBKit", exact: "0.2.4"), // change this to latest ver, + .package(url: "https://github.com/swiftpackages/DotEnv.git", from: "3.0.0") ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -17,6 +18,7 @@ let package = Package( .product(name: "DDBKit", package: "DDBKit"), .product(name: "DDBKitUtilities", package: "DDBKit"), .product(name: "DDBKitFoundation", package: "DDBKit"), + .product(name: "DotEnv", package: "DotEnv"), ] ), ] diff --git a/Sources/Bot.swift b/Sources/Bot.swift index 5f410bb..cea55dd 100644 --- a/Sources/Bot.swift +++ b/Sources/Bot.swift @@ -1,14 +1,24 @@ import DDBKit +import DotEnv +import Foundation @main struct FjAdminBot: DiscordBotApp { init() async { + do { + let env = try DotEnv.read(path: "./.env") + env.load() + print("Loaded .env file") + } catch { + print("Failed to load .env file, things won't work!") + } + let httpClient = HTTPClient() bot = await BotGatewayManager( eventLoopGroup: httpClient.eventLoopGroup, httpClient: httpClient, - token: "MTMxMTY2NTg1OTQ3NTAxMzY1Mg.GgVETf.KbMqaqPhOR3JMNT-GiWT3qwiK862cbbjZm9RTc", + token: ProcessInfo.processInfo.environment["BOT_TOKEN"]!, largeThreshold: 250, presence: .init(activities: [], status: .online, afk: false), intents: [.messageContent, .guildMessages] @@ -23,7 +33,7 @@ struct FjAdminBot: DiscordBotApp { var body: [any BotScene] { ReadyEvent { ready in - print("hi mom") + print(String(format: "Logged on as %@#%@!", ready.user.username, ready.user.discriminator)) } }