Skip to content

Commit

Permalink
Initial reddit support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZekeSnider committed Apr 16, 2016
1 parent 7fcf84b commit 27e6043
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482161844.57728"
timestampString = "482400780.28752"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "87"
endingLineNumber = "87">
startingLineNumber = "108"
endingLineNumber = "108">
<Locations>
<Location
shouldBeEnabled = "No"
Expand Down Expand Up @@ -104,11 +104,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482161844.57728"
timestampString = "482400780.28752"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "104"
endingLineNumber = "104">
startingLineNumber = "125"
endingLineNumber = "125">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -118,11 +118,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482161844.57728"
timestampString = "482400780.28752"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "98"
endingLineNumber = "98">
startingLineNumber = "119"
endingLineNumber = "119">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down Expand Up @@ -178,12 +178,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482153142.353186"
timestampString = "482398573.13379"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "45"
endingLineNumber = "45"
landmarkName = "getVideo(_:toChat:)"
startingLineNumber = "46"
endingLineNumber = "46"
landmarkName = "sendVideoInfo(_:toChat:)"
landmarkType = "5">
<Locations>
<Location
Expand Down Expand Up @@ -258,13 +258,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482161844.57728"
timestampString = "482400780.28752"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "youtubeCall(_:myRoom:)"
landmarkType = "5">
startingLineNumber = "103"
endingLineNumber = "103">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down Expand Up @@ -310,7 +308,9 @@
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "31"
endingLineNumber = "31">
endingLineNumber = "31"
landmarkName = "pingCall(_:myRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down Expand Up @@ -359,5 +359,21 @@
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482398635.359025"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "75"
endingLineNumber = "75"
landmarkName = "redditCall(_:myRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
13 changes: 11 additions & 2 deletions Jared/EpicModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class EpicModule: RoutingModule {
let done = Route(comparisons: [.StartsWith: "/done"], call: self.donezo, description: "Declare your completion of a task")
let choose = Route(comparisons: [.StartsWith: "/choose"], call: self.makeChoice, description: "Make a tough decision easily")
let guess = Route(comparisons: [.StartsWith: "/guess"], call: self.guessNumber, description: "Fun Number guessing game")
let face = Route(comparisons: [.StartsWith: "/grin", .Contains: ":^)"], call: self.printFace, description: "Send a shit eating grin")
let muslim = Route(comparisons: [.StartsWith: "/isjalenmuslim", .Contains: "Is Jalen Muslim"], call: self.isJalenMuslim, description: "Check if Jalen is a muslim")
let jew = Route(comparisons: [.StartsWith: "/jew"], call: self.printJew, description: "Jew")

routes = [fuccboi, tip, bazinga, nice, stop, hello, rate, bigBunny, slots, kill, clear, kin, correction, done, choose, guess, jew]
routes = [fuccboi, tip, bazinga, nice, stop, hello, rate, bigBunny, slots, kill, clear, kin, correction, done, choose, guess, jew, face, muslim]
}

func bigBunny(message:String, myRoom: Room) -> Void{
Expand Down Expand Up @@ -236,8 +238,15 @@ class EpicModule: RoutingModule {
}
}

func isJalenMuslim(message:String, myRoom: Room) -> Void {
SendText("Yes", toRoom: myRoom)
}

func printJew(message:String, myRoom: Room) -> Void {
//This is not anti-semetic, this ia tribute to our fellow sons of god. <no sarcasm>
SendText("            ✡\n          ✡  ✡\n✡✡✡✡✡✡✡✡✡✡✡\n  ✡  ✡           ✡  ✡\n   ✡               ✡\n  ✡  ✡           ✡  ✡\n✡✡✡✡✡✡✡✡✡✡✡\n          ✡  ✡\n            ✡", toRoom: myRoom)
SendText("                   ✡️\n                ✡️  ✡️\n✡️✡️✡️✡️✡️✡️✡️✡️✡️\n   ✡️  ✡️                ✡️  ✡️\n      ✡️                       ✡️\n   ✡️  ✡️                ✡️  ✡️\n✡️✡️✡️✡️✡️✡️✡️✡️✡️\n                ✡️  ✡️\n                    ✡️", toRoom: myRoom)
}
func printFace(message:String, myRoom: Room) -> Void {
SendText("               :^)\n:^)    :^)      :^)\n       :^):^)     :^)\n      :^)  :^)    :^)\n:^)              :^)\n               :^)", toRoom: myRoom)
}
}
23 changes: 22 additions & 1 deletion Jared/RESTModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct RESTModule: RoutingModule {

init() {
let youtube = Route(comparisons: [.ContainsURL: "youtu.be"], call: self.youtubeCall, description: "Youtube integration to get details of youtube video url")
routes = [youtube]
let Reddit = Route(comparisons: [.ContainsURL: "reddit.com"], call: self.redditCall, description: "Reddit integration")
routes = [youtube, Reddit]
}

func getVideo(videoID: String, toChat: Room) {
Expand Down Expand Up @@ -59,6 +60,26 @@ struct RESTModule: RoutingModule {
}
}
}
func sendRedditComment(commentJSON: String, toChat: Room) {
if let dataFromString = commentJSON.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
let JSONParse = JSON(data: dataFromString)
let commentAuthor = JSONParse[1]["data"]["children"][0]["data"]["author"]
let commentBody = JSONParse[1]["data"]["children"][0]["data"]["body"]
let message = "\"\(commentBody)\" -\(commentAuthor)"
SendText(message, toRoom: toChat)
}

}

func redditCall(url: String, myRoom: Room) -> Void {
let JSONurl: String = url + ".json"
if JSONurl.containsString("/comments/") {
Alamofire.request(.GET, JSONurl).responseString {response in
self.sendRedditComment(response.result.value!, toChat: myRoom)
}
}

}

func youtubeCall(url:String, myRoom: Room) -> Void {
let regexMatches = matchesForRegexInText("(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)", text:url)
Expand Down

0 comments on commit 27e6043

Please sign in to comment.