- Switched to array-based channels list

Config

- Use `channels` array instead of string

App

- Pass in `Config` to `Bot` constructor

Bot

- Constructor now takes in `Config` instance and then will extract the channels to join after authentication from said `Config` struct
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-24 21:48:24 +02:00
parent dd253b6292
commit 2e94ecef69
4 changed files with 10 additions and 12 deletions

View File

@ -2,5 +2,5 @@
"serverAddr": "rany.irc.bnet.eu.org",
"serverPort": 6667,
"nickname": "bottyng",
"channels": "#bot,#tlang"
"channels": ["#bot", "#tlang"]
}

View File

@ -37,11 +37,9 @@ void main(string[] args)
// // Set the fakelag to 1 second
// connInfo.setFakeLag(1);
// Extract the channels to connect to
string[] channels = split(config.channels, ",");
Bot botty = new Bot(connInfo, channels);
Bot botty = new Bot(connInfo, config);
// Start the bot
botty.start();

View File

@ -5,17 +5,17 @@ import lumars;
import std.conv : to;
import core.thread : Thread, dur;
import botty.mod : Mod;
import botty.config : Config;
public class Bot : Client
{
private string[] channels;
private Config config;
private Mod[] modules;
this(ConnectionInfo info, string[] channels)
this(ConnectionInfo info, Config config)
{
super(info);
this.channels = channels;
this.config = config;
// TODO: testing addTestModules
addTestModules();
@ -51,7 +51,7 @@ public class Bot : Client
Thread.sleep(dur!("seconds")(2));
// Join channels requested
joinChannel(channels);
joinChannel(config.channels);
}
public override void onChannelMessage(Message fullMessage, string channel, string msgBody)

View File

@ -21,9 +21,9 @@ public struct Config
string nickname;
/**
* Channels to join (in CSV format (for now))
* Channels to join
*/
string channels;
string[] channels;
}
public Config getConfig(string configPath)