mirror of
https://git.klmp200.net/ALFRED/ALFRED.git
synced 2025-01-18 10:36:44 +01:00
Best effort to provide a unpublish option
This commit is contained in:
parent
da0729d234
commit
0acdcb6351
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Amalvy Arthur
|
* @Authors: Amalvy Arthur, Bartuccio Antoine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This module uses a property named "subscribed_chats" in the shared Users structure.
|
// This module uses a property named "subscribed_chats" in the shared Users structure.
|
||||||
@ -54,6 +54,12 @@ func Subscribe(m *tb.Message) {
|
|||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.Sender.Username == "" {
|
||||||
|
shared.Bot.Send(m.Chat, "Il faut avoir enregistré un username pour pouvoir utiliser cette fonction")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
||||||
if !exists {
|
if !exists {
|
||||||
shared.Bot.Send(m.Chat, "Abonnement au chat : "+m.Chat.Title)
|
shared.Bot.Send(m.Chat, "Abonnement au chat : "+m.Chat.Title)
|
||||||
@ -82,6 +88,12 @@ func Unsubscribe(m *tb.Message) {
|
|||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.Sender.Username == "" {
|
||||||
|
shared.Bot.Send(m.Chat, "Il faut avoir enregistré un username pour pouvoir utiliser cette fonction")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
userSubscribedChats, exists := shared.Users.Get(m.Sender.Username, "subscribed_chats")
|
||||||
if !exists || len(userSubscribedChats) == 0 {
|
if !exists || len(userSubscribedChats) == 0 {
|
||||||
shared.Bot.Send(m.Chat, "Vous n'êtes abonné à aucun chat")
|
shared.Bot.Send(m.Chat, "Vous n'êtes abonné à aucun chat")
|
||||||
@ -135,11 +147,6 @@ func Publish(m *tb.Message) {
|
|||||||
// Command syntax (while replying to a message) : /unpublish
|
// Command syntax (while replying to a message) : /unpublish
|
||||||
func Unpublish(m *tb.Message) {
|
func Unpublish(m *tb.Message) {
|
||||||
|
|
||||||
// This is not working at the moment
|
|
||||||
// This can't work because when retrieving, the newly send message
|
|
||||||
// has a different ID from the one stored so you can't detect that's
|
|
||||||
// it's in the database except if you find the original message
|
|
||||||
// which is very unlikely to happen
|
|
||||||
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup {
|
if m.Chat.Type != tb.ChatGroup && m.Chat.Type != tb.ChatSuperGroup {
|
||||||
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
shared.Bot.Send(m.Chat, "Cette commande n'est pas autorisée pour ce type de chat")
|
||||||
return
|
return
|
||||||
@ -159,7 +166,16 @@ func Unpublish(m *tb.Message) {
|
|||||||
filteredPublishedMessages := []tb.Message{}
|
filteredPublishedMessages := []tb.Message{}
|
||||||
found := false
|
found := false
|
||||||
for _, message := range publishedMessages {
|
for _, message := range publishedMessages {
|
||||||
if message.ID == m.ReplyTo.ID {
|
// You can't just compare messages id because
|
||||||
|
// when retrieving, the newly send message
|
||||||
|
// has a different ID from the one stored so you can't detect that's
|
||||||
|
// it's in the database except if you find the original message
|
||||||
|
// which is very unlikely to happen
|
||||||
|
// As a workaround, we check the original sender, original unix time
|
||||||
|
// and associated text
|
||||||
|
if message.Sender.ID == m.ReplyTo.OriginalSender.ID &&
|
||||||
|
message.Unixtime == int64(m.ReplyTo.OriginalUnixtime) &&
|
||||||
|
message.Text == m.ReplyTo.Text {
|
||||||
found = true
|
found = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,9 @@ The publish module intend to be a "multi-pin" feature for chats, allowing users
|
|||||||
|
|
||||||
**Usage location** : Group chat only
|
**Usage location** : Group chat only
|
||||||
|
|
||||||
**Command syntax** : /unpublish [publication ID]
|
**usage conditions** : Reply to the message to unpublish
|
||||||
|
|
||||||
|
**Command syntax** : /unpublish
|
||||||
|
|
||||||
|
|
||||||
### Retrieve
|
### Retrieve
|
||||||
|
Loading…
Reference in New Issue
Block a user