The goal of this challenge is to create a chatbot that can run in the chatrooms of Stack Exchange. Your bot needs to be able to detect when specific commands are posted by a user and respond to it. This is the list of commands, and what your bot should do:
!!newest: output the title (no link, but the title) of the newest question posted on this site (codegolf.SE).
!!metanewest: output the title of the newest question posted on the meta site (meta.codegolf.SE).
!!questioncount: output the current question count.
!!metaquestioncount: output the current question count on the meta site.
!!tag tagname: output the tag excerpt (the short description) of the tag that's given as the first parameter.
!!metatag tagname: same as above, but for the meta site.
!!featured: output the count of questions that currently have a bounty.
!!metafeatured: output the count of questions that have the [featured] tag on Meta.
You should write a complete program, not a snippet or function.
You are allowed to use external libraries to do stuff like WebSockets. These libraries do not have to count for your character count.
You can use an external chat wrapper (but you don't have to, writing your own is encouraged), and then that has to count for the character count. You also are not allowed to change the wrapper's code. If you use it, you use it without modifications and all characters have to be counted (that's as a penalty for not writing your own wrapper).
Only the code of the wrapper itself has to count. If there are other files such as examples, these don't have to count.
No use of URL shorteners or other ways that can make URLs shorter: the challenge is to golf a chatbot, not to golf a URL.
No web requests, except those necessary to chat and to get the information necessary to respond to the commands.
Use of the Standard "loopholes" is not allowed.
If someone posts a command, you need to respond with a chat message of this format:
@user response. So, if I write the command
!!featuredand there are 5 featured questions, your bot should post
If I test your bot, I'll run it from my chatbot account and I'll run it in this chatroom. I will always test the bots in that room, so it is not necessary to provide room ID as input, it will always be 14697. This ID won't be given as input, it should be hard-coded.
If the command is not found, output
@user The command [command] does not exist. Replace
[command]by the name of the non-existing command. If arguments are provided to the command, don't output the arguments, only the command name.
If a command has to many arguments, ignore the arguments that are not necessary.
If a command has not enough arguments, output
@user You have not provided enough arguments
The system prevents that duplicate messages are posted within a short time range. So, when testing your bot, I will never run two commands that give the same output successively (which means that you do not have to implement a system that makes messages different if they are duplicates, by adding a dot for example).
The system prevents that too many messages get posted within a short time range, so when testing, I will never send too many commands within a short time range, which means that your bot does not have to take care of this (by waiting some time before posting, for example).
This is code-golf, the program with the least amount of bytes wins.
Here is some info to get started with writing your bot. You don't have to use this, but it can be a guidance.
To log in, first log in to an OpenID provider. This will always be Stack Exchange OpenID (
https://openid.stackexchange.com). The login form is located at
https://openid.stackexchange.com/account/login, and provide the username and password there.
Then, login to
stackexchange.com. The login form is located at
https://stackexchange.com/users/login. Choose Stack Exchange as OpenID provider.
After doing that, log in to chat. The login form for that is located at
http://stackexchange.com/users/chat-login. Choose Stack Exchange as OpenID provider.
Then you need to get your
fkey. For that, go to
http://chat.stackexchange.com/chats/join/favoriteand get the
fkeyfrom an hidden input field.
To post a message, send a request to
http://chat.stackexchange.com/chats/14697/messages/new, and provide two POST parameters: a
textparameter containing the message text, and a
fkeyparameter containing the
To see when a new message is posted, you can use WebSockets (but don't have to, feel free to use something else if it's shorter). Please see this Meta Stack Exchange answer:
The hash can be fetched by POSTing the room id and fkey to
The timethingy is the time key of the json returned by
The event ID when a message is posted is
It is useful to look at the existing chat-wrappers, such as Doorknob's StackExchange-Chatty and Manishearth's ChatExchange, to see how it exactly works.
metafeaturedwould mean bountied questions on meta, but... thanks :-) \$\endgroup\$