-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting options feature #76
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package main | |
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"path/filepath" | ||
|
@@ -94,10 +95,21 @@ func main() { | |
// | ||
viper.SetDefault("irc_puppet_prejoin_commands", []string{"MODE ${NICK} +D"}) | ||
ircPuppetPrejoinCommands := viper.GetStringSlice("irc_puppet_prejoin_commands") // Commands for each connection to send before joining channels | ||
rawDiscordFormat := viper.GetStringMapString("discord_format") | ||
var discordFormat map[string]string | ||
if df, err := setupDiscordFormat(rawDiscordFormat); err == nil { | ||
discordFormat = df | ||
} else { | ||
log.WithError(err).Fatal("discord_format setting is invalid") | ||
return | ||
} | ||
// | ||
viper.SetDefault("avatar_url", "https://ui-avatars.com/api/?name=${USERNAME}") | ||
avatarURL := viper.GetString("avatar_url") | ||
// | ||
viper.SetDefault("irc_format", "<${USER}#${DISCRIMINATOR}> ${CONTENT}") | ||
ircFormat := viper.GetString("irc_format") | ||
// | ||
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 | ||
|
@@ -142,7 +154,9 @@ func main() { | |
AvatarURL: avatarURL, | ||
Discriminator: discriminator, | ||
DiscordBotToken: discordBotToken, | ||
DiscordFormat: discordFormat, | ||
GuildID: guildID, | ||
IRCFormat: ircFormat, | ||
IRCListenerName: ircUsername, | ||
IRCServer: ircServer, | ||
IRCServerPass: ircPassword, | ||
|
@@ -227,6 +241,14 @@ func main() { | |
} | ||
dib.Config.DiscordIgnores = discordIgnores | ||
|
||
rawDiscordFormat := viper.GetStringMapString("discord_format") | ||
if discordFormat, err := setupDiscordFormat(rawDiscordFormat); err == nil { | ||
dib.Config.DiscordFormat = discordFormat | ||
} else { | ||
log.WithError(err).Error("discord_format setting is invalid, this setting has not been updated") | ||
} | ||
dib.Config.IRCFormat = viper.GetString("irc_format") | ||
|
||
chans := viper.GetStringMapString("channel_mappings") | ||
equalChans := reflect.DeepEqual(chans, channelMappings) | ||
if !equalChans { | ||
|
@@ -282,6 +304,34 @@ func setupFilter(filters []string) []glob.Glob { | |
return matchers | ||
} | ||
|
||
func setupDiscordFormat(discordFormat map[string]string) (map[string]string, error) { | ||
var err error | ||
// lowercase to match that YAML lowercases it | ||
discordFormatDefaults := map[string]string{ | ||
"pm": "${SERVER},${NICK}!${IDENT}@${HOST} - ${NICK}@${DISCRIMINATOR}: ${CONTENT}", | ||
"join": "_${NICK} joined (${IDENT}@${HOST})_", | ||
"part": "_${NICK} left (${IDENT}@${HOST}) - ${CONTENT}_", | ||
"quit": "_${NICK} quit (${IDENT}@${HOST}) - Quit: ${CONTENT}_", | ||
"kick": "_${TARGET} was kicked by ${NICK} - ${CONTENT}_", | ||
"nick": "_${NICK} changed nick to ${CONTENT}_", | ||
} | ||
Comment on lines
+313
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still like the default to be off (empty string), so maybe we should move this to config.yml, but commented out. Additionally, please could you try to match the original format that was created programmatically, if possible? The original ones were designed to match irccloud's output 1:1, which I believe to be a reasonable default for good UX. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I hate typing all caps and special symbols pretend the following are the interpolators...
Now may be a good time to discuss what we want the interpolators to actually be. I'm not picky, and seeing as I only must type them once, the super-long-all-caps ones are okay with me. Discussing them and having to reference them is a pain though. For For
So, 1st question - Do you want PM to default to "" (empty) (I don't think so but good to figure this out now). An example of 2 and why it leads to 3 is... consider "$n/$d!$i@$h: $c"... Looks like a good idea but I've seen pylinks use '/' in nicks. So even formatting appealingly will lead to 3 unless we pick a symbol that is impossible to be found in a hostmask to set as a seperator between $n and $d and from there we need to change PM reply parsing to match so it's a simple "copy/paste" vs having to type and pick and figure out which part is which. If we went with '/' then PM reply parsing would need a heuristic or a "try few different ways until truly fail" both of which would lead to suprises when you have "llmII/pylink/actual_network!ident@host" and "llmII/same_actual_network!ident@host". I'd also argue for dropping out $s (why would that be needed any more with network discriminators?) $s has the potential to leak information if the puppet connects to a "hidden" server over the public internet to some degree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In what way are you personally planning to use the PM format? It seems like an outlier, and does not seem to be necessary for configuration, from my point of view. |
||
|
||
for ev, format := range discordFormatDefaults { | ||
if df, ok := discordFormat[ev]; !ok || df == "" { | ||
discordFormat[ev] = format | ||
} | ||
} | ||
|
||
for ev := range discordFormat { | ||
if _, ok := discordFormatDefaults[ev]; !ok { | ||
err = fmt.Errorf("Unknown format key %s", ev) | ||
break | ||
} | ||
} | ||
|
||
return discordFormat, err | ||
} | ||
|
||
func SetLogDebug(debug bool) { | ||
logger := log.StandardLogger() | ||
if debug { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make
m.formatIRCMessage
return a slice (so that it only needs to be passedmsg
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean move
m.bridge.ircListener.Privmsg(channel, m.formatIRCMessage(msg, line))
out of the "for range" and have it just takemsg
? Probably better to do it that way actually, instead of formatting per channel. Could you explain what you mean by return a slice however?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, rereading the code, but basically the for range wrapping this splits the line on '\n' and that's why I made it take a line argument. The function is to format lines, not to split lines out and format them. That said the formatting works on things besides lines anyway so still moving that outside of the for range and letting it then be split on '\n' works too I would think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking through this more, it wouldn't work,
formatIRCMessage
would need to be aware of new lines '\n' and apply each line as content.Say the format is
"\x02${USER}\x02 ${CONTENT}"
- if we treat the entiremsg.Content
as the singular content then only the first line will have the"\x02${USER}\x02"
part and the rest of the lines will have no prefix of the user.That or I'm misunderstanding what is wanted to be done...
The reason
formatIRCMessage
needs to remain unaware that it may be handling more than one line is if I add support for including the referenced content in the message (for edit/reply) then this will also be applying for IRCConnections when pushing into theirmessages
channel.