Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bridge thing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
random asynchronous nightmare distributor
bridge thing
Commits
be2946fc
Commit
be2946fc
authored
Nov 9, 2021
by
Ophestra
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.go
+9
-4
9 additions, 4 deletions
config.go
discord.go
+19
-1
19 additions, 1 deletion
discord.go
with
28 additions
and
5 deletions
config.go
+
9
−
4
View file @
be2946fc
...
@@ -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
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
discord.go
+
19
−
1
View file @
be2946fc
...
@@ -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
{}{}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment