Skip to content
Snippets Groups Projects
Commit be2946fc authored by Ophestra's avatar Ophestra
Browse files

accept discord user IDs as negative integers and create user channels for them automatically

parent 3aecc901
No related branches found
No related tags found
No related merge requests found
...@@ -13,8 +13,9 @@ var ( ...@@ -13,8 +13,9 @@ var (
confPath string confPath string
parsed = false parsed = false
discordBridge = make(map[string]bridgeConf) discordPMQueue = make(map[string]*bridgeConf)
telegramBridge = make(map[int64]bridgeConf) discordBridge = make(map[string]*bridgeConf)
telegramBridge = make(map[int64]*bridgeConf)
) )
func init() { func init() {
...@@ -95,10 +96,14 @@ func setupConfig() { ...@@ -95,10 +96,14 @@ func setupConfig() {
for _, c := range config.Bridges.Item { for _, c := range config.Bridges.Item {
if c.Discord.Enable { if c.Discord.Enable {
discordBridge[strconv.Itoa(c.Discord.ID)] = c if c.Discord.ID < 0 {
discordPMQueue[strconv.Itoa(c.Discord.ID)] = &c
} else {
discordBridge[strconv.Itoa(c.Discord.ID)] = &c
}
} }
if c.Telegram.Enable { if c.Telegram.Enable {
telegramBridge[int64(c.Telegram.ID)] = c telegramBridge[int64(c.Telegram.ID)] = &c
} }
} }
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"log" "log"
"strconv"
"strings" "strings"
) )
...@@ -41,7 +42,7 @@ func openDiscord() { ...@@ -41,7 +42,7 @@ func openDiscord() {
session = s session = s
} }
session.Identify.Intents = discordgo.IntentsGuildMessages session.Identify.Intents = discordgo.IntentsGuildMessages | discordgo.IntentsDirectMessages
session.Token = "Bot " + config.Discord.Token session.Token = "Bot " + config.Discord.Token
if err := session.Open(); err != nil { if err := session.Open(); err != nil {
...@@ -58,6 +59,23 @@ func openDiscord() { ...@@ -58,6 +59,23 @@ func openDiscord() {
application = app application = app
} }
for uid, c := range discordPMQueue {
id := strconv.Itoa(-c.Discord.ID)
if st, err := session.UserChannelCreate(id); err != nil {
log.Printf("error creating user channel for %s: %s", id, err)
} else {
if c.Discord.ID, err = strconv.Atoi(st.ID); err != nil {
log.Printf("error parsing discord response for user channel: %s", err)
} else {
if config.System.Verbose {
log.Printf("configured user %s with channel %s", id, st.ID)
}
discordBridge[st.ID] = c
delete(discordPMQueue, uid)
}
}
}
ready <- struct{}{} ready <- struct{}{}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment