Skip to content

Instantly share code, notes, and snippets.

@Zedd0202
Last active January 5, 2019 09:24
Show Gist options
  • Save Zedd0202/87b196019d798bd96d77a1b91fe5e8d6 to your computer and use it in GitHub Desktop.
Save Zedd0202/87b196019d798bd96d77a1b91fe5e8d6 to your computer and use it in GitHub Desktop.
import UIKit
import Foundation
import SlackKit
class LonelyWolf {
let bot: SlackKit
init(token: String) {
bot = SlackKit()
bot.addRTMBotWithAPIToken(token)
bot.addWebAPIAccessWithToken(token)
bot.notificationForEvent(.message) { [weak self] (event, client) in
guard let message = event.message else { return }
self?.handleMessage(message)
}
}
// MARK: Bot logic
private func handleMessage(_ message: Message) {
if let text = message.text, let channel = message.channel, text.contains("개빡친다") || text.contains("개빡쳐") {
let reaction = "워 워 진정하세요"
bot.webAPI?.sendMessage(channel: channel, text: reaction, success: nil, failure: nil)
return
}
return
}
}
class ViewController: UIViewController {
let bot = SlackKit()
override func viewDidLoad() {
super.viewDidLoad()
// With API token
let slackbot = LonelyWolf(token: "Your Token")
RunLoop.main.run()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment