Skip to content

Commit

Permalink
follow invites
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffany352 committed May 28, 2024
1 parent f0673d2 commit b7cd376
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions irc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ that a user would be able to pwn your system though.
In an IRC channel, prefix a message with `rink: ` and then put your
query after. Direct messages are always interpreted as queries.

To add rink to a new channel, you can invite it and it will follow. It
won't remember this if the bot is restarted though.

## How to operate it

You'll need to create a `config.toml` for the bot. It uses the following
format (the values show the defaults):

```toml
[behavior]
follow_invites = true

[limits]
# Not yet implemented
enabled = true
Expand Down
15 changes: 15 additions & 0 deletions irc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,26 @@ impl Default for Currency {
}
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(default, deny_unknown_fields)]
pub struct Behavior {
pub follow_invites: bool,
}

impl Default for Behavior {
fn default() -> Self {
Behavior {
follow_invites: true,
}
}
}

#[derive(Serialize, Deserialize, Clone, Default)]
#[serde(default, deny_unknown_fields)]
pub struct Config {
pub limits: Limits,
pub currency: Currency,
pub behavior: Behavior,
pub servers: Vec<IrcConfig>,
}

Expand Down
2 changes: 1 addition & 1 deletion irc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn write_irc_string(out: &mut String, config: &Config, spans: &[Span]) {
}
}

fn write_irc_token(out: &mut String, config: &Config, text: &str, token: FmtToken) {
fn write_irc_token(out: &mut String, _config: &Config, text: &str, token: FmtToken) {
let (prefix, postfix) = match token {
FmtToken::Plain => ("", ""),
FmtToken::Error => ("\x0304", "\x03"),
Expand Down
4 changes: 4 additions & 0 deletions irc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ async fn server_task(config: config::Config, index: usize) {
&channel
};
client.send_notice(where_to, result).unwrap();
} else if let Command::INVITE(_nickname, channel) = message.command {
if config.behavior.follow_invites {
client.send_join(channel).unwrap();
}
}
}
}
Expand Down

0 comments on commit b7cd376

Please sign in to comment.