Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /pad command to post an editor.xdc to a group #1

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
dist/
coverage-percent.out
coverage.out
coverage.out
.idea/*
Binary file added editor.xdc
Binary file not shown.
43 changes: 38 additions & 5 deletions invitebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ func onBotInit(cli *botcli.BotCli, bot *deltachat.Bot, cmd *cobra.Command, args
if err != nil {
cli.Logger.Error(err)
}
err = bot.Rpc.SetConfig(accId, "delete_device_after", option.Some("1800"))
if err != nil {
cli.Logger.Error(err)
}
Comment on lines -43 to -46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bot needs to save its messages locally for this feature to work, so I guess this is a dealbreaker for merging it into main. I guess I will fork this instead.

}
}
}
Expand All @@ -56,6 +52,10 @@ func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.Msg
return
}

if msg.SystemMessageType == deltachat.SysmsgMemberAddedToGroup {
resendPads(bot.Rpc, accId, msg.ChatId)
}

if !msg.IsBot && !msg.IsInfo && msg.FromId > deltachat.ContactLastSpecial {
chat, err := bot.Rpc.GetBasicChatInfo(accId, msg.ChatId)
if err != nil {
Expand All @@ -81,6 +81,8 @@ func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.Msg
logger.Error(err)
}
}
case "/pad":
sendPad(bot.Rpc, accId, msg.ChatId, msg.Text)
case "/help":
sendHelp(bot.Rpc, accId, msg.ChatId)
default:
Expand All @@ -98,13 +100,44 @@ func onNewMsg(bot *deltachat.Bot, accId deltachat.AccountId, msgId deltachat.Msg
}
}

func sendPad(rpc *deltachat.Rpc, accId deltachat.AccountId, chatId deltachat.ChatId, command string) {
description := command[5:] // bot adds text after /pad as description to the editor.xdc message
editor_path := "editor.xdc"
_, err := rpc.SendMsg(accId, chatId, deltachat.MsgData{Text: description, File: editor_path})
if err != nil {
cli.GetLogger(accId).With("chat", chatId).Error(err)
}
}

func resendPads(rpc *deltachat.Rpc, accId deltachat.AccountId, chatId deltachat.ChatId) {
var toResend []deltachat.MsgId
selfAddr, err := rpc.GetConfig(accId, "addr")
if err == nil {
msgIds, _ := rpc.GetMessageIds(accId, chatId, false, false)
for _, id := range msgIds {
msg, _ := rpc.GetMessage(accId, id)
senderaddress := msg.Sender.Address
if senderaddress == selfAddr.Unwrap() && msg.WebxdcInfo != nil {
toResend = append(toResend, id)
}
}
err := rpc.ResendMessages(accId, toResend)
if err != nil {
cli.Logger.Error("Resending messages failed.")
}
}
}

func sendHelp(rpc *deltachat.Rpc, accId deltachat.AccountId, chatId deltachat.ChatId) {
text := "I am a bot that can help you invite friends to your private groups.\n\n"
text += "You can also share your own invitation QR with them so why would you need me?\n"
text += "If you share your QR, your friends will be able to join only when you are online, but since I am a bot I am always online!\n\n"
text += "To get the invitation QR of a group, add me to the group and send in the group:\n\n/invite\n\n"
text += "I will share the invitation QR, you can then send it to friends you want to invite.\n\n"
text += "If you want to revoque te invitation QR just remove me from the group"
text += "If you want to revoque te invitation QR just remove me from the group.\n\n"
text += "To create a new shared editor for the group, you can write:\n\n"
text += "/pad Shopping List for Friday's Example Party\n\n"
text += "I will send an editor to the group, which anyone can edit; and if new members are added, they will see it, too."
_, err := rpc.SendMsg(accId, chatId, deltachat.MsgData{Text: text})
if err != nil {
cli.GetLogger(accId).With("chat", chatId).Error(err)
Expand Down
Loading