Skip to content

Commit

Permalink
Merge pull request #8 from SOBotics/updates-patch
Browse files Browse the repository at this point in the history
some updates
  • Loading branch information
double-fault committed Mar 8, 2017
2 parents 4215328 + 9aed643 commit 7ad1cce
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Sources/CommandLocation.swift
Expand Up @@ -3,11 +3,12 @@
// FireAlarm
//
// Created by Ashish Ahuja on 25/02/17.
// Copyright © 2017 Ashish Ahuja. All right reserved
// Copyright © 2017 Ashish Ahuja. All rights reserved
//

import Foundation
import SwiftChatSE
import SwiftStack

class CommandLocation: Command {
override class func usage() -> [String] {
Expand Down
82 changes: 82 additions & 0 deletions Sources/CommandUnclosed.swift
@@ -0,0 +1,82 @@
//
// CommandUnclosed.swift
// FireAlarm
//
// Created by Ashish Ahuja on 05/03/17.
// Copyright © 2017 Ashish Ahuja. All right reserved
//

import Foundation
import SwiftStack
import SwiftChatSE
import Dispatch

class CommandUnclosed: Command {
override class func usage() -> [String] {
return ["unclosed reports ..."]
}

override func run() throws {

if (reportedPosts.isEmpty)
{
reply ("no reports!")
return
}

var totalToCheck: Int!

if let total = Int(arguments[0]) {
if (total > 20)
{
reply ("You cannot specify to check more than the last 20 reports!")
return
}
totalToCheck = total
} else {
reply ("Please enter how many reports should be checked!")
return
}

var postsToCheck = [Int]()

if let minDate: Date = Calendar(identifier: .gregorian).date(byAdding: DateComponents(hour: -10), to: Date()) {
let recentlyReportedPosts = reportedPosts.filter {
$0.when > minDate
}

if (recentlyReportedPosts.count == 0)
{
reply ("There are no reports made by me recently, thus I have nothing to check!")
return
}

if (totalToCheck > recentlyReportedPosts.count)
{
totalToCheck = recentlyReportedPosts.count
}

for i in 0..<totalToCheck {
postsToCheck.append(recentlyReportedPosts[i].id)
}
}
else {
message.room.postMessage("Failed to calculate minimum report date!")
}

var messageClosed = ""

//Now fetch the posts from the API
for post in try apiClient.fetchQuestions(postsToCheck).items ?? [] {
if (post.closed_reason == nil)
{
//post is not closed
//message.room.postMessage("\(post.link)")

messageClosed = messageClosed + "\n [tag: \(post.tags!.first)] \(post.link!)"
}
}

message.room.postMessage (messageClosed)
}
}
6 changes: 3 additions & 3 deletions Sources/Filter.swift
Expand Up @@ -35,6 +35,8 @@ extension Post {
}
}

var reportedPosts = [(id: Int, when: Date, difference: Int)]()

class Filter {
let client: Client
let rooms: [ChatRoom]
Expand All @@ -43,8 +45,6 @@ class Filter {
let words: [String:Word]
var blacklistedUsernames: [String]

var reportedPosts = [(id: Int, when: Date, difference: Int)]()

var postsToCheck = [Int]()

var queue = DispatchQueue(label: "Filter", attributes: [.concurrent])
Expand Down Expand Up @@ -576,7 +576,7 @@ class Filter {
do {
if wsRetries >= wsMaxRetries {
fatalError(
"Realtime questions websocket died; failed to reconnect! Active posts will not be reported until a reboot. (cc @NobodyNada)"
"Realtime questions websocket died; failed to reconnect! Active posts will not be reported until a reboot. \(ping)"
)
}
wsRetries += 1
Expand Down
2 changes: 1 addition & 1 deletion Sources/main.swift
Expand Up @@ -19,7 +19,7 @@ let commands: [Command.Type] = [
CommandCheckPost.self, CommandQuota.self,
CommandBlacklistUsername.self, CommandGetBlacklistedUsernames.self, CommandUnblacklistUsername.self,
CommandOptIn.self, CommandOptOut.self, CommandCheckNotification.self, CommandLeaveRoom.self,
CommandLocation.self, CommandReport.self,
CommandLocation.self, CommandReport.self, CommandUnclosed.self,
]


Expand Down

0 comments on commit 7ad1cce

Please sign in to comment.