-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from 40ants/many-changes
Large update.
- Loading branch information
Showing
19 changed files
with
713 additions
and
149 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"HTTP" | ||
"HTTPS" | ||
"MIME" | ||
"CL" | ||
"TODO" | ||
"MIT" | ||
"API" | ||
|
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
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
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 |
---|---|---|
@@ -1,42 +1,37 @@ | ||
(defpackage #:cl-telegram-bot/entities/core | ||
(uiop:define-package #:cl-telegram-bot/entities/core | ||
(:use #:cl) | ||
(:import-from #:cl-telegram-bot/utils | ||
#:make-keyword) | ||
(:import-from #:arrows | ||
#:->) | ||
(:nicknames #:cl-telegram-bot/entities) | ||
(:export | ||
#:make-entity | ||
#:make-entity-internal)) | ||
(:import-from #:cl-telegram-bot/message | ||
#:message) | ||
(:import-from #:cl-telegram-bot/chat | ||
#:get-chat) | ||
(:import-from #:cl-telegram-bot/entities/generic | ||
#:make-entity-internal) | ||
(:nicknames #:cl-telegram-bot/entities)) | ||
(in-package cl-telegram-bot/entities/core) | ||
|
||
|
||
(defclass entity () | ||
((raw-data :initarg :raw-data | ||
((payload :type message | ||
:initarg :payload | ||
:reader get-payload) | ||
(raw-data :initarg :raw-data | ||
:reader get-raw-data))) | ||
|
||
|
||
(defclass unsupported-entity (entity) | ||
()) | ||
|
||
|
||
(defgeneric make-entity-internal (entity-type payload data) | ||
(:documentation "Extendable protocol to support entities of different kinds. | ||
First argument is a keyword, denoting a type of the entity. | ||
Payload is an object of type `message'. | ||
And data is a plist with data, describing the entity.")) | ||
|
||
|
||
(defmethod make-entity-internal (entity-type payload data) | ||
(declare (ignorable payload entity-type)) | ||
(make-instance 'unsupported-entity | ||
:raw-data data)) | ||
:raw-data data | ||
:payload payload)) | ||
|
||
|
||
(defun make-entity (payload data) | ||
(let ((entity-type (-> data | ||
(getf :|type|) | ||
(make-keyword)))) | ||
(make-entity-internal entity-type | ||
payload | ||
data))) | ||
(defmethod get-chat ((command entity)) | ||
(get-chat (get-payload command))) |
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,25 @@ | ||
(uiop:define-package #:cl-telegram-bot/entities/generic | ||
(:use #:cl) | ||
(:import-from #:cl-telegram-bot/utils | ||
#:make-keyword) | ||
(:import-from #:arrows | ||
#:->) | ||
(:export #:make-entity | ||
#:make-entity-internal)) | ||
(in-package #:cl-telegram-bot/entities/generic) | ||
|
||
|
||
(defgeneric make-entity-internal (entity-type payload data) | ||
(:documentation "Extendable protocol to support entities of different kinds. | ||
First argument is a keyword, denoting a type of the entity. | ||
Payload is an object of type `message'. | ||
And data is a plist with data, describing the entity.")) | ||
|
||
|
||
(defun make-entity (payload data) | ||
(let ((entity-type (-> data | ||
(getf :|type|) | ||
(make-keyword)))) | ||
(make-entity-internal entity-type | ||
payload | ||
data))) |
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,65 @@ | ||
(uiop:define-package #:cl-telegram-bot/envelope | ||
(:use #:cl) | ||
(:import-from #:cl-telegram-bot/pipeline | ||
#:process) | ||
(:export #:wrapped-message | ||
#:envelope | ||
#:edited-message | ||
#:channel-post | ||
#:edited-channel-post | ||
#:edited-message-p | ||
#:channel-post-p)) | ||
(in-package #:cl-telegram-bot/envelope) | ||
|
||
|
||
(defvar *wrappers* nil | ||
"This var will hold a list of wrappers during the call to PROCESS generic-function. It is used by functions CHANNEL-POST-P and EDITED-MESSAGE-P.") | ||
|
||
|
||
(defclass envelope () | ||
((message :initarg :message | ||
:reader wrapped-message)) | ||
(:documentation "This is the container for a message. From the type of container we can understand if this message was sent to a channel or maybe edited, etc.")) | ||
|
||
|
||
(defclass edited-message (envelope) | ||
() | ||
(:documentation "This container wraps CL-TELEGRAM-BOT/MESSAGE:MESSAGE when user edits a message.")) | ||
|
||
|
||
(defclass channel-post (envelope) | ||
() | ||
(:documentation "This container wraps CL-TELEGRAM-BOT/MESSAGE:MESSAGE when somebody sends a message to a channel.")) | ||
|
||
|
||
(defclass edited-channel-post (envelope) | ||
() | ||
(:documentation "This container wraps CL-TELEGRAM-BOT/MESSAGE:MESSAGE when somebody edits a message in a channel.")) | ||
|
||
|
||
(defmethod process ((bot t) (envelope envelope)) | ||
"By default, just calls `process' on the wrapped message." | ||
(log:debug "Processing envelope" envelope) | ||
(let ((message (wrapped-message envelope)) | ||
(*wrappers* (cons envelope *wrappers*))) | ||
(process bot message))) | ||
|
||
|
||
(declaim (ftype (function () boolean) | ||
channel-post-p)) | ||
|
||
(defun channel-post-p () | ||
"Returns T if current message was posted to a channel." | ||
(loop for wrapper in *wrappers* | ||
thereis (or (typep wrapper 'channel-post) | ||
(typep wrapper 'edited-channel-post)))) | ||
|
||
|
||
(declaim (ftype (function () boolean) | ||
edited-message-p)) | ||
|
||
(defun edited-message-p () | ||
"Returns T if current message is an update for existing message in the channel of group chat." | ||
(loop for wrapper in *wrappers* | ||
thereis (or (typep wrapper 'edited-message) | ||
(typep wrapper 'edited-channel-post)))) |
Oops, something went wrong.