aboutsummaryrefslogtreecommitdiff
path: root/telegram/utils.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-07 19:37:14 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-07 19:37:14 +0300
commit589876eef53ad2a64ffec9e1e47579b80465ac68 (patch)
tree6f66c86de87b4896bde046970070c4e569300531 /telegram/utils.go
parent3e791db2015d47661cc640e41eb6a23914c86ad4 (diff)
Add replace command
Diffstat (limited to 'telegram/utils.go')
-rw-r--r--telegram/utils.go82
1 files changed, 46 insertions, 36 deletions
diff --git a/telegram/utils.go b/telegram/utils.go
index b088069..8e2fdb9 100644
--- a/telegram/utils.go
+++ b/telegram/utils.go
@@ -411,7 +411,7 @@ func (c *Client) messageToPrefix(message *client.Message, fileString string) str
// ProcessOutgoingMessage executes commands or sends messages to mapped chats
func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int64, returnJid string) {
- if strings.HasPrefix(text, "/") {
+ if messageID == 0 && strings.HasPrefix(text, "/") {
// try to execute a command
response, isCommand := c.ProcessChatCommand(chatID, text)
if response != "" {
@@ -430,53 +430,63 @@ func (c *Client) ProcessOutgoingMessage(chatID int64, text string, messageID int
log.Warnf("Send message to chat %v", chatID)
- // quotations
- var reply int64
- replySlice := replyRegex.FindStringSubmatch(text)
- if len(replySlice) > 1 {
- reply, _ = strconv.ParseInt(replySlice[1], 10, 64)
- }
-
- // attach a file
- var file *client.InputFileRemote
- if c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) {
- file = &client.InputFileRemote{
- Id: text,
- }
- }
-
- // remove first line from text
- if file != nil || reply != 0 {
- newlinePos := strings.Index(text, newlineChar)
- if newlinePos != -1 {
- text = text[newlinePos+1:]
+ if messageID != 0 {
+ formattedText := &client.FormattedText{
+ Text: text,
}
- }
- formattedText := &client.FormattedText{
- Text: text,
- }
- var message client.InputMessageContent
- if file != nil {
- // we can try to send a document
- message = &client.InputMessageDocument{
- Document: file,
- Caption: formattedText,
- }
- } else {
// compile our message
- message = &client.InputMessageText{
+ message := &client.InputMessageText{
Text: formattedText,
}
- }
- if messageID != 0 {
c.client.EditMessageText(&client.EditMessageTextRequest{
ChatId: chatID,
MessageId: messageID,
InputMessageContent: message,
})
} else {
+ // quotations
+ var reply int64
+ replySlice := replyRegex.FindStringSubmatch(text)
+ if len(replySlice) > 1 {
+ reply, _ = strconv.ParseInt(replySlice[1], 10, 64)
+ }
+
+ // attach a file
+ var file *client.InputFileRemote
+ if c.content.Upload != "" && strings.HasPrefix(text, c.content.Upload) {
+ file = &client.InputFileRemote{
+ Id: text,
+ }
+ }
+
+ // remove first line from text
+ if file != nil || reply != 0 {
+ newlinePos := strings.Index(text, newlineChar)
+ if newlinePos != -1 {
+ text = text[newlinePos+1:]
+ }
+ }
+
+ formattedText := &client.FormattedText{
+ Text: text,
+ }
+
+ var message client.InputMessageContent
+ if file != nil {
+ // we can try to send a document
+ message = &client.InputMessageDocument{
+ Document: file,
+ Caption: formattedText,
+ }
+ } else {
+ // compile our message
+ message = &client.InputMessageText{
+ Text: formattedText,
+ }
+ }
+
c.client.SendMessage(&client.SendMessageRequest{
ChatId: chatID,
ReplyToMessageId: reply,