Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire ab83859175 Bot
- Enabled `.ub` command
2023-07-03 14:00:33 +02:00
Tristan B. Velloza Kildaire 94c5403ebd UrbanDict
- WIP: New module
2023-07-03 14:00:20 +02:00
2 changed files with 67 additions and 1 deletions

View File

@ -29,12 +29,14 @@ public class Bot : Client
import botty.modules.ping : Ping;
import botty.modules.rot13 : Rot13;
import botty.modules.translate : Translate;
import botty.modules.urbandict : UrbanDict;
modules ~= [
new DeavmiComedy(this),
new EskomCalendarAPI(this),
new Ping(this),
new Rot13(this),
new Translate(this)
new Translate(this),
new UrbanDict(this)
];
}

View File

@ -0,0 +1,64 @@
/**
* Urban Dictionary module
*/
module botty.modules.urbandict;
import botty.mod;
import botty.bot : Bot;
import birchwood.protocol.messages : Message;
/**
* Urban dictionary command
*/
public final class UrbanDict : Mod
{
private static string commandStr = ".ub";
/**
* Base URL to use for constructing requests
*/
private static string ubBase = "http://api.urbandictionary.com/v0/define?term=";
/**
* Constructs a new `UrbanDict` module with the provided
* bot to associate with
*
* Params:
* bot = the `Bot` to associate with
*/
this(Bot bot)
{
super(bot);
}
public override bool accepts(Message fullMessage, string channel, string messageBody)
{
import std.string : startsWith;
return messageBody.startsWith(commandStr);
}
public override void react(Message fullMessage, string channel, string messageBody)
{
import std.string : indexOf, strip;
import std.stdio;
import std.string : split;
/**
* Split the ` .ub dictionarydef`
* into two parts `[.ub, dictionarydef]`
*/
string[] splits = split(strip(messageBody), " ");
writeln("splits", splits);
if(splits.length >= 2)
{
string searchTerm = splits[1];
getBot().channelMessage("hehe", channel);
}
else
{
// Do nothing
}
}
}