-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# .gitignore | ||
Secrets.swift | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+10.8 KB
(110%)
...eproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// HmtaiReader.swift | ||
// AnimeGen | ||
// | ||
// Created by cranci on 03/03/24. | ||
// | ||
|
||
import UIKit | ||
|
||
extension ViewController { | ||
|
||
func fetchLastMessageFromDiscordAndLoadImage() { | ||
|
||
let discordChannelID = "1212099607031578674" | ||
|
||
let url = URL(string: "https://discord.com/api/v10/channels/\(discordChannelID)/messages")! | ||
var request = URLRequest(url: url) | ||
request.setValue(Secrets.apiToken, forHTTPHeaderField: "Authorization") | ||
|
||
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in | ||
if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]], let message = json.first { | ||
if let imageUrl = self.extractImageUrl(from: message) { | ||
self.loadImageFromDiscord(imageUrl: imageUrl) | ||
} else { | ||
print("Error extracting image URL from Discord message.") | ||
print("Message JSON: \(self.convertDictionaryToJsonString(message) ?? "")") | ||
} | ||
} | ||
} | ||
|
||
task.resume() | ||
} | ||
|
||
func extractImageUrl(from message: [String: Any]) -> String? { | ||
if let embeds = message["embeds"] as? [[String: Any]], let embed = embeds.first { | ||
if let type = embed["type"] as? String, type == "image", let thumbnail = embed["thumbnail"] as? [String: Any] { | ||
if let proxyUrl = thumbnail["proxy_url"] as? String { | ||
return proxyUrl | ||
} else if let url = thumbnail["url"] as? String { | ||
return url | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func loadImageFromDiscord(imageUrl: String) { | ||
DispatchQueue.main.async { | ||
self.imageView.loadImage(from: imageUrl) | ||
|
||
self.currentImageURL = imageUrl | ||
|
||
self.stopLoadingIndicator() | ||
} | ||
} | ||
|
||
func convertDictionaryToJsonString(_ dictionary: [String: Any]) -> String? { | ||
do { | ||
let jsonData = try JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted) | ||
return String(data: jsonData, encoding: .utf8) | ||
} catch { | ||
print("Error converting dictionary to JSON string: \(error)") | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// HmtaiSender.swift | ||
// AnimeGen | ||
// | ||
// Created by cranci on 03/03/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
extension ViewController { | ||
|
||
@objc func fetchDataAndSendImageToDiscord() { | ||
startLoadingIndicator() | ||
|
||
let categories3: [String] | ||
let endpointPrefix: String | ||
|
||
if UserDefaults.standard.bool(forKey: "enableExplictiCont") { | ||
categories3 = ["ass", "anal", "bdsm", "classic", "cum", "creampie", "manga", "femdom", "hentai", "incest", "masturbation", "public", "ero", "orgy", "elves", "yuri", "pantsu", "pussy", "glasses", "cuckold", "blowjob", "boobjob", "handjob", "footjob", "boobs", "thighs", "ahegao", "uniform", "gangbang", "tentacles", "gif", "nsfwNeko", "nsfwMobileWallpaper", "zettaiRyouiki"] | ||
endpointPrefix = "https://hmtai.hatsunia.cfd/nsfw/" | ||
} else { | ||
categories3 = ["wave", "wink", "tea", "bonk", "punch", "poke", "bully", "pat", "kiss", "kick", "blush", "feed", "smug", "hug", "cuddle", "cry", "cringe", "slap", "five", "glomp", "happy", "hold", "nom", "smile", "throw", "lick", "bite", "dance", "boop", "sleep", "like", "kill", "tickle", "nosebleed", "threaten", "depression", "wolf_arts", "jahy_arts", "neko_arts", "coffee_arts", "wallpaper", "mobileWallpaper"] | ||
endpointPrefix = "https://hmtai.hatsunia.cfd/sfw/" | ||
} | ||
|
||
let randomCategory3 = categories3.randomElement() ?? "pat" | ||
let apiEndpoint = "\(endpointPrefix)\(randomCategory3)" | ||
|
||
guard let url = URL(string: apiEndpoint) else { | ||
print("Invalid URL") | ||
self.stopLoadingIndicator() | ||
return | ||
} | ||
|
||
URLSession.shared.dataTask(with: url) { data, response, error in | ||
guard let data = data, error == nil else { | ||
print("Error fetching data: \(error?.localizedDescription ?? "Unknown error")") | ||
return | ||
} | ||
|
||
do { | ||
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] | ||
|
||
if let imageUrlString = json?["url"] as? String { | ||
DispatchQueue.main.async { [weak self] in | ||
self?.sendImageToDiscord(imageUrlString) | ||
|
||
let category3 = randomCategory3 | ||
self?.tagsLabel.isHidden = false | ||
self?.updateUIWithTags([category3]) | ||
} | ||
} else { | ||
print("Error: Could not find 'url' field in the API response.") | ||
} | ||
} catch { | ||
print("Error parsing JSON: \(error.localizedDescription)") | ||
} | ||
}.resume() | ||
} | ||
|
||
private func sendImageToDiscord(_ imageUrlString: String) { | ||
let discordWebhookURL = URL(string: "https://discord.com/api/webhooks/1213771285507735592/flCaAxQ8NuhnJML3P_YYFIOvSQxhmT8552nm4lQE2LgDWOzZvMGNaVsf7BJU4yqdQ_ql")! | ||
|
||
var request = URLRequest(url: discordWebhookURL) | ||
request.httpMethod = "POST" | ||
request.setValue("application/json", forHTTPHeaderField: "Content-Type") | ||
|
||
let payload: [String: Any] = ["content": imageUrlString] | ||
let jsonData = try? JSONSerialization.data(withJSONObject: payload) | ||
|
||
request.httpBody = jsonData | ||
|
||
URLSession.shared.dataTask(with: request) { [weak self] data, response, error in | ||
if let error = error { | ||
print("Error sending image URL to Discord: \(error.localizedDescription)") | ||
} else { | ||
self?.fetchLastMessageFromDiscordAndLoadImage() | ||
} | ||
}.resume() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters