WEBUI_MODULE brainstorming

Have you created a module that you would like to submit to BudaBot? Post it here, and it might make it into the next release.
Tyrence
The Team
Posts: 1883
Joined: Sat Jan 09, 2010 1:32 am

Re: WEBUI_MODULE brainstorming

Postby Tyrence » Mon Dec 12, 2011 6:23 pm

Marebone wrote:Well, the api command registering you posted above would work for this, right?
Do you need a separate class APICommand for this? Or could you use the normal Command-class, just replace the "guild"-channel with, say "api"?
Tyrence wrote:Command::register($MODULE_NAME, "", "cloak.php", "cloak", "guild", "Shows the status of the city cloak");

Well, in this case, "guild" is the access level, not the channel. The second parameter (in this case "") defines the channel ("" is equivalent to "guild;priv;msg"). But yeah, that is a good idea. Let's use that.
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: WEBUI_MODULE brainstorming

Postby Marebone » Mon Dec 12, 2011 6:27 pm

Oops, yea, my bad :oops:
Tyrence
The Team
Posts: 1883
Joined: Sat Jan 09, 2010 1:32 am

Re: WEBUI_MODULE brainstorming

Postby Tyrence » Mon Dec 12, 2011 7:30 pm

Btw, "API" is just a generic name I came up with in two seconds. Does anyone have a better idea of what we should call this module?
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Teeko
The Team
Posts: 191
Joined: Tue Mar 08, 2011 8:57 am
antispam: Rimor

Re: WEBUI_MODULE brainstorming

Postby Teeko » Tue Dec 13, 2011 1:39 am

Budapi. lol
Tyrence
The Team
Posts: 1883
Joined: Sat Jan 09, 2010 1:32 am

Re: WEBUI_MODULE brainstorming

Postby Tyrence » Tue Dec 13, 2011 5:46 am

Ok so I have implemented this as we've discussed and these are the steps to use this now, and assuming you are running at least revision 2096 from trunk I have written a webpage that you can use to access your bot through the API. Steps:
1) set a password for your character: /tell bot !apipassword p@ssw0rd
2) login at: http://budabot.jkbff.com/api.php
. a) your username is the name of the character that you set your password with
. b) your password is the password you set with the !apipassword command
. c) the server is the ip or host name of the server that you bot is running on
. d) the port is by default 5250 and you must make sure that your firewall is setup correctly to allow that port through
3) once you are logged in, you can execute any command that has api support (currently !kick, !invite, and !fc) by typing the command in the "Command" box and hitting "Send". For instance, if I wanted to invite Argufix to the private channel of my bot I would type "invite argufix" (without the !). The result or output from the command will be shown at the top of the page.

To enable a command for api usage, you must add the api channel in the command registration. For instance, if I wanted to enable the !invite command:

Code: Select all

Command::register($MODULE_NAME, "", "invite.php", "invite", "guild", "Invite players to the private channel", 'private_channel');

would become:

Code: Select all

Command::register($MODULE_NAME, "api msg priv guild", "invite.php", "invite", "guild", "Invite players to the private channel", 'private_channel');

Then restart the bot. Since !invite returns plain text and not AOML, we don't have to change the code for the command at all.

If you had a command that you wanted output from that normally returned it's output as a blob, say !adminlist for instance, then you could easily do that as well. First you would register the !adminlist command for the 'api' channel as shown above. Then you would replace line 4 of /core/ADMIN/adminlist.php with this:

Code: Select all

if ($type == 'api') {
   $chatBot->send(json_encode($chatBot->admins), $sendto);
   return;
}
$list = "<header>::::: List of administrators :::::<end>\n\n";

which would send the list of admins as a json object to the API caller.

How does that look so far?
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: WEBUI_MODULE brainstorming

Postby Marebone » Tue Dec 13, 2011 7:47 pm

Tyrence wrote:

Code: Select all

if ($type == 'api') {
   $chatBot->send(json_encode($chatBot->admins), $sendto);
   return;
}
$list = "<header>::::: List of administrators :::::<end>\n\n";

which would send the list of admins as a json object to the API caller.

How does that look so far?


I think you don't actually need the json_encode() there, you could just pass the admins-list as it is to send(), right?
It probably even makes things a bit more difficult in the client side if the message is encoded as you need to first json_decode() the response and then again json_decode() response's message.

Btw, what if the client needs to send something else than a string as argument through to the API? Say, a list or object?
Tyrence
The Team
Posts: 1883
Joined: Sat Jan 09, 2010 1:32 am

Re: WEBUI_MODULE brainstorming

Postby Tyrence » Tue Dec 13, 2011 8:46 pm

Marebone wrote:I think you don't actually need the json_encode() there, you could just pass the admins-list as it is to send(), right?
It probably even makes things a bit more difficult in the client side if the message is encoded as you need to first json_decode() the response and then again json_decode() response's message.

Ah yes, you are correct. So that should actually look like this:

Code: Select all

if ($type == 'api') {
   $chatBot->send($chatBot->admins, $sendto);
   return;
}
$list = "<header>::::: List of administrators :::::<end>\n\n";


Marebone wrote:Btw, what if the client needs to send something else than a string as argument through to the API? Say, a list or object?

You can pass anything to $chatBot->send() as long as it's an API call and it will be sent as part of the response.

Also, I added some code to strip AOML from the output, so if you open /modules/API_MODULE/listen.php and change line 18 from this:

Code: Select all

$chatBot->process_command('api', $apiRequest->command, $apiRequest->username, $clientHandler);

to this:

Code: Select all

$chatBot->process_command('msg', $apiRequest->command, $apiRequest->username, $clientHandler);

then you will be able to call any command using the api. The downside is of course that the output isn't that pretty, and we're basically tricking the bot into thinking that it's a private tell message instead of an api message. Besides the issue of formatting tho, doing it this way actually works extremely well.
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: WEBUI_MODULE brainstorming

Postby Marebone » Tue Dec 13, 2011 8:54 pm

Tyrence wrote:
Marebone wrote:Btw, what if the client needs to send something else than a string as argument through to the API? Say, a list or object?

You can pass anything to $chatBot->send() as long as it's an API call and it will be sent as part of the response.

Sorry no, I meant sending of something complex, like objects or lists from client --> bot through the API, not from bot --> client.
The parameters are extracted using preg_match, e.g:

Code: Select all

if (preg_match("/^invite (.+)$/i", $message, $arr)) {

I'm kinda worried that extracting the $arr could be hard, if the given arguments are, say a bunch of objects.
Tyrence
The Team
Posts: 1883
Joined: Sat Jan 09, 2010 1:32 am

Re: WEBUI_MODULE brainstorming

Postby Tyrence » Tue Dec 13, 2011 9:31 pm

Hmm, I hadn't considered the client sending objects back to the bot. Do you have an idea of where this might be useful that we could test ideas against?
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: WEBUI_MODULE brainstorming

Postby Marebone » Tue Dec 13, 2011 10:09 pm

Well, at least on example comes to mind.

Our org's site at http://insanity-inc.com/ has this shoutbox (the list on the right side), if you're logged in there is also a text input field where you can write your own shout. That is just a ready made Joomla module called Turtushout (http://www.turtus.org.ua/files?func=fileinfo&id=13).
We have, however, extended that so that those shouts are also sent to our org's chat in-game.
It has been implemented with a custom made Budabot module which periodically, or by command, fetches latest shouts from the website through a json api and then it renders the shouts into an aoml blob before sending those to org chat.

But, this could be implemented also so that when a shout is added on the site, the site could push the latest shouts through this new BUDAPI ( :D ) to our org bot. This way there would be less traffic between the site and the bot, as constant polling would not be required.

One shout contains username, title, message and timestamp.

Return to “User Modules”

Who is online

Users browsing this forum: No registered users and 1 guest