Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneQi committed Nov 9, 2018
2 parents cb889ce + 78262b7 commit bc4093f
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 102 deletions.
9 changes: 2 additions & 7 deletions Example/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import Foundation

let bot = ZEGBot(token: "TYPE YOUR TOKEN HERE")

bot.run { updateResult, bot in
switch updateResult {
case .success(let update):
dump(update)
case .failure(let error):
dump(error)
}
try! bot.run { update, bot in
dump(update)
}
7 changes: 4 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.1
// swift-tools-version:4.2

import PackageDescription

Expand All @@ -11,7 +11,7 @@ let package = Package(
.executable(
name: "ZEGBotExample",
targets: ["ZEGBotExample"])
],
],
dependencies: [],
targets: [
.target(
Expand All @@ -25,5 +25,6 @@ let package = Package(
.testTarget(
name: "ZEGBotTests",
dependencies: ["ZEGBot"]),
]
],
swiftLanguageVersions: [.v4_2]
)
56 changes: 43 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ZEGBot

[![Build Status](https://travis-ci.org/ShaneQi/ZEGBot.svg?branch=master)](https://travis-ci.org/ShaneQi/ZEGBot) [![Swift Version](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://swift.org) ![Platforms](https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-blue.svg?style=flat) ![License](https://img.shields.io/badge/License-Apache-red.svg?style=flat)
[![Build Status](https://travis-ci.org/ShaneQi/ZEGBot.svg?branch=master)](https://travis-ci.org/ShaneQi/ZEGBot) [![Swift Version](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat)](https://swift.org) ![Platforms](https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-blue.svg?style=flat) ![License](https://img.shields.io/badge/License-Apache-red.svg?style=flat)

This library wraps the JSON decoding processing, making it easy to decode incoming JSON String to manipulatable objects.

Expand All @@ -11,7 +11,7 @@ This library wraps the processing of converting objects to Telegram Bot API requ
Add this project as a dependency in your Package.swift file.

```swift
.package(url: "https://github.com/shaneqi/ZEGBot.git", from: Version(4, 0, 0))
.package(url: "https://github.com/shaneqi/ZEGBot.git", from: Version(4, 2, 0))
```
## Quick Start

Expand All @@ -25,10 +25,13 @@ import ZEGBot
// Don't forget to fill in your bot token.
let bot = ZEGBot(token: "TYPE YOUR TOKEN HERE")

bot.run { update, bot in
// Handle updates here...

})
do {
try bot.run { update, bot in
// Handle updates here...
})
} catch let error {
NSLog("Bot exit due to: \(error)")
}
```

## Usage
Expand All @@ -55,7 +58,11 @@ bot.run { update, bot in
```swift
...
if let message = update.message {
bot.send(message: "bar", to: message.chat)
do {
try bot.send(message: "bar", to: message.chat)
} catch let error {
NSLog("Failed to send message due to: \(error)")
}
}
...
```
Expand All @@ -64,7 +71,11 @@ bot.run { update, bot in
```swift
...
if let message = update?.message {
bot.send(message: "[Google](https://google.com)", to: message.chat, parseMode: .markdown, disableWebPagePreview: true, disableNotification: true)
do {
try bot.send(message: "[Google](https://google.com)", to: message.chat, parseMode: .markdown, disableWebPagePreview: true, disableNotification: true)
} catch let error {
NSLog("Failed to send message due to: \(error)")
}
}
...
```
Expand All @@ -73,10 +84,14 @@ bot.run { update, bot in
```swift
...
if let message = update?.message {
/* This sends a message replying to another message. */
bot.send(message: "bar", to: message)
/* This doesn't reply to a message. */
bot.send(message: "bar", to: message.chat)
do {
/* This sends a message replying to another message. */
try bot.send(message: "bar", to: message)
/* This doesn't reply to a message. */
try bot.send(message: "bar", to: message.chat)
} catch let error {
NSLog("Failed to send message due to: \(error)")
}
}
...
```
Expand All @@ -85,7 +100,11 @@ bot.run { update, bot in
```swift
...
if let channelPost = update?.channelPost {
bot.send(message: "bar", to: channelPost.chat)
do {
try bot.send(message: "bar", to: channelPost.chat)
} catch let error {
NSLog("Failed to send message due to: \(error)")
}
}
...

Expand All @@ -106,6 +125,12 @@ bot.run { update, bot in
- Location
- Venue
- File
- ParseMode
- ChatAction
- ChatMember
- InlineKeyboardButton
- InlineKeyboardMarkup
- CallbackQuery

Not all the types are supported, checkout more details on [Telegram Bot API](https://core.telegram.org/bots/api#available-types).

Expand All @@ -124,6 +149,11 @@ Not all the types are supported, checkout more details on [Telegram Bot API](htt
- sendContact
- sendChatAction
- getFile
- deleteMessage
- getChatAdministrators
- answerCallbackQuery
- restrictChatMember
- kickChatMember

Not all the methods are supported, checkout more details on [Telegram Bot API](https://core.telegram.org/bots/api#available-methods).

Expand Down
16 changes: 16 additions & 0 deletions Sources/Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Extensions.swift
// ZEGBot
//
// Created by Shane Qi on 11/7/18.
//

import Foundation

extension Date {

var unixTimeInt: Int {
return Int(timeIntervalSince1970)
}

}
Loading

0 comments on commit bc4093f

Please sign in to comment.