Skip to content

Commit

Permalink
add support for multiple owners
Browse files Browse the repository at this point in the history
  • Loading branch information
akshettrj committed Jan 14, 2023
1 parent 40aa2b8 commit 7e49f6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ telegram:
# api_url: http://localhost:8082 # Uncomment if you have a local bot API server running (for bypassing file size limits)
self_hosted_api: false
owner_id: 704338780
sudo_users_id:
- 704338780
target_chat_id: 704338780 # This is the chat where messages will be forwarded

whatsapp:
Expand Down
11 changes: 6 additions & 5 deletions state/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ type Config struct {
GoExecutable string `yaml:"go_executable"`

Telegram struct {
BotToken string `yaml:"bot_token"`
APIURL string `yaml:"api_url"`
SelfHostedAPI bool `yaml:"self_hosted_api"`
OwnerID int64 `yaml:"owner_id"`
TargetChatID int64 `yaml:"target_chat_id"`
BotToken string `yaml:"bot_token"`
APIURL string `yaml:"api_url"`
SudoUsersID []int64 `yaml:"sudo_users_id"`
OwnerID int64 `yaml:"owner_id"`
TargetChatID int64 `yaml:"target_chat_id"`
SelfHostedAPI bool `yaml:"self_hosted_api"`
} `yaml:"telegram"`

WhatsApp struct {
Expand Down
12 changes: 7 additions & 5 deletions utils/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ func TgSendTextById(b *gotgbot.Bot, chatId int64, threadId int64, text string) e

func TgUpdateIsAuthorized(b *gotgbot.Bot, c *ext.Context) bool {
var (
cfg = state.State.Config
sender = c.EffectiveSender.User
ownerID = cfg.Telegram.OwnerID
cfg = state.State.Config
sender = c.EffectiveSender.User
ownerID = cfg.Telegram.OwnerID
sudoUsersID = cfg.Telegram.SudoUsersID
)

if sender != nil && sender.Id == ownerID {
if sender != nil &&
(slices.Contains(sudoUsersID, sender.Id) || sender.Id == ownerID) {
return true
}

Expand Down Expand Up @@ -682,7 +684,7 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
SenderTimestampMs: proto.Int64(time.Now().UnixMilli()),
Key: &waProto.MessageKey{
RemoteJid: proto.String(waChatJID.String()),
FromMe: proto.Bool(msgToReplyTo != nil && msgToReplyTo.From.Id == cfg.Telegram.OwnerID),
FromMe: proto.Bool(msgToReplyTo != nil && msgToReplyTo.From.Id != b.Id),
Id: proto.String(stanzaId),
},
},
Expand Down

0 comments on commit 7e49f6e

Please sign in to comment.