Skip to content

Commit

Permalink
Initial Avatar URL Configurable Support (#74)
Browse files Browse the repository at this point in the history
Fixes the relay to use an Avatar API that provides PNG (Discord doesn't
like SVG).

Adds a configurable that can be changed at runtime allowing the URL used
for avatars to be user managed.
  • Loading branch information
llmII authored Feb 13, 2021
1 parent 94d7b3d commit 3928d5d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,27 @@ The binary takes three flags:

The config file is a yaml formatted file with the following fields:

| name | requires restart | default | optional | description |
| ------------------- | ---------------- | ------------------------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `discord_token` | Yes | | No | [The bot user token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) |
| `irc_server` | Yes | | No | IRC server address |
| `channel_mappings` | No | | No | a dict with irc channel as key (prefixed with `#`) and Discord channel ID as value |
| `guild_id` | No | | No | the Discord guild (server) id |
| `irc_pass` | Yes | | Yes | password for connecting to the IRC server |
| `suffix` | No | `~d` | Yes | appended to each Discord user's nickname when they are connected to IRC. If set to `_d2`, if the name will be `bob_d2` |
| `separator` | No | `_` | Yes | used in fallback situations. If set to `-`, the **fallback name** will be like `bob-7247_d2` (where `7247` is the discord user's discriminator, and `_d2` is the suffix) |
| `irc_listener_name` | Yes | `~d` | The name of the irc listener |
| `puppet_username` | No | username of discord account being puppeted | Yes | username to connect to irc with |
| `webirc_pass` | No | | Yes | optional, but recommended for regular (non-simple) usage. this must be obtained by the IRC sysops |
| `debug` | Yes | false | Yes | debug mode |
| `insecure`, | Yes | false | Yes | TLS will skip verification (but still uses TLS) |
| `no_tls`, | Yes | false | Yes | turns off TLS |
| `webhook_prefix`, | Yes | | No | a prefix for webhooks, so we know which ones to keep and which ones to delete |
| `nickserv_identify` | No | | Yes | on connect this message will be sent: `PRIVMSG nickserv IDENTIFY <value>`, you can provide both a username and password if your ircd supports it |
| `cooldown_duration` | No | 86400 (24 hours) | Yes | time in seconds for a discord user to be offline before it's puppet disconnects from irc |
| `show_joinquit` | No | false | yes | displays JOIN, PART, QUIT, KICK on discord |
| `max_nick_length` | No | 30 | yes | Maximum allowed nick length |
| name | requires restart | default | optional | description |
| ------------------- | ---------------- | ---------------------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `avatar_url` | No | `https://ui-avatars.com/api/?name=${USERNAME}` | Yes | The URL for the API to use to tell Discord what Avatar to use for a User when the user's avatar cannot be found at Discord already. |
| `discord_token` | Yes | | No | [The bot user token](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token) |
| `irc_server` | Yes | | No | IRC server address |
| `channel_mappings` | No | | No | a dict with irc channel as key (prefixed with `#`) and Discord channel ID as value |
| `guild_id` | No | | No | the Discord guild (server) id |
| `irc_pass` | Yes | | Yes | password for connecting to the IRC server |
| `suffix` | No | `~d` | Yes | appended to each Discord user's nickname when they are connected to IRC. If set to `_d2`, if the name will be `bob_d2` |
| `separator` | No | `_` | Yes | used in fallback situations. If set to `-`, the **fallback name** will be like `bob-7247_d2` (where `7247` is the discord user's discriminator, and `_d2` is the suffix) |
| `irc_listener_name` | Yes | `~d` | The name of the irc listener |
| `puppet_username` | No | username of discord account being puppeted | Yes | username to connect to irc with |
| `webirc_pass` | No | | Yes | optional, but recommended for regular (non-simple) usage. this must be obtained by the IRC sysops |
| `debug` | Yes | false | Yes | debug mode |
| `insecure`, | Yes | false | Yes | TLS will skip verification (but still uses TLS) |
| `no_tls`, | Yes | false | Yes | turns off TLS |
| `webhook_prefix`, | Yes | | No | a prefix for webhooks, so we know which ones to keep and which ones to delete |
| `nickserv_identify` | No | | Yes | on connect this message will be sent: `PRIVMSG nickserv IDENTIFY <value>`, you can provide both a username and password if your ircd supports it |
| `cooldown_duration` | No | 86400 (24 hours) | Yes | time in seconds for a discord user to be offline before it's puppet disconnects from irc |
| `show_joinquit` | No | false | yes | displays JOIN, PART, QUIT, KICK on discord |
| `max_nick_length` | No | 30 | yes | Maximum allowed nick length |

**The filename.yaml file is continuously read from and many changes will
automatically update on the bridge. This means you can add or remove channels
Expand Down
3 changes: 2 additions & 1 deletion bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

// Config to be passed to New
type Config struct {
AvatarURL string
DiscordBotToken, GuildID string

// Map from Discord to IRC
Expand Down Expand Up @@ -381,7 +382,7 @@ func (b *Bridge) loop() {
avatar = b.discord.GetAvatar(b.Config.GuildID, msg.Username)
if avatar == "" {
// If we don't have a Discord avatar, generate an adorable avatar
avatar = "https://avatars.dicebear.com/api/gridy/" + msg.Username + ".svg"
avatar = strings.ReplaceAll(b.Config.AvatarURL, "${USERNAME}", msg.Username)
}

if len(username) == 1 {
Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ irc_server: localhost:6697
guild_id: 315277951597936640
nickserv_identify: password123

# default is as below
# avatar_url: https://ui-avatars.com/api/?name=${USERNAME}

# Updating this will automatically add or remove puppets from channels
channel_mappings:
"#bottest chanKey": 316038111811600387
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func main() {
*insecure = viper.GetBool("insecure")
}
//
viper.SetDefault("avatar_url", "https://ui-avatars.com/api/?name=${USERNAME}")
avatarURL := viper.GetString("avatar_url")
//
viper.SetDefault("irc_listener_name", "~d")
ircUsername := viper.GetString("irc_listener_name") // Name for IRC-side bot, for listening to messages.
// Name to Connect to IRC puppet account with
Expand Down Expand Up @@ -115,6 +118,7 @@ func main() {
SetLogDebug(*debugMode)

dib, err := bridge.New(&bridge.Config{
AvatarURL: avatarURL,
DiscordBotToken: discordBotToken,
GuildID: guildID,
IRCListenerName: ircUsername,
Expand Down Expand Up @@ -170,6 +174,9 @@ func main() {
dib.SetIRCListenerName(ircUsername)
}

avatarURL := viper.GetString("avatar_url")
dib.Config.AvatarURL = avatarURL

if debug := viper.GetBool("debug"); *debugMode != debug {
log.Printf("Debug changed from %+v to %+v", *debugMode, debug)
*debugMode = debug
Expand Down

0 comments on commit 3928d5d

Please sign in to comment.