- Start working on bot commands parsing
- Added load shedding command test
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-13 11:48:24 +02:00
parent 08c9dd0fbc
commit eebc5d4464
1 changed files with 46 additions and 0 deletions

View File

@ -2,6 +2,7 @@ module botty.bot;
import birchwood;
import lumars;
import std.conv : to;
public class Bot : Client
{
@ -18,10 +19,55 @@ public class Bot : Client
{
// Authenticate
connect();
// Wait a little then try join (TODO: Should we not detect this in birchwood perhaps)
// TODO: Join channels listed in configuration
joinChannel("#general");
}
public override void onChannelMessage(Message fullMessage, string channel, string msgBody)
{
// TODO: Implement me
// fullMessage.getFrom
// channelMessage("Yes I received '"~msgBody~"' BOI!", "#general");
reactCommand(fullMessage, channel, msgBody);
}
public void reactCommand(Message fullMessage, string channel, string msgBody)
{
fullMessage.getFrom();
import std.stdio;
import std.string;
writeln(msgBody);
writeln(split(msgBody, " "));
string[] stuff = split(msgBody, " ");
string command = stuff[1];
if(command == "eskont")
{
import eskomcalendar;
EskomCalendar calendar = new EskomCalendar();
string area = "western-cape-worscester";
string message = "Load shedding for area '"~area~"':";
channelMessage(message, channel);
Schedule[] schedules = calendar.getSchedules(area);
foreach(Schedule schedule; schedules)
{
message = bold("From")~" "~italics(to!(string)(schedule.getStart())~" "~bold("Till")~" "~italics(to!(string)(schedule.getFinish())));
channelMessage(message, channel);
}
}
}
}