Skip to content

Commit 97dc44b

Browse files
authored
Merge pull request #102 from HDCodePractice/master
Add Package.resolved to .gitignore
2 parents 8070217 + cf16b1c commit 97dc44b

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

Examples/hello-bot/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ playground.xcworkspace
4141
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
4242
Packages/
4343
.build/
44+
Package.resolved
4445

4546
# CocoaPods
4647
#
@@ -59,7 +60,7 @@ Carthage/Build
5960

6061
# fastlane
6162
#
62-
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
63+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
6364
# screenshots whenever they are needed.
6465
# For more information about the recommended setup visit:
6566
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

Examples/shopster-bot/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ db.sqlite
44
/.build
55
/Packages
66
/*.xcodeproj
7+
Package.resolved

Examples/word-reverse-bot/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ playground.xcworkspace
4141
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
4242
Packages/
4343
.build/
44+
Package.resolved
4445

4546
# CocoaPods
4647
#
@@ -59,7 +60,7 @@ Carthage/Build
5960

6061
# fastlane
6162
#
62-
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
63+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
6364
# screenshots whenever they are needed.
6465
# For more information about the recommended setup visit:
6566
# https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ let bot = TelegramBot(token: token)
149149

150150
while let update = bot.nextUpdateSync() {
151151
if let message = update.message, let from = message.from, let text = message.text {
152-
bot.sendMessageAsync(chatId: from.id,
152+
bot.sendMessageAsync(chatId: ChatId.chat(from.id),
153153
text: "Hi \(from.firstName)! You said: \(text).\n")
154154
}
155155
}
156156

157-
fatalError("Server stopped due to error: \(bot.lastError)")
157+
fatalError("Server stopped due to error: \(String(describing: bot.lastError))")
158158
```
159159

160160
> Do not commit your token to git!
@@ -208,7 +208,7 @@ Press CMD-R to start the bot.
208208
SDK type and request names closely mirror [original Telegram ones](https://core.telegram.org/bots/api).
209209

210210
Swift types and enums were added where appropriate:
211-
211+
212212

213213
```swift
214214
if entity.type == .botCommand { ... }
@@ -379,25 +379,25 @@ Handlers take `Context` argument and return `Bool`.
379379

380380
* If handler returns `true`, command matching stops.
381381
* If handler returns `false`, other paths will be matched.
382-
382+
383383
So, in handler check preconditions and return false if they aren't satisfied:
384384

385385
```swift
386386
router["reboot"] = { context in
387387
guard let fromId = context.fromId where isAdmin(fromId) else { return false }
388-
388+
389389
context.respondAsync("I will now reboot the PC.") { _ in
390390
reboot()
391391
}
392-
392+
393393
return true
394394
}
395395
```
396396

397397
Handler functions can be marked as `throws` and throw exceptions. Router won't process them and will simply pass the exceptions to caller.
398398

399399
`Context` is a request context, it contains:
400-
400+
401401
* `bot` - a reference to the bot.
402402
* `update` - current `Update` structure.
403403
* `message` - convenience method for accessing `update.message`. If `update.message` is nil, fallbacks to `update.edited_message`, then to `update.callback_query?.message`.
@@ -428,21 +428,21 @@ extension Context {
428428
var session: Session { return properties["session"] as! Session }
429429
}
430430
```
431-
431+
432432
`Context` also contains a few helper methods and variables:
433-
433+
434434
* `privateChat` - true, if this is a private chat with bot, false for all group chat types.
435435
* `chatId` - shortcut for message?.chat.id. If message is nil, tries to retrieve chatId from other `Update` fields.
436436
* `fromId` - shortcut for message?.from?.id. If message is nil, tries to retrieve fromId from other `Update` fields.
437437
* `respondAsync`, `respondSync` - works as `sendMessage(chatId, ...)`
438438
* `respondPrivatelyAsync/Sync("text", groupText: "text")` - respond to user privately, sending a short message to the group if this was a group chat. For example:
439-
439+
440440
```swift
441441
context.respondPrivatelyAsync("Command list: ...",
442442
groupText: "Please find a list of commands in a private message.")
443443
```
444444

445-
* `reportErrorAsync/Sync(text: "User text", errorDescription: "Detailed error description for administrator")` - sends a short message to user and prints detailed error description to a console. `text` parameter can be omitted, in which case user will receive a generic error message.
445+
* `reportErrorAsync/Sync(text: "User text", errorDescription: "Detailed error description for administrator")` - sends a short message to user and prints detailed error description to a console. `text` parameter can be omitted, in which case user will receive a generic error message.
446446

447447
**Text commands**
448448

@@ -603,4 +603,3 @@ Happy coding!
603603
## License
604604

605605
Apache License Version 2.0 with Runtime Library Exception. Please see LICENSE.txt for more information.
606-

0 commit comments

Comments
 (0)