Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/swift' into swift
- Loading branch information
Showing
3 changed files
with
85 additions
and
10 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,64 @@ | ||
// | ||
// CommandReport.swift | ||
// FireAlarm | ||
// | ||
// Created by Ashish Ahuja on 2/26/17. | ||
// Copyright © 2017 Ashish Ahuja (Fortunate-MAN). All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftChatSE | ||
import SwiftStack | ||
import Dispatch | ||
|
||
class CommandReport: Command { | ||
override class func usage() -> [String] { | ||
return ["report print ...", "report ..."] | ||
} | ||
|
||
override class func privileges() -> ChatUser.Privileges { | ||
return .owner | ||
} | ||
|
||
func tags(for post: Post) -> [String] { | ||
if let q = post as? Question { | ||
return q.tags ?? [] | ||
} else if let a = post as? Answer { | ||
return a.tags ?? [] | ||
} else { | ||
return [] | ||
} | ||
} | ||
|
||
override func run() throws { | ||
var questionID: Int! | ||
if let id = Int(arguments[0]) { | ||
questionID = id | ||
} | ||
else if let url = URL(string: arguments[0]), let id = postIDFromURL(url) { | ||
questionID = id | ||
} | ||
else { | ||
reply("Please enter a valid post ID or URL.") | ||
return | ||
} | ||
|
||
guard let question = try apiClient.fetchQuestion(questionID).items?.first else { | ||
reply("Could not fetch the question!") | ||
return | ||
} | ||
|
||
if usageIndex == 0 | ||
{ | ||
var newTitle = "\(question.title ?? "<no title>")" | ||
|
||
newTitle = newTitle.replacingOccurrences(of: "[", with: "\\[") | ||
newTitle = newTitle.replacingOccurrences(of: "]", with: "\\]") | ||
|
||
let messagePost = "[ [\(botName)](\(stackAppsLink)) ] " + | ||
"[tag:\(tags(for: question).first ?? "<unknown tag>")] Manually reported post [\(newTitle)](//stackoverflow.com/q/\(questionID!))" | ||
|
||
message.room.postMessage(messagePost) | ||
} | ||
} | ||
} |
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